Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkColorBarAnnotation.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkColorBarAnnotation.h"
14 #include "mitkLookupTable.h"
16 #include <vtkScalarBarActor.h>
17 
19 {
20  SetDrawAnnotations(true);
21 
22  SetDrawTickLabels(true);
23 
25 
28 
30 
31  SetLookupTable(nullptr);
32 }
33 
35 {
36  for (BaseRenderer *renderer : m_LSH.GetRegisteredBaseRenderer())
37  {
38  if (renderer)
39  {
40  this->RemoveFromBaseRenderer(renderer);
41  }
42  }
43 }
44 
46 {
47 }
48 
50 {
51  m_ScalarBarActor = vtkSmartPointer<vtkScalarBarActor>::New();
52 }
53 
55 {
56  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
57 
58  if (ls->IsGenerateDataRequired(renderer, this))
59  {
60  ls->m_ScalarBarActor->SetDrawAnnotations(this->GetDrawAnnotations());
61  ls->m_ScalarBarActor->SetLookupTable(this->GetLookupTable());
62  ls->m_ScalarBarActor->SetOrientation(this->GetOrientation());
63  ls->m_ScalarBarActor->SetDrawTickLabels(this->GetDrawTickLabels());
64  ls->m_ScalarBarActor->SetMaximumNumberOfColors(this->GetMaxNumberOfColors());
65  ls->m_ScalarBarActor->SetNumberOfLabels(this->GetNumberOfLabels());
66  ls->m_ScalarBarActor->SetAnnotationTextScaling(this->GetAnnotationTextScaling());
67  // manually set position so there is no overlap with mitk logo in 3d renderwindow
68  if (this->GetOrientation() == 1)
69  {
70  ls->m_ScalarBarActor->SetPosition(0.80, 0.15);
71  ls->m_ScalarBarActor->SetWidth(0.15);
72  ls->m_ScalarBarActor->SetHeight(0.85);
73  }
74  else
75  {
76  ls->m_ScalarBarActor->SetPosition(0.03, 0.03);
77  ls->m_ScalarBarActor->SetWidth(0.8);
78  ls->m_ScalarBarActor->SetHeight(0.15);
79  }
80  }
81 }
82 
84 {
85  LocalStorage *ls = this->m_LSH.GetLocalStorage(renderer);
86  return ls->m_ScalarBarActor;
87 }
88 
90 {
91  SetBoolProperty("ColorBarAnnotation.DrawAnnotations", annotations);
92 }
93 
95 {
96  bool annotations;
97  GetPropertyList()->GetBoolProperty("ColorBarAnnotation.DrawAnnotations", annotations);
98  return annotations;
99 }
100 
101 void mitk::ColorBarAnnotation::SetLookupTable(vtkSmartPointer<vtkLookupTable> table)
102 {
105  lut->SetVtkLookupTable(table);
106  prop->SetLookupTable(lut);
107  SetProperty("ColorBarAnnotation.LookupTable", prop.GetPointer());
108 }
109 
110 vtkSmartPointer<vtkLookupTable> mitk::ColorBarAnnotation::GetLookupTable() const
111 {
113  lut = dynamic_cast<mitk::LookupTableProperty *>(GetPropertyList()->GetProperty("ColorBarAnnotation.LookupTable"))
114  ->GetLookupTable();
115  return lut->GetVtkLookupTable();
116 }
117 
119 {
120  SetIntProperty("ColorBarAnnotation.Orientation", orientation);
121 }
122 
124 {
125  int orientation;
126  GetPropertyList()->GetIntProperty("ColorBarAnnotation.Orientation", orientation);
127  return orientation;
128 }
129 
131 {
132  SetBoolProperty("ColorBarAnnotation.DrawTicks", ticks);
133 }
134 
136 {
137  bool ticks;
138  GetPropertyList()->GetBoolProperty("ColorBarAnnotation.DrawTicks", ticks);
139  return ticks;
140 }
141 
143 {
144  SetOrientation(0);
145 }
146 
148 {
149  SetOrientation(1);
150 }
151 
153 {
154  SetIntProperty("ColorBarAnnotation.MaximumNumberOfColors", numberOfColors);
155 }
156 
158 {
159  int numberOfColors;
160  GetPropertyList()->GetIntProperty("ColorBarAnnotation.MaximumNumberOfColors", numberOfColors);
161  return numberOfColors;
162 }
163 
165 {
166  SetIntProperty("ColorBarAnnotation.NumberOfLabels", numberOfLabels);
167 }
168 
170 {
171  int numberOfLabels;
172  GetPropertyList()->GetIntProperty("ColorBarAnnotation.NumberOfLabels", numberOfLabels);
173  return numberOfLabels;
174 }
175 
177 {
178  SetBoolProperty("ColorBarAnnotation.ScaleAnnotationText", scale);
179 }
180 
182 {
183  bool scale;
184  GetPropertyList()->GetBoolProperty("ColorBarAnnotation.ScaleAnnotationText", scale);
185  return scale;
186 }
#define ls
Definition: MitkMCxyz.cpp:57
void SetNumberOfLabels(int numberOfLabels)
vtkProp * GetVtkProp(BaseRenderer *renderer) const override
This method is implemented by the specific VTKAnnotation in order to create the element as a vtkProp...
void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
L * GetLocalStorage(mitk::BaseRenderer *forRenderer)
Retrieves a LocalStorage for a specific BaseRenderer.
~LocalStorage()
Default deconstructor of the local storage.
std::vector< mitk::BaseRenderer * > GetRegisteredBaseRenderer()
bool GetIntProperty(const char *propertyKey, int &intValue) const
Convenience method to access the value of an IntProperty.
vtkSmartPointer< vtkLookupTable > GetLookupTable() const
vtkSmartPointer< vtkScalarBarActor > m_ScalarBarActor
Actor of a 2D render window.
mitk::LocalStorageHandler< LocalStorage > m_LSH
The LocalStorageHandler holds all LocalStorages for the render windows.
Organizes the rendering process.
bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Annotation *Annotation)
~ColorBarAnnotation() override
virtual destructor in order to derive from this class
void SetOrientation(int orientation)
ColorBarAnnotation()
explicit constructor which disallows implicit conversions
The LookupTableProperty class Property to associate mitk::LookupTable to an mitk::DataNode.
static Pointer New()
void UpdateVtkAnnotation(BaseRenderer *renderer) override
void SetMaxNumberOfColors(int numberOfColors)
void RemoveFromBaseRenderer(BaseRenderer *renderer) override
Removes the Annotation from the specified renderer. It is not visible anymore then.
void SetBoolProperty(const std::string &propertyKey, bool boolValue)
Convenience method for setting int properties (instances of IntProperty)
LocalStorage()
Default constructor of the local storage.
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
void SetLookupTable(vtkSmartPointer< vtkLookupTable > table)
PropertyList * GetPropertyList() const
static Pointer New()
bool GetBoolProperty(const char *propertyKey, bool &boolValue) const
Convenience method to access the value of a BoolProperty.
void SetIntProperty(const std::string &propertyKey, int intValue)
Convenience method for setting int properties (instances of IntProperty)
void SetDrawAnnotations(bool annotations)