Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLColorLegendDisplayNode.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  See COPYRIGHT.txt
6  or http://www.slicer.org/copyright/copyright.txt for details.
7 
8  Unless required by applicable law or agreed to in writing, software
9  distributed under the License is distributed on an "AS IS" BASIS,
10  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  See the License for the specific language governing permissions and
12  limitations under the License.
13 
14 ==============================================================================*/
15 
16 #ifndef __vtkMRMLColorLegendDisplayNode_h
17 #define __vtkMRMLColorLegendDisplayNode_h
18 
19 // MRML includes
20 #include <vtkMRMLDisplayNode.h>
21 #include "vtkSlicerColorsModuleMRMLExport.h"
22 
23 class vtkMRMLColorNode;
24 class vtkTextProperty;
25 
34 class VTK_SLICER_COLORS_MODULE_MRML_EXPORT vtkMRMLColorLegendDisplayNode : public vtkMRMLDisplayNode
35 {
36 public:
38  enum OrientationType : int { Horizontal = 0, Vertical, Orientation_Last };
39 
40  static vtkMRMLColorLegendDisplayNode *New();
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
44  vtkMRMLNode* CreateNodeInstance() override;
45 
47  const char* GetNodeTagName() override { return "ColorLegendDisplay"; }
48 
50  void ReadXMLAttributes(const char** atts) override;
51 
53  void WriteXML(ostream& of, int indent) override;
54 
58 
60  vtkGetMacro(Orientation, OrientationType);
63  vtkSetMacro(Orientation, OrientationType);
65 
67  vtkGetVector2Macro(Position, double);
70  vtkSetVector2Macro(Position, double);
72 
74  vtkGetVector2Macro(Size, double);
81  vtkSetVector2Macro(Size, double);
83 
85  vtkGetMacro(TitleText, std::string);
87  vtkSetMacro(TitleText, std::string);
89 
91  vtkGetMacro(LabelFormat, std::string);
100  vtkSetMacro(LabelFormat, std::string);
102 
106  virtual std::string GetDefaultNumericLabelFormat();
107 
111  virtual std::string GetDefaultTextLabelFormat();
112 
114  vtkGetMacro(MaxNumberOfColors, int);
116  vtkSetMacro(MaxNumberOfColors, int);
118 
120  vtkGetMacro(NumberOfLabels, int);
122  vtkSetMacro(NumberOfLabels, int);
124 
126  vtkGetMacro(UseColorNamesForLabels, bool);
128  vtkSetMacro(UseColorNamesForLabels, bool);
130 
132  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
137 
139  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
144 
146  vtkMRMLDisplayNode* GetPrimaryDisplayNode();
151  void SetAndObservePrimaryDisplayNode(vtkMRMLDisplayNode* node);
153 
155  void ProcessMRMLEvents(vtkObject *caller, unsigned long eventID, void *callData) override;
156 
157 protected:
159  ~vtkMRMLColorLegendDisplayNode() override;
162 
163  static const char* GetOrientationAsString(int id);
164  static int GetOrientationFromString(const char* name);
165  void SetOrientation(int id);
166 
168  void SetTitleTextPropertyFromString(std::string textPropertyString);
171  void SetLabelTextPropertyFromString(std::string textPropertyString);
172  std::string GetTitleTextPropertyAsString();
173  std::string GetLabelTextPropertyAsString();
175 
176 private:
177  OrientationType Orientation{ vtkMRMLColorLegendDisplayNode::Vertical }; // Vertical or Horizontal
178  double Position[2]{ 0.95, 0.5 }; // color legend position within view
179  double Size[2]{ 0.15, 0.5 }; // color legend width within view
180  std::string TitleText; // color legend title
181  vtkTextProperty* TitleTextProperty{ nullptr };
182  vtkTextProperty* LabelTextProperty{ nullptr };
183  // 7 so that the number appears aligned to the right even if it is large (>1000)
184  // .1 to show one fractional digit
185  // f to make the behavior more predictable for users (behavior of g is somewhat complex)
186  std::string LabelFormat;
187  int MaxNumberOfColors{ 256 };
188  int NumberOfLabels{ 5 };
189  bool UseColorNamesForLabels{ false };
190  bool CenterLabels{ false };
191 };
192 
193 #endif
void PrintSelf(ostream &os, vtkIndent indent) override
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Model)
void ReadXMLAttributes(const char **atts) override
virtual vtkMRMLNode * CreateNodeInstance()=0
Create instance of the default node. Like New only virtual.
vtkMRMLCopyContentMacro(vtkMRMLDisplayNode)
void WriteXML(ostream &of, int indent) override
void operator=(const vtkMRMLDisplayNode &)
Abstract MRML node to represent color information.
void ProcessMRMLEvents(vtkObject *caller, unsigned long event, void *callData) override
Abstract class that contains graphical display properties for displayable nodes.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
OrientationType
color legend orientation preset on a view node
Class describing how to display a color legend.