Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkSlicerSegmentationsModuleLogic.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 // .NAME vtkSlicerSegmentationsModuleLogic - Logic class for segmentation handling
22 // .SECTION Description
23 // This class manages the logic associated with converting and handling
24 // segmentation node objects.
25 
26 #ifndef __vtkSlicerSegmentationsModuleLogic_h
27 #define __vtkSlicerSegmentationsModuleLogic_h
28 
29 // Slicer includes
30 #include "vtkSlicerModuleLogic.h"
31 #include "vtkSlicerSegmentationsModuleLogicExport.h"
32 
33 // Segmentations includes
35 
36 class vtkCallbackCommand;
38 class vtkPolyData;
39 class vtkDataObject;
40 class vtkGeneralTransform;
41 
45 class vtkMRMLVolumeNode;
46 class vtkMRMLModelNode;
49 
51 class VTK_SLICER_SEGMENTATIONS_LOGIC_EXPORT vtkSlicerSegmentationsModuleLogic :
53 {
54 public:
57  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
58 
64  static vtkMRMLSegmentationNode* GetSegmentationNodeForSegmentation(vtkMRMLScene* scene, vtkSegmentation* segmentation);
65 
72  static vtkMRMLSegmentationNode* GetSegmentationNodeForSegment(vtkMRMLScene* scene, vtkSegment* segment, std::string& segmentId);
73 
78  vtkMRMLSegmentationNode* LoadSegmentationFromFile(const char* filename, bool autoOpacities=true);
79 
86  static bool CreateLabelmapVolumeFromOrientedImageData(vtkOrientedImageData* orientedImageData, vtkMRMLLabelMapVolumeNode* labelmapVolumeNode);
87 
95  static bool CopyOrientedImageDataToVolumeNode(vtkOrientedImageData* orientedImageData,
96  vtkMRMLVolumeNode* volumeNode, bool shallowCopy = true, bool shiftImageDataExtentToZeroStart = true);
97 
101  static vtkOrientedImageData* CreateOrientedImageDataFromVolumeNode(vtkMRMLScalarVolumeNode* volumeNode, vtkMRMLTransformNode* outputParentTransformNode = NULL);
102 
105  static int DoesLabelmapContainSingleLabel(vtkMRMLLabelMapVolumeNode* labelmapVolumeNode);
106 
108  static void GetAllLabelValues(vtkIntArray* labels, vtkImageData* labelmap);
109 
119  static vtkSegment* CreateSegmentFromLabelmapVolumeNode(vtkMRMLLabelMapVolumeNode* labelmapVolumeNode, vtkMRMLSegmentationNode* segmentationNode=NULL);
120 
130  static vtkSegment* CreateSegmentFromModelNode(vtkMRMLModelNode* modelNode, vtkMRMLSegmentationNode* segmentationNode=NULL);
131 
133  static vtkMRMLSegmentationNode* GetSegmentationNodeForSegmentSubjectHierarchyItem(vtkIdType segmentShItemID, vtkMRMLScene* scene);
134 
136  static vtkSegment* GetSegmentForSegmentSubjectHierarchyItem(vtkIdType segmentShItemID, vtkMRMLScene* scene);
137 
143  static bool ExportSegmentToRepresentationNode(vtkSegment* segment, vtkMRMLNode* representationNode);
144 
149  static bool ExportSegmentsToModelHierarchy(vtkMRMLSegmentationNode* segmentationNode,
150  std::vector<std::string>& segmentIDs, vtkMRMLModelHierarchyNode* modelHierarchyNode);
151 
156  static bool ExportSegmentsToModelHierarchy(vtkMRMLSegmentationNode* segmentationNode,
157  vtkStringArray* segmentIds, vtkMRMLModelHierarchyNode* modelHierarchyNode);
158 
162  static bool ExportVisibleSegmentsToModelHierarchy(vtkMRMLSegmentationNode* segmentationNode, vtkMRMLModelHierarchyNode* modelHierarchyNode);
163 
167  static bool ExportAllSegmentsToModelHierarchy(vtkMRMLSegmentationNode* segmentationNode, vtkMRMLModelHierarchyNode* modelHierarchyNode);
168 
174  static bool ExportSegmentsToLabelmapNode(vtkMRMLSegmentationNode* segmentationNode, std::vector<std::string>& segmentIDs,
175  vtkMRMLLabelMapVolumeNode* labelmapNode, vtkMRMLVolumeNode* referenceVolumeNode = NULL);
176 
182  static bool ExportSegmentsToLabelmapNode(vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* segmentIDs,
183  vtkMRMLLabelMapVolumeNode* labelmapNode, vtkMRMLVolumeNode* referenceVolumeNode = NULL);
184 
189  static bool ExportVisibleSegmentsToLabelmapNode(vtkMRMLSegmentationNode* segmentationNode,
190  vtkMRMLLabelMapVolumeNode* labelmapNode, vtkMRMLVolumeNode* referenceVolumeNode = NULL);
191 
195  static bool ExportAllSegmentsToLabelmapNode(vtkMRMLSegmentationNode* segmentationNode, vtkMRMLLabelMapVolumeNode* labelmapNode);
196 
200  static bool ImportLabelmapToSegmentationNode(vtkMRMLLabelMapVolumeNode* labelmapNode,
201  vtkMRMLSegmentationNode* segmentationNode, std::string insertBeforeSegmentId="");
202 
209  static bool ImportLabelmapToSegmentationNode(vtkOrientedImageData* labelmapImage,
210  vtkMRMLSegmentationNode* segmentationNode, std::string baseSegmentName="", std::string insertBeforeSegmentId="") ;
211 
214  static bool ImportLabelmapToSegmentationNode(vtkMRMLLabelMapVolumeNode* labelmapNode,
215  vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* updatedSegmentIDs);
216 
219  static bool ImportLabelmapToSegmentationNode(vtkOrientedImageData* labelmapImage,
220  vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* updatedSegmentIDs,
221  vtkGeneralTransform* labelmapToSegmentationTransform=NULL );
222 
227  bool ImportLabelmapToSegmentationNodeWithTerminology(vtkMRMLLabelMapVolumeNode* labelmapNode,
228  vtkMRMLSegmentationNode* segmentationNode, std::string terminologyContextName, std::string insertBeforeSegmentId="");
229 
231  static bool ImportModelToSegmentationNode(vtkMRMLModelNode* modelNode, vtkMRMLSegmentationNode* segmentationNode, std::string insertBeforeSegmentId = "");
232 
238  static vtkDataObject* CreateRepresentationForOneSegment(vtkSegmentation* segmentation, std::string segmentID, std::string representationName);
239 
243  static bool ApplyParentTransformToOrientedImageData(vtkMRMLTransformableNode* transformableNode, vtkOrientedImageData* orientedImageData, bool linearInterpolation=false, double backgroundColor[4]=NULL);
244 
248  static bool ApplyParentTransformToPolyData(vtkMRMLTransformableNode* transformableNode, vtkPolyData* polyData);
249 
259  static bool GetTransformBetweenRepresentationAndSegmentation(vtkMRMLTransformableNode* representationNode, vtkMRMLSegmentationNode* segmentationNode, vtkGeneralTransform* representationToSegmentationTransform);
260 
270  static bool GetSegmentRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, std::string representationName, vtkDataObject* segmentRepresentation, bool applyParentTransform=true);
271 
282  static bool GetSegmentBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, vtkOrientedImageData* imageData, bool applyParentTransform=true);
283 
293  static bool GetSegmentClosedSurfaceRepresentation(vtkMRMLSegmentationNode* segmentationNode,
294  std::string segmentID, vtkPolyData* polyData, bool applyParentTransform = true);
295 
302  enum
303  {
304  MODE_REPLACE = 0,
306  MODE_MERGE_MIN
307  };
308  static bool SetBinaryLabelmapToSegment(vtkOrientedImageData* labelmap, vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, int mergeMode=MODE_REPLACE, const int extent[6]=0);
309 
313  bool SetTerminologyToSegmentationFromLabelmapNode(vtkMRMLSegmentationNode* segmentationNode,
314  vtkMRMLLabelMapVolumeNode* labelmapNode, std::string terminologyContextName);
315 
316 public:
318  void SetTerminologiesLogic(vtkSlicerTerminologiesModuleLogic* terminologiesLogic);
319 
320 protected:
321  virtual void SetMRMLSceneInternal(vtkMRMLScene * newScene) VTK_OVERRIDE;
322 
324  virtual void RegisterNodes() VTK_OVERRIDE;
325 
331  static void OnSubjectHierarchyUIDAdded(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
332 
334  virtual void OnMRMLSceneNodeAdded(vtkMRMLNode* node) VTK_OVERRIDE;
335 
336 protected:
338  virtual ~vtkSlicerSegmentationsModuleLogic();
339 
341  vtkCallbackCommand* SubjectHierarchyUIDCallbackCommand;
342 
345 
346 private:
347  vtkSlicerSegmentationsModuleLogic(const vtkSlicerSegmentationsModuleLogic&); // Not implemented
348  void operator=(const vtkSlicerSegmentationsModuleLogic&); // Not implemented
349 };
350 
351 #endif
static vtkSlicerModuleLogic * New()
The Usual vtk class functions.
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
MRML node for representing a transformation between this node space and a parent node space...
MRML node to represent a 3D surface model.
MRML node for representing a label map volume.
MRML node for segmentation storage on disk.
Image data containing orientation information.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:54
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
virtual void SetMRMLSceneInternal(vtkMRMLScene *newScene)
MRML node to represent a hierarchyu of models.
MRML node for representing a volume (image stack).
MRML node for representing a volume (image stack).
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:135
MRML node for representing a node with a tranform.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...