Slicer  5.3
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{true}; // 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{true};
55  bool Visible2DFill{true}; // This one is used for labelmap volume related operations (color table, merged labelmap)
56  bool Visible2DOutline{true};
58  double Opacity3D{1.0};
59  double Opacity2DFill{1.0}; // This one is used for labelmap volume related operations (color table, merged labelmap)
60  double Opacity2DOutline{1.0};
61 
62  // Initialize with default values
64  {
65  OverrideColor[0] = SEGMENT_COLOR_NO_OVERRIDE;
66  OverrideColor[1] = SEGMENT_COLOR_NO_OVERRIDE;
67  OverrideColor[2] = SEGMENT_COLOR_NO_OVERRIDE;
68  }
69 
70  // Automatically generated operator= and copy constructor work
71  // correctly for these members, so there is no need to define them.
72  };
73 
74  typedef std::map<std::string, SegmentDisplayProperties> SegmentDisplayPropertiesMap;
75 
76 public:
77  static vtkMRMLSegmentationDisplayNode *New();
79  void PrintSelf(ostream& os, vtkIndent indent) override;
80 
81  vtkMRMLNode* CreateNodeInstance() override;
82 
84  void ReadXMLAttributes( const char** atts) override;
85 
87  void WriteXML(ostream& of, int indent) override;
88 
92 
94  const char* GetNodeTagName() override { return "SegmentationDisplay"; }
95 
96 public:
99  vtkGetStringMacro(PreferredDisplayRepresentationName2D);
101  vtkSetStringMacro(PreferredDisplayRepresentationName2D);
103  vtkGetStringMacro(PreferredDisplayRepresentationName3D);
105  vtkSetStringMacro(PreferredDisplayRepresentationName3D);
106 
108  vtkGetMacro(Visibility2DFill, bool);
109  vtkSetMacro(Visibility2DFill, bool);
110  vtkBooleanMacro(Visibility2DFill, bool);
112  vtkGetMacro(Visibility2DOutline, bool);
113  vtkSetMacro(Visibility2DOutline, bool);
114  vtkBooleanMacro(Visibility2DOutline, bool);
115 
117  vtkGetMacro(Opacity3D, double);
118  vtkSetMacro(Opacity3D, double);
120  vtkGetMacro(Opacity2DFill, double);
121  vtkSetMacro(Opacity2DFill, double);
123  vtkGetMacro(Opacity2DOutline, double);
124  vtkSetMacro(Opacity2DOutline, double);
125 
126 public:
132  bool GetSegmentDisplayProperties(std::string segmentID, SegmentDisplayProperties &properties);
133 
135  void SetSegmentDisplayProperties(std::string segmentID, SegmentDisplayProperties &properties);
136 
138  void SetSegmentDisplayPropertiesToDefault(const std::string& segmentId);
139 
141  void RemoveSegmentDisplayProperties(std::string segmentID);
142 
144  void ClearSegmentDisplayProperties();
145 
149  bool CalculateAutoOpacitiesForSegments();
150 
157  void GenerateSegmentColor(double color[3], int colorNumber=0);
160  void GenerateSegmentColor(double &r, double &g, double &b);
161 
163  void SetSegmentColorGeneratorSourceColorNodeID(const char* colorNodeID);
166  const char* GetSegmentColorGeneratorSourceColorNodeID();
168 
170  void GetPolyDataRepresentationNames(std::set<std::string> &representationNames);
171 
177  std::string GetDisplayRepresentationName3D();
178 
182  std::string GetDisplayRepresentationName2D();
183 
184 // Convenience and python compatibility functions
185 public:
188  vtkVector3d GetSegmentColor(std::string segmentID);
190  bool GetSegmentColor(std::string segmentID, double* color);
192  bool GetSegmentColor(std::string segmentID, double &r, double &g, double &b);
193 
196  vtkVector3d GetSegmentOverrideColor(std::string segmentID);
202  void SetSegmentOverrideColor(std::string segmentID, double r, double g, double b);
204  void SetSegmentOverrideColor(std::string segmentID, vtkVector3d overrideColor);
206  void UnsetSegmentOverrideColor(std::string segmentID);
207 
210  bool GetSegmentVisibility(std::string segmentID);
212  void SetSegmentVisibility(std::string segmentID, bool visible);
213  void SetAllSegmentsVisibility(bool visible);
214 
217  bool GetSegmentVisibility3D(std::string segmentID);
219  void SetSegmentVisibility3D(std::string segmentID, bool visible);
220  void SetAllSegmentsVisibility3D(bool visible, bool changeVisibleSegmentsOnly = false);
221 
224  bool GetSegmentVisibility2DFill(std::string segmentID);
226  void SetSegmentVisibility2DFill(std::string segmentID, bool visible);
227  void SetAllSegmentsVisibility2DFill(bool visible, bool changeVisibleSegmentsOnly = false);
228 
231  bool GetSegmentVisibility2DOutline(std::string segmentID);
233  void SetSegmentVisibility2DOutline(std::string segmentID, bool visible);
234  void SetAllSegmentsVisibility2DOutline(bool visible, bool changeVisibleSegmentsOnly = false);
235 
238  double GetSegmentOpacity3D(std::string segmentID);
240  void SetSegmentOpacity3D(std::string segmentID, double opacity);
241  void SetAllSegmentsOpacity3D(double opacity, bool changeVisibleSegmentsOnly = false);
242 
245  double GetSegmentOpacity2DFill(std::string segmentID);
247  void SetSegmentOpacity2DFill(std::string segmentID, double opacity);
248  void SetAllSegmentsOpacity2DFill(double opacity, bool changeVisibleSegmentsOnly = false);
249 
252  double GetSegmentOpacity2DOutline(std::string segmentID);
254  void SetSegmentOpacity2DOutline(std::string segmentID, double opacity);
255  void SetAllSegmentsOpacity2DOutline(double opacity, bool changeVisibleSegmentsOnly = false);
256 
258  void SetSegmentOpacity(std::string segmentID, double opacity);
259  void SetAllSegmentsOpacity(double opacity, bool changeVisibleSegmentsOnly = false);
260 
262  void GetVisibleSegmentIDs(vtkStringArray* segmentIDs);
263 
265  void GetVisibleSegmentIDs(std::vector<std::string>& segmentIDs);
266 
268  std::vector<std::string> GetVisibleSegmentIDs();
269 
270 protected:
272  void GetSegmentIDs(std::vector<std::string>& segmentIDs, bool visibleSegmentsOnly);
273 
277  void UpdateSegmentList(bool removeUnusedDisplayProperties = true);
278 
279 protected:
281  ~vtkMRMLSegmentationDisplayNode() override;
284 
285  friend class vtkMRMLSegmentationNode; // Access to UpdateSegmentList();
286 
287 protected:
290  char* PreferredDisplayRepresentationName2D{nullptr};
291 
295  char* PreferredDisplayRepresentationName3D{nullptr};
296 
300 
303  unsigned int NumberOfGeneratedColors{0};
304 
306  vtkMTimeType SegmentListUpdateTime{0};
307  vtkSegmentation* SegmentListUpdateSource{nullptr};
308 
312  bool Visibility2DFill{true};
316  bool Visibility2DOutline{true};
317 
319  double Opacity3D{1.0};
321  double Opacity2DFill{0.5};
323  double Opacity2DOutline{1.0};
324 };
325 
326 #endif
SegmentDisplayPropertiesMap SegmentationDisplayProperties
void PrintSelf(ostream &os, vtkIndent indent) override
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
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
void operator=(const vtkMRMLDisplayNode &)
MRML node for representing segmentation display attributes.
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Model)
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:167
MRML node to represent discrete color information.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...