Slicer  4.10
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 
234  static bool ImportModelHierarchyToSegmentationNode(
235  vtkMRMLModelHierarchyNode* modelHierarchyNode, vtkMRMLSegmentationNode* segmentationNode, std::string insertBeforeSegmentId = "" );
236 
244  static bool ExportSegmentsClosedSurfaceRepresentationToFiles(std::string destinationFolder,
245  vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* segmentIds = NULL,
246  std::string fileFormat = "STL", bool lps = true, double sizeScale = 1.0, bool merge = false);
247 
253  static vtkDataObject* CreateRepresentationForOneSegment(vtkSegmentation* segmentation, std::string segmentID, std::string representationName);
254 
258  static bool ApplyParentTransformToOrientedImageData(
259  vtkMRMLTransformableNode* transformableNode, vtkOrientedImageData* orientedImageData, bool linearInterpolation=false, double backgroundColor[4]=NULL );
260 
264  static bool ApplyParentTransformToPolyData(vtkMRMLTransformableNode* transformableNode, vtkPolyData* polyData);
265 
275  static bool GetTransformBetweenRepresentationAndSegmentation(
276  vtkMRMLTransformableNode* representationNode, vtkMRMLSegmentationNode* segmentationNode, vtkGeneralTransform* representationToSegmentationTransform );
277 
287  static bool GetSegmentRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, std::string representationName, vtkDataObject* segmentRepresentation, bool applyParentTransform=true);
288 
299  static bool GetSegmentBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, vtkOrientedImageData* imageData, bool applyParentTransform=true);
300 
310  static bool GetSegmentClosedSurfaceRepresentation(vtkMRMLSegmentationNode* segmentationNode,
311  std::string segmentID, vtkPolyData* polyData, bool applyParentTransform = true);
312 
319  enum
320  {
321  MODE_REPLACE = 0,
323  MODE_MERGE_MIN
324  };
325  static bool SetBinaryLabelmapToSegment(vtkOrientedImageData* labelmap, vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, int mergeMode=MODE_REPLACE, const int extent[6]=0);
326 
330  bool SetTerminologyToSegmentationFromLabelmapNode(vtkMRMLSegmentationNode* segmentationNode,
331  vtkMRMLLabelMapVolumeNode* labelmapNode, std::string terminologyContextName);
332 
334  vtkMRMLSegmentationNode* GetDefaultSegmentationNode();
335 
337  bool GetDefaultSurfaceSmoothingEnabled();
338  void SetDefaultSurfaceSmoothingEnabled(bool enabled);
339 
340 public:
342  void SetTerminologiesLogic(vtkSlicerTerminologiesModuleLogic* terminologiesLogic);
343 
344 protected:
345  virtual void SetMRMLSceneInternal(vtkMRMLScene * newScene) VTK_OVERRIDE;
346 
348  virtual void RegisterNodes() VTK_OVERRIDE;
349 
355  static void OnSubjectHierarchyUIDAdded(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
356 
358  virtual void OnMRMLSceneNodeAdded(vtkMRMLNode* node) VTK_OVERRIDE;
359 
360  static bool ExportSegmentsClosedSurfaceRepresentationToStlFiles(std::string destinationFolder,
361  vtkMRMLSegmentationNode* segmentationNode, std::vector<std::string>& segmentIDs, bool lps, double sizeScale, bool merge);
362  static bool ExportSegmentsClosedSurfaceRepresentationToObjFile(std::string destinationFolder,
363  vtkMRMLSegmentationNode* segmentationNode, std::vector<std::string>& segmentIDs, bool lps, double sizeScale);
364 
368  static std::string GetSafeFileName(std::string originalName);
369 
370 protected:
373 
375  vtkCallbackCommand* SubjectHierarchyUIDCallbackCommand;
376 
379 
380 private:
382  void operator=(const vtkSlicerSegmentationsModuleLogic&); // Not implemented
383 };
384 
385 #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.
LRU Cache.
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:138
MRML node for representing a node with a transform.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...