Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLSegmentationDisplayNode.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
6  Queen's University, Kingston, ON, Canada. All Rights Reserved.
7 
8  See COPYRIGHT.txt
9  or http://www.slicer.org/copyright/copyright.txt for details.
10 
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16 
17  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
18  and was supported through the Applied Cancer Research Unit program of Cancer Care
19  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
20 
21 ==============================================================================*/
22 
23 #ifndef __vtkMRMLSegmentationDisplayNode_h
24 #define __vtkMRMLSegmentationDisplayNode_h
25 
26 #include "vtkMRMLDisplayNode.h"
27 
28 #include <set>
29 
31 class vtkSegmentation;
32 class vtkStringArray;
33 class vtkVector3d;
34 
35 
40 class VTK_MRML_EXPORT vtkMRMLSegmentationDisplayNode : public vtkMRMLDisplayNode
41 {
42 public:
43  // Define constants
44  static const double SEGMENT_COLOR_NO_OVERRIDE;
45 
48  {
51  double OverrideColor[3];
53  bool Visible; // Turns visibility on/off in general. Useful for allowing the user to show/hide a segment without changing any detailed visibility options.
54  bool Visible3D;
55  bool Visible2DFill; // This one is used for labelmap volume related operations (color table, merged labelmap)
58  double Opacity3D;
59  double Opacity2DFill; // This one is used for labelmap volume related operations (color table, merged labelmap)
61 
62  // Initialize with default values
64  : Visible(true)
65  , Visible3D(true)
66  , Visible2DFill(true)
67  , Visible2DOutline(true)
68  , Opacity3D(1.0)
69  , Opacity2DFill(1.0) // Default is 1, because these are relative values. Half transparency is default for the whole segmentation
70  , Opacity2DOutline(1.0)
71  {
72  OverrideColor[0] = SEGMENT_COLOR_NO_OVERRIDE;
73  OverrideColor[1] = SEGMENT_COLOR_NO_OVERRIDE;
74  OverrideColor[2] = SEGMENT_COLOR_NO_OVERRIDE;
75  }
76 
77  // Automatically generated operator= and copy constructor work
78  // correctly for these members, so there is no need to define them.
79  };
80 
81  typedef std::map<std::string, SegmentDisplayProperties> SegmentDisplayPropertiesMap;
82 
83 public:
84  static vtkMRMLSegmentationDisplayNode *New();
86  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
87 
88  virtual vtkMRMLNode* CreateNodeInstance() VTK_OVERRIDE;
89 
91  virtual void ReadXMLAttributes( const char** atts) VTK_OVERRIDE;
92 
94  virtual void WriteXML(ostream& of, int indent) VTK_OVERRIDE;
95 
97  virtual void Copy(vtkMRMLNode *node) VTK_OVERRIDE;
98 
100  virtual const char* GetNodeTagName() VTK_OVERRIDE { return "SegmentationDisplay"; }
101 
102 public:
105  vtkGetStringMacro(PreferredDisplayRepresentationName2D);
107  vtkSetStringMacro(PreferredDisplayRepresentationName2D);
109  vtkGetStringMacro(PreferredDisplayRepresentationName3D);
111  vtkSetStringMacro(PreferredDisplayRepresentationName3D);
112 
114  vtkGetMacro(Visibility3D, bool);
115  vtkSetMacro(Visibility3D, bool);
116  vtkBooleanMacro(Visibility3D, bool);
118  vtkGetMacro(Visibility2DFill, bool);
119  vtkSetMacro(Visibility2DFill, bool);
120  vtkBooleanMacro(Visibility2DFill, bool);
122  vtkGetMacro(Visibility2DOutline, bool);
123  vtkSetMacro(Visibility2DOutline, bool);
124  vtkBooleanMacro(Visibility2DOutline, bool);
125 
127  vtkGetMacro(Opacity3D, double);
128  vtkSetMacro(Opacity3D, double);
130  vtkGetMacro(Opacity2DFill, double);
131  vtkSetMacro(Opacity2DFill, double);
133  vtkGetMacro(Opacity2DOutline, double);
134  vtkSetMacro(Opacity2DOutline, double);
135 
136 public:
142  bool GetSegmentDisplayProperties(std::string segmentID, SegmentDisplayProperties &properties);
143 
145  void SetSegmentDisplayProperties(std::string segmentID, SegmentDisplayProperties &properties);
146 
148  void SetSegmentDisplayPropertiesToDefault(const std::string& segmentId);
149 
151  void RemoveSegmentDisplayProperties(std::string segmentID);
152 
154  void ClearSegmentDisplayProperties();
155 
159  bool CalculateAutoOpacitiesForSegments();
160 
167  void GenerateSegmentColor(double color[3], int colorNumber=0);
170  void GenerateSegmentColor(double &r, double &g, double &b);
171 
173  void GetPolyDataRepresentationNames(std::set<std::string> &representationNames);
174 
180  std::string GetDisplayRepresentationName3D();
181 
185  std::string GetDisplayRepresentationName2D();
186 
187 // Convenience and python compatibility functions
188 public:
191  vtkVector3d GetSegmentColor(std::string segmentID);
193  bool GetSegmentColor(std::string segmentID, double* color);
195  bool GetSegmentColor(std::string segmentID, double &r, double &g, double &b);
196 
199  vtkVector3d GetSegmentOverrideColor(std::string segmentID);
201  void SetSegmentOverrideColor(std::string segmentID, double r, double g, double b);
203  void SetSegmentOverrideColor(std::string segmentID, vtkVector3d overrideColor);
205  void UnsetSegmentOverrideColor(std::string segmentID);
206 
209  bool GetSegmentVisibility(std::string segmentID);
211  void SetSegmentVisibility(std::string segmentID, bool visible);
212  void SetAllSegmentsVisibility(bool visible);
213 
216  bool GetSegmentVisibility3D(std::string segmentID);
218  void SetSegmentVisibility3D(std::string segmentID, bool visible);
219  void SetAllSegmentsVisibility3D(bool visible, bool changeVisibleSegmentsOnly = false);
220 
223  bool GetSegmentVisibility2DFill(std::string segmentID);
225  void SetSegmentVisibility2DFill(std::string segmentID, bool visible);
226  void SetAllSegmentsVisibility2DFill(bool visible, bool changeVisibleSegmentsOnly = false);
227 
230  bool GetSegmentVisibility2DOutline(std::string segmentID);
232  void SetSegmentVisibility2DOutline(std::string segmentID, bool visible);
233  void SetAllSegmentsVisibility2DOutline(bool visible, bool changeVisibleSegmentsOnly = false);
234 
237  double GetSegmentOpacity3D(std::string segmentID);
239  void SetSegmentOpacity3D(std::string segmentID, double opacity);
240  void SetAllSegmentsOpacity3D(double opacity, bool changeVisibleSegmentsOnly = false);
241 
244  double GetSegmentOpacity2DFill(std::string segmentID);
246  void SetSegmentOpacity2DFill(std::string segmentID, double opacity);
247  void SetAllSegmentsOpacity2DFill(double opacity, bool changeVisibleSegmentsOnly = false);
248 
251  double GetSegmentOpacity2DOutline(std::string segmentID);
253  void SetSegmentOpacity2DOutline(std::string segmentID, double opacity);
254  void SetAllSegmentsOpacity2DOutline(double opacity, bool changeVisibleSegmentsOnly = false);
255 
257  void SetSegmentOpacity(std::string segmentID, double opacity);
258  void SetAllSegmentsOpacity(double opacity, bool changeVisibleSegmentsOnly = false);
259 
261  void GetVisibleSegmentIDs(vtkStringArray* segmentIDs);
262 
264  void GetVisibleSegmentIDs(std::vector<std::string>& segmentIDs);
265 
266 protected:
268  void GetSegmentIDs(std::vector<std::string>& segmentIDs, bool visibleSegmentsOnly);
269 
272  void UpdateSegmentList();
273 
274 protected:
278  void operator=(const vtkMRMLSegmentationDisplayNode&);
279 
280  friend class vtkMRMLSegmentationNode; // Access to UpdateSegmentList();
281 
282 protected:
286 
291 
294  SegmentDisplayPropertiesMap SegmentationDisplayProperties;
295 
299 
301  vtkMTimeType SegmentListUpdateTime;
303 
310 
312  double Opacity3D;
317 };
318 
319 #endif
SegmentDisplayPropertiesMap SegmentationDisplayProperties
double Opacity2DFill
2D fill opacity for the whole segmentation
vtkMTimeType SegmentListUpdateTime
For checking if cached segment list in SegmentationDisplayProperties has to be updated.
bool Visibility3D
3D visibility for the whole segmentation
double Opacity3D
3D opacity for the whole segmentation
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
bool Visibility2DFill
2D fill visibility for the whole segmentation
MRML node for representing segmentation display attributes.
double Opacity2DOutline
2D outline opacity for the whole segmentation
bool Visibility2DOutline
2D outline visibility for the whole segmentation
std::map< std::string, SegmentDisplayProperties > SegmentDisplayPropertiesMap
Abstract class that contains graphical display properties for displayable nodes.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:135
MRML node to represent discrete color information.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...