Slicer  4.11
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 GetPolyDataRepresentationNames(std::set<std::string> &representationNames);
164 
170  std::string GetDisplayRepresentationName3D();
171 
175  std::string GetDisplayRepresentationName2D();
176 
177 // Convenience and python compatibility functions
178 public:
181  vtkVector3d GetSegmentColor(std::string segmentID);
183  bool GetSegmentColor(std::string segmentID, double* color);
185  bool GetSegmentColor(std::string segmentID, double &r, double &g, double &b);
186 
189  vtkVector3d GetSegmentOverrideColor(std::string segmentID);
195  void SetSegmentOverrideColor(std::string segmentID, double r, double g, double b);
197  void SetSegmentOverrideColor(std::string segmentID, vtkVector3d overrideColor);
199  void UnsetSegmentOverrideColor(std::string segmentID);
200 
203  bool GetSegmentVisibility(std::string segmentID);
205  void SetSegmentVisibility(std::string segmentID, bool visible);
206  void SetAllSegmentsVisibility(bool visible);
207 
210  bool GetSegmentVisibility3D(std::string segmentID);
212  void SetSegmentVisibility3D(std::string segmentID, bool visible);
213  void SetAllSegmentsVisibility3D(bool visible, bool changeVisibleSegmentsOnly = false);
214 
217  bool GetSegmentVisibility2DFill(std::string segmentID);
219  void SetSegmentVisibility2DFill(std::string segmentID, bool visible);
220  void SetAllSegmentsVisibility2DFill(bool visible, bool changeVisibleSegmentsOnly = false);
221 
224  bool GetSegmentVisibility2DOutline(std::string segmentID);
226  void SetSegmentVisibility2DOutline(std::string segmentID, bool visible);
227  void SetAllSegmentsVisibility2DOutline(bool visible, bool changeVisibleSegmentsOnly = false);
228 
231  double GetSegmentOpacity3D(std::string segmentID);
233  void SetSegmentOpacity3D(std::string segmentID, double opacity);
234  void SetAllSegmentsOpacity3D(double opacity, bool changeVisibleSegmentsOnly = false);
235 
238  double GetSegmentOpacity2DFill(std::string segmentID);
240  void SetSegmentOpacity2DFill(std::string segmentID, double opacity);
241  void SetAllSegmentsOpacity2DFill(double opacity, bool changeVisibleSegmentsOnly = false);
242 
245  double GetSegmentOpacity2DOutline(std::string segmentID);
247  void SetSegmentOpacity2DOutline(std::string segmentID, double opacity);
248  void SetAllSegmentsOpacity2DOutline(double opacity, bool changeVisibleSegmentsOnly = false);
249 
251  void SetSegmentOpacity(std::string segmentID, double opacity);
252  void SetAllSegmentsOpacity(double opacity, bool changeVisibleSegmentsOnly = false);
253 
255  void GetVisibleSegmentIDs(vtkStringArray* segmentIDs);
256 
258  void GetVisibleSegmentIDs(std::vector<std::string>& segmentIDs);
259 
260 protected:
262  void GetSegmentIDs(std::vector<std::string>& segmentIDs, bool visibleSegmentsOnly);
263 
267  void UpdateSegmentList(bool removeUnusedDisplayProperties = true);
268 
269 protected:
271  ~vtkMRMLSegmentationDisplayNode() override;
274 
275  friend class vtkMRMLSegmentationNode; // Access to UpdateSegmentList();
276 
277 protected:
280  char* PreferredDisplayRepresentationName2D{nullptr};
281 
285  char* PreferredDisplayRepresentationName3D{nullptr};
286 
290 
293  unsigned int NumberOfGeneratedColors{0};
294 
296  vtkMTimeType SegmentListUpdateTime{0};
297  vtkSegmentation* SegmentListUpdateSource{nullptr};
298 
302  bool Visibility2DFill{true};
306  bool Visibility2DOutline{true};
307 
309  double Opacity3D{1.0};
311  double Opacity2DFill{0.5};
313  double Opacity2DOutline{1.0};
314 };
315 
316 #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 ...