Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkMRMLSegmentationNode.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
4  Queen's University, Kingston, ON, Canada. All Rights Reserved.
5 
6  See COPYRIGHT.txt
7  or http://www.slicer.org/copyright/copyright.txt for details.
8 
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  See the License for the specific language governing permissions and
13  limitations under the License.
14 
15  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
16  and was supported through the Applied Cancer Research Unit program of Cancer Care
17  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
18 
19 ==============================================================================*/
20 
21 #ifndef __vtkMRMLSegmentationNode_h
22 #define __vtkMRMLSegmentationNode_h
23 
24 // MRML includes
25 #include <vtkMRML.h>
26 #include <vtkMRMLDisplayableNode.h>
27 #include <vtkMRMLColorTableNode.h>
28 
29 // STD includes
30 #include <cstdlib>
31 
32 // vtkSegmentationCore includes
33 #include "vtkSegmentation.h"
34 
35 class vtkCallbackCommand;
36 class vtkIntArray;
37 class vtkMRMLScene;
41 class vtkPolyData;
42 
53 class VTK_MRML_EXPORT vtkMRMLSegmentationNode : public vtkMRMLDisplayableNode
54 {
55 public:
56  // Define constants
57  static const char* GetSegmentIDAttributeName() { return "segmentID"; };
58 
59  static vtkMRMLSegmentationNode *New();
61  void PrintSelf(ostream& os, vtkIndent indent) override;
62 
64  vtkMRMLNode* CreateNodeInstance() override;
65 
67  void ReadXMLAttributes( const char** atts) override;
68 
70  void WriteXML(ostream& of, int indent) override;
71 
75 
77  const char* GetNodeTagName() override {return "Segmentation";};
78 
83  void GetRASBounds(double bounds[6]) override;
84 
88  void GetBounds(double bounds[6]) override;
89 
92  bool CanApplyNonLinearTransforms()const override;
93 
96  void ApplyTransformMatrix(vtkMatrix4x4* transformMatrix) override;
97 
100  void ApplyTransform(vtkAbstractTransform* transform) override;
101 
104 
106  void CreateDefaultDisplayNodes() override;
107 
115  virtual void OnSubjectHierarchyUIDAdded(vtkMRMLSubjectHierarchyNode* shNode, vtkIdType itemWithNewUID);
116 
121  virtual vtkIdType GetSegmentSubjectHierarchyItem(std::string segmentID, vtkMRMLSubjectHierarchyNode* shNode);
122 
123 #ifndef __VTK_WRAP__
124 //BTX
137  virtual bool GenerateMergedLabelmap(vtkOrientedImageData* mergedImageData, int extentComputationMode, vtkOrientedImageData* mergedLabelmapGeometry = nullptr,
138  const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues = nullptr);
139 //ETX
140 #endif // __VTK_WRAP__
141 
155  virtual bool GenerateMergedLabelmapForAllSegments(vtkOrientedImageData* mergedImageData,
156  int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS,
157  vtkOrientedImageData* mergedLabelmapGeometry = nullptr, vtkStringArray* segmentIDs = nullptr, vtkIntArray* labelValues = nullptr);
158 
159  enum
160  {
162  EditAllowedEverywhere = 0,
174  EditAllowed_Last
175  };
176 
178  static const char* ConvertMaskModeToString(int mode);
180  static int ConvertMaskModeFromString(const char* modeStr);
182 
194  virtual bool GenerateEditMask(vtkOrientedImageData* maskImage, int editMode,
195  vtkOrientedImageData* referenceGeometry,
196  std::string editedSegmentID="", std::string maskSegmentID="",
197  vtkOrientedImageData* masterVolume = nullptr, double editableIntensityRange[2] = nullptr,
198  vtkMRMLSegmentationDisplayNode* displayNode = nullptr);
199 
201  static std::string GetReferenceImageGeometryReferenceRole() { return "referenceImageGeometryRef"; };
203  virtual void SetReferenceImageGeometryParameterFromVolumeNode(vtkMRMLScalarVolumeNode* volumeNode);
204 
206  vtkGetObjectMacro(Segmentation, vtkSegmentation);
208  void SetAndObserveSegmentation(vtkSegmentation* segmentation);
209 
210  // Convenience functions for commonly needed features
211 
214  virtual bool SetMasterRepresentationToBinaryLabelmap();
217  virtual bool SetMasterRepresentationToClosedSurface();
218 
220  virtual bool CreateBinaryLabelmapRepresentation();
221 
223  virtual void RemoveBinaryLabelmapRepresentation();
224 
229  virtual bool GetBinaryLabelmapRepresentation(const std::string segmentId, vtkOrientedImageData* outputBinaryLabelmap);
230 
237  virtual vtkOrientedImageData* GetBinaryLabelmapInternalRepresentation(const std::string segmentId);
238 
241  virtual bool CreateClosedSurfaceRepresentation();
242 
244  virtual void RemoveClosedSurfaceRepresentation();
245 
250  virtual bool GetClosedSurfaceRepresentation(const std::string segmentId, vtkPolyData* outputClosedSurface);
251 
255  virtual vtkPolyData* GetClosedSurfaceInternalRepresentation(const std::string segmentId);
256 
259  virtual std::string AddSegmentFromClosedSurfaceRepresentation(vtkPolyData* polyData,
260  std::string segmentName = "", double color[3] = nullptr, std::string segmentId = "");
261 
264  std::string AddSegmentFromBinaryLabelmapRepresentation(vtkOrientedImageData* imageData,
265  std::string segmentName = "", double color[3] = nullptr, std::string segmentId = "");
266 
268  void RemoveSegment(const std::string& segmentID);
269 
271  double* GetSegmentCenter(const std::string& segmentID) VTK_SIZEHINT(3);
274  void GetSegmentCenter(const std::string& segmentID, double center[3]);
275 
279  double* GetSegmentCenterRAS(const std::string& segmentID) VTK_SIZEHINT(3);
282  void GetSegmentCenterRAS(const std::string& segmentID, double centerRAS[3]);
283 
285  vtkSetMacro(SegmentListFilterEnabled, bool);
286  vtkGetMacro(SegmentListFilterEnabled, bool);
287  vtkBooleanMacro(SegmentListFilterEnabled, bool);
288 
290  vtkSetMacro(SegmentListFilterOptions, std::string);
291  vtkGetMacro(SegmentListFilterOptions, std::string);
292 
296  void SetLabelmapConversionColorTableNodeID(const char* labelmapConversionColorTableNodeID);
297  vtkMRMLColorTableNode* GetLabelmapConversionColorTableNode();
298 
301  enum
302  {
303  ReferenceImageGeometryChangedEvent = 23000,
304  SegmentationChangedEvent
305  };
306 
307 protected:
309  vtkSetObjectMacro(Segmentation, vtkSegmentation);
310 
312  static void SegmentationModifiedCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
313 
316  void OnMasterRepresentationModified();
317 
320  void OnSegmentAdded(const char* segmentId);
321 
324  void OnSegmentRemoved(const char* segmentId);
325 
328  void OnSegmentModified(const char* segmentId);
329 
330  static const char* GetLabelmapConversionColorTableNodeReferenceRole() { return "labelmapConversionColorTableNode"; };
331  static const char* GetLabelmapConversionColorTableNodeReferenceMRMLAttributeName() { return "labelmapConversionColorTableNodeRef"; };
332 
334  void OnNodeReferenceAdded(vtkMRMLNodeReference* reference) override;
335 
337  void OnNodeReferenceModified(vtkMRMLNodeReference* reference) override;
338 
340  void OnNodeReferenceRemoved(vtkMRMLNodeReference* reference) override;
341 
342 protected:
344  ~vtkMRMLSegmentationNode() override;
346  void operator=(const vtkMRMLSegmentationNode&);
347 
350 
352  vtkSmartPointer<vtkCallbackCommand> SegmentationModifiedCallbackCommand;
353 
356  double SegmentCenterTmp[4];
357 
360 };
361 
362 #endif // __vtkMRMLSegmentationNode_h
vtkSmartPointer< vtkCallbackCommand > SegmentationModifiedCallbackCommand
Command handling events from segmentation object.
Modification is allowed inside all visible segments.
void ReadXMLAttributes(const char **atts) override
Read node attributes from XML file
static const char * GetLabelmapConversionColorTableNodeReferenceMRMLAttributeName()
void OnNodeReferenceRemoved(vtkMRMLNodeReference *reference) override
Called after a node reference ID is removed (list size decreased).
static std::string GetReferenceImageGeometryReferenceRole()
Expose reference identifier to get the volume node defining the reference image geometry if any...
virtual vtkMRMLStorageNode * CreateDefaultStorageNode()
virtual void GetBounds(double bounds[6])
void OnNodeReferenceAdded(vtkMRMLNodeReference *reference) override
Called when a node reference ID is added (list size increased).
virtual void ApplyTransform(vtkAbstractTransform *transform)
Modification is allowed outside all visible segments.
const char * GetNodeTagName() override
Get unique node XML tag name (like Volume, Model)
void WriteXML(ostream &of, int indent) override
Write this node&#39;s information to a MRML file in XML format.
void operator=(const vtkMRMLDisplayableNode &)
MRML node to represent a complete subject hierarchy tree.
Image data containing orientation information.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
void PrintSelf(ostream &os, vtkIndent indent) override
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
vtkSegmentation * Segmentation
Segmentation object to store the actual data.
virtual void CreateDefaultDisplayNodes()
virtual void ApplyTransformMatrix(vtkMatrix4x4 *transformMatrix)
MRML node for representing segmentation display attributes.
static const char * GetSegmentIDAttributeName()
Extent is computed as union of effective extent of all segments.
A superclass for other storage nodes.
vtkMRMLNode * CreateNodeInstance() override=0
MRMLNode methods.
Modification is allowed only over the area covered by segment specified in MaskSegmentID.
static const char * GetLabelmapConversionColorTableNodeReferenceRole()
vtkMRMLCopyContentMacro(vtkMRMLStorableNode)
virtual bool CanApplyNonLinearTransforms() const
MRML node for representing a volume (image stack).
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
MRML node to represent discrete color information.
void OnNodeReferenceModified(vtkMRMLNodeReference *reference) override
Called when a node reference ID is modified.
Modification is allowed outside all segments.
Modification is allowed inside all segments.
virtual void GetRASBounds(double bounds[6])
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...