Slicer 5.4
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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
31#include "vtkSlicerSegmentationsModuleLogicExport.h"
32
33// Segmentations includes
35
36class vtkCallbackCommand;
38class vtkPolyData;
39class vtkDataObject;
40class vtkGeneralTransform;
41
48
50class VTK_SLICER_SEGMENTATIONS_LOGIC_EXPORT vtkSlicerSegmentationsModuleLogic :
52{
53public:
56 void PrintSelf(ostream& os, vtkIndent indent) override;
57
64
71 static vtkMRMLSegmentationNode* GetSegmentationNodeForSegment(vtkMRMLScene* scene, vtkSegment* segment, std::string& segmentId);
72
79 vtkMRMLSegmentationNode* LoadSegmentationFromFile(const char* filename, bool autoOpacities = true, const char* nodeName=nullptr,
80 vtkMRMLColorTableNode* colorTableNode=nullptr);
81
89
98 vtkMRMLVolumeNode* volumeNode, bool shallowCopy = true, bool shiftImageDataExtentToZeroStart = true);
99
104
108
110 static void GetAllLabelValues(vtkIntArray* labels, vtkImageData* labelmap);
111
122
133
136
138 static vtkSegment* GetSegmentForSegmentSubjectHierarchyItem(vtkIdType segmentShItemID, vtkMRMLScene* scene);
139
145 static bool ExportSegmentToRepresentationNode(vtkSegment* segment, vtkMRMLNode* representationNode);
146
151 static bool ExportSegmentsToModels(vtkMRMLSegmentationNode* segmentationNode,
152 const std::vector<std::string>& segmentIDs, vtkIdType folderItemId);
153
158 static bool ExportSegmentsToModels(vtkMRMLSegmentationNode* segmentationNode,
159 vtkStringArray* segmentIds, vtkIdType folderItemId);
160
164 static bool ExportVisibleSegmentsToModels(vtkMRMLSegmentationNode* segmentationNode, vtkIdType folderItemId);
165
169 static bool ExportAllSegmentsToModels(vtkMRMLSegmentationNode* segmentationNode, vtkIdType folderItemId);
170
181 static bool ExportSegmentsToLabelmapNode(vtkMRMLSegmentationNode* segmentationNode, const std::vector<std::string>& segmentIDs,
182 vtkMRMLLabelMapVolumeNode* labelmapNode, vtkMRMLVolumeNode* referenceVolumeNode = nullptr,
183 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS, vtkMRMLColorTableNode* colorTableNode = nullptr);
184
192 static bool ExportSegmentsToLabelmapNode(vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* segmentIDs,
193 vtkMRMLLabelMapVolumeNode* labelmapNode, vtkMRMLVolumeNode* referenceVolumeNode = nullptr,
194 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS, vtkMRMLColorTableNode* colorTableNode = nullptr);
195
203 vtkMRMLLabelMapVolumeNode* labelmapNode, vtkMRMLVolumeNode* referenceVolumeNode = nullptr,
204 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
205
212 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
213
218 vtkMRMLSegmentationNode* segmentationNode, std::string insertBeforeSegmentId="");
219
227 vtkMRMLSegmentationNode* segmentationNode, std::string baseSegmentName="", std::string insertBeforeSegmentId="") ;
228
232 vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* updatedSegmentIDs);
233
237 vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* updatedSegmentIDs,
238 vtkGeneralTransform* labelmapToSegmentationTransform=nullptr );
239
245 vtkMRMLSegmentationNode* segmentationNode, std::string terminologyContextName, std::string insertBeforeSegmentId="");
246
248 static bool ImportModelToSegmentationNode(vtkMRMLModelNode* modelNode, vtkMRMLSegmentationNode* segmentationNode, std::string insertBeforeSegmentId = "");
249
252 vtkIdType folderItemId, vtkMRMLSegmentationNode* segmentationNode, std::string insertBeforeSegmentId = "" );
253
261 static bool ExportSegmentsClosedSurfaceRepresentationToFiles(std::string destinationFolder,
262 vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* segmentIds = nullptr,
263 std::string fileFormat = "STL", bool lps = true, double sizeScale = 1.0, bool merge = false);
264
272 static void GetLabelValuesFromColorNode(vtkMRMLSegmentationNode* segmentationNode, vtkMRMLColorTableNode* colorTableNode,
273 vtkStringArray* segmentIds, vtkIntArray* labelValues);
274
286 static bool ExportSegmentsBinaryLabelmapRepresentationToFiles(std::string destinationFolder,
287 vtkMRMLSegmentationNode* segmentationNode, vtkStringArray* segmentIds = nullptr, std::string extension = "nrrd", bool useCompression = false,
288 vtkMRMLVolumeNode* referenceVolumeNode = nullptr, int extentComputationMode = vtkSegmentation::EXTENT_REFERENCE_GEOMETRY,
289 vtkMRMLColorTableNode* colorTableNode = nullptr);
290
296 static vtkDataObject* CreateRepresentationForOneSegment(vtkSegmentation* segmentation, std::string segmentID, std::string representationName);
297
302 vtkMRMLTransformableNode* transformableNode, vtkOrientedImageData* orientedImageData, bool linearInterpolation=false, double backgroundColor[4]=nullptr );
303
307 static bool ApplyParentTransformToPolyData(vtkMRMLTransformableNode* transformableNode, vtkPolyData* polyData);
308
319 vtkMRMLTransformableNode* representationNode, vtkMRMLSegmentationNode* segmentationNode, vtkGeneralTransform* representationToSegmentationTransform );
320
330 static bool GetSegmentRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, std::string representationName, vtkDataObject* segmentRepresentation, bool applyParentTransform=true);
331
342 static bool GetSegmentBinaryLabelmapRepresentation(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID, vtkOrientedImageData* imageData, bool applyParentTransform=true);
343
354 std::string segmentID, vtkPolyData* polyData, bool applyParentTransform = true);
355
362 enum
363 {
364 MODE_REPLACE = 0,
367 MODE_MERGE_MASK
368 };
369 static bool SetBinaryLabelmapToSegment(vtkOrientedImageData* labelmap, vtkMRMLSegmentationNode* segmentationNode, std::string segmentID,
370 int mergeMode=MODE_REPLACE, const int extent[6]=nullptr, bool minimumOfAllSegments=false, const std::vector<std::string>& segmentIdsToOverwrite={});
371
376 vtkMRMLLabelMapVolumeNode* labelmapNode, std::string terminologyContextName);
377
380
384
394 static const char* GetSegmentStatusAsHumanReadableString(int segmentStatus);
396 static const char* GetSegmentStatusAsMachineReadableString(int segmentStatus);
398 static int GetSegmentStatusFromMachineReadableString(std::string statusString);
399
401 static const char* GetStatusTagName();
404 static int GetSegmentStatus(vtkSegment* segment);
408 static void SetSegmentStatus(vtkSegment* segment, int status);
410 static bool ClearSegment(vtkMRMLSegmentationNode* segmentationNode, std::string segmentID);
411
418 static bool GetSharedSegmentIDsInMask(vtkMRMLSegmentationNode* segmentationNode, std::string sharedSegmentID, vtkOrientedImageData* mask, const int extent[6],
419 std::vector<std::string>& segmentIDs, int maskThreshold = 0.0, bool includeInputSharedSegmentID = false);
420
426 const std::vector<std::string>& segmentIDs={});
427
433 static void CollapseBinaryLabelmaps(vtkMRMLSegmentationNode* segmentationNode, bool forceToSingleLayer);
434
443 vtkStringArray* segmentIDs, int extentComputationMode, vtkOrientedImageData* mergedLabelmap_Reference, vtkIntArray* labelValues=nullptr);
444
450 static bool IsEffectiveExentOutsideReferenceVolume(vtkMRMLVolumeNode* referenceVolumeNode, vtkMRMLSegmentationNode* segmentationNode,
451 vtkStringArray* segmentIDs = nullptr);
452
457 static bool IsSegmentationExentOutsideReferenceGeometry(vtkOrientedImageData* referenceGeometry, vtkOrientedImageData* segmentationGeometry);
458
459protected:
460 void SetMRMLSceneInternal(vtkMRMLScene * newScene) override;
461
463 void RegisterNodes() override;
464
470 static void OnSubjectHierarchyUIDAdded(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
471
473 void OnMRMLSceneNodeAdded(vtkMRMLNode* node) override;
474
475 static bool ExportSegmentsClosedSurfaceRepresentationToStlFiles(std::string destinationFolder,
476 vtkMRMLSegmentationNode* segmentationNode, const std::vector<std::string>& segmentIDs, bool lps, double sizeScale, bool merge);
477 static bool ExportSegmentsClosedSurfaceRepresentationToObjFile(std::string destinationFolder,
478 vtkMRMLSegmentationNode* segmentationNode, const std::vector<std::string>& segmentIDs, bool lps, double sizeScale);
479
483 static std::string GetSafeFileName(std::string originalName);
484
485protected:
488
491
492private:
494 void operator=(const vtkSlicerSegmentationsModuleLogic&) = delete;
495};
496
497#endif
MRML node to represent discrete color information.
MRML node for representing a label map volume.
MRML node to represent a 3D surface model.
Abstract Superclass for all specific types of MRML nodes.
MRML node for representing a volume (image stack).
A set of MRML Nodes that supports serialization and undo/redo.
MRML node containing segmentations.
MRML node for segmentation storage on disk.
MRML node for representing a transformation between this node space and a parent node space.
MRML node for representing a node with a transform.
MRML node for representing a volume (image stack).
Image data containing orientation information.
This class encapsulates a segment that is part of a segmentation.
Definition vtkSegment.h:46
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
@ EXTENT_UNION_OF_EFFECTIVE_SEGMENTS
Extent is computed as union of effective extent of all segments.
@ EXTENT_REFERENCE_GEOMETRY
Extent of common geometry is used as extent.
void SetDefaultSurfaceSmoothingEnabled(bool enabled)
static bool ExportAllSegmentsToModels(vtkMRMLSegmentationNode *segmentationNode, vtkIdType folderItemId)
static bool GetSharedSegmentIDsInMask(vtkMRMLSegmentationNode *segmentationNode, std::string sharedSegmentID, vtkOrientedImageData *mask, const int extent[6], std::vector< std::string > &segmentIDs, int maskThreshold=0.0, bool includeInputSharedSegmentID=false)
static vtkMRMLSegmentationNode * GetSegmentationNodeForSegmentSubjectHierarchyItem(vtkIdType segmentShItemID, vtkMRMLScene *scene)
Utility function for getting the segmentation node for a segmentation or segment subject hierarchy it...
static bool ImportModelToSegmentationNode(vtkMRMLModelNode *modelNode, vtkMRMLSegmentationNode *segmentationNode, std::string insertBeforeSegmentId="")
Import model into the segmentation as a segment.
vtkMRMLSegmentationNode * LoadSegmentationFromFile(const char *filename, bool autoOpacities=true, const char *nodeName=nullptr, vtkMRMLColorTableNode *colorTableNode=nullptr)
static int DoesLabelmapContainSingleLabel(vtkMRMLLabelMapVolumeNode *labelmapVolumeNode)
static bool ExportAllSegmentsToLabelmapNode(vtkMRMLSegmentationNode *segmentationNode, vtkMRMLLabelMapVolumeNode *labelmapNode, int extentComputationMode=vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS)
static bool IsSegmentationExentOutsideReferenceGeometry(vtkOrientedImageData *referenceGeometry, vtkOrientedImageData *segmentationGeometry)
static bool IsEffectiveExentOutsideReferenceVolume(vtkMRMLVolumeNode *referenceVolumeNode, vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *segmentIDs=nullptr)
static const char * GetSegmentStatusAsMachineReadableString(int segmentStatus)
Get the machine readable segment status from the SegmentStatus enum value.
static bool ImportLabelmapToSegmentationNode(vtkMRMLLabelMapVolumeNode *labelmapNode, vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *updatedSegmentIDs)
static vtkSegment * CreateSegmentFromModelNode(vtkMRMLModelNode *modelNode, vtkMRMLSegmentationNode *segmentationNode=nullptr)
static void SetSegmentStatus(vtkSegment *segment, int status)
static vtkMRMLSegmentationNode * GetSegmentationNodeForSegmentation(vtkMRMLScene *scene, vtkSegmentation *segmentation)
static void GetLabelValuesFromColorNode(vtkMRMLSegmentationNode *segmentationNode, vtkMRMLColorTableNode *colorTableNode, vtkStringArray *segmentIds, vtkIntArray *labelValues)
static bool ExportSegmentsToLabelmapNode(vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *segmentIDs, vtkMRMLLabelMapVolumeNode *labelmapNode, vtkMRMLVolumeNode *referenceVolumeNode=nullptr, int extentComputationMode=vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS, vtkMRMLColorTableNode *colorTableNode=nullptr)
vtkMRMLSegmentationNode * GetDefaultSegmentationNode()
Get default segmentation node. All new segmentation nodes are initialized to the content of this node...
static void CollapseBinaryLabelmaps(vtkMRMLSegmentationNode *segmentationNode, bool forceToSingleLayer)
static vtkMRMLSegmentationNode * GetSegmentationNodeForSegment(vtkMRMLScene *scene, vtkSegment *segment, std::string &segmentId)
static void GenerateMergedLabelmapInReferenceGeometry(vtkMRMLSegmentationNode *segmentationNode, vtkMRMLVolumeNode *referenceVolumeNode, vtkStringArray *segmentIDs, int extentComputationMode, vtkOrientedImageData *mergedLabelmap_Reference, vtkIntArray *labelValues=nullptr)
static bool ImportModelsToSegmentationNode(vtkIdType folderItemId, vtkMRMLSegmentationNode *segmentationNode, std::string insertBeforeSegmentId="")
Import models in a folder into the segmentation as segments.
static bool ExportSegmentsClosedSurfaceRepresentationToFiles(std::string destinationFolder, vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *segmentIds=nullptr, std::string fileFormat="STL", bool lps=true, double sizeScale=1.0, bool merge=false)
static bool ExportSegmentToRepresentationNode(vtkSegment *segment, vtkMRMLNode *representationNode)
static int GetSegmentStatus(vtkSegment *segment)
static bool ExportSegmentsClosedSurfaceRepresentationToStlFiles(std::string destinationFolder, vtkMRMLSegmentationNode *segmentationNode, const std::vector< std::string > &segmentIDs, bool lps, double sizeScale, bool merge)
static bool ReconvertAllRepresentations(vtkMRMLSegmentationNode *segmentationNode, const std::vector< std::string > &segmentIDs={})
static bool ExportSegmentsToLabelmapNode(vtkMRMLSegmentationNode *segmentationNode, const std::vector< std::string > &segmentIDs, vtkMRMLLabelMapVolumeNode *labelmapNode, vtkMRMLVolumeNode *referenceVolumeNode=nullptr, int extentComputationMode=vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS, vtkMRMLColorTableNode *colorTableNode=nullptr)
static bool GetTransformBetweenRepresentationAndSegmentation(vtkMRMLTransformableNode *representationNode, vtkMRMLSegmentationNode *segmentationNode, vtkGeneralTransform *representationToSegmentationTransform)
static bool ExportSegmentsToModels(vtkMRMLSegmentationNode *segmentationNode, const std::vector< std::string > &segmentIDs, vtkIdType folderItemId)
static bool GetSegmentClosedSurfaceRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string segmentID, vtkPolyData *polyData, bool applyParentTransform=true)
static vtkSegment * CreateSegmentFromLabelmapVolumeNode(vtkMRMLLabelMapVolumeNode *labelmapVolumeNode, vtkMRMLSegmentationNode *segmentationNode=nullptr)
bool ImportLabelmapToSegmentationNodeWithTerminology(vtkMRMLLabelMapVolumeNode *labelmapNode, vtkMRMLSegmentationNode *segmentationNode, std::string terminologyContextName, std::string insertBeforeSegmentId="")
static const char * GetStatusTagName()
Returns the name of the status tag.
static bool GetSegmentBinaryLabelmapRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string segmentID, vtkOrientedImageData *imageData, bool applyParentTransform=true)
void SetMRMLSceneInternal(vtkMRMLScene *newScene) override
static vtkOrientedImageData * CreateOrientedImageDataFromVolumeNode(vtkMRMLScalarVolumeNode *volumeNode, vtkMRMLTransformNode *outputParentTransformNode=nullptr)
static void OnSubjectHierarchyUIDAdded(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
static bool ExportVisibleSegmentsToLabelmapNode(vtkMRMLSegmentationNode *segmentationNode, vtkMRMLLabelMapVolumeNode *labelmapNode, vtkMRMLVolumeNode *referenceVolumeNode=nullptr, int extentComputationMode=vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS)
static void GetAllLabelValues(vtkIntArray *labels, vtkImageData *labelmap)
Utility function that returns all non-empty label values in a labelmap.
void RegisterNodes() override
Register MRML Node classes to Scene. Gets called automatically when the MRMLScene is attached to this...
static vtkSegment * GetSegmentForSegmentSubjectHierarchyItem(vtkIdType segmentShItemID, vtkMRMLScene *scene)
Utility function for getting the segment object for a segment subject hierarchy item.
static bool SetBinaryLabelmapToSegment(vtkOrientedImageData *labelmap, vtkMRMLSegmentationNode *segmentationNode, std::string segmentID, int mergeMode=MODE_REPLACE, const int extent[6]=nullptr, bool minimumOfAllSegments=false, const std::vector< std::string > &segmentIdsToOverwrite={})
bool GetDefaultSurfaceSmoothingEnabled()
Get/Set default closed surface smoothing enabled flag for new segmentation nodes.
static std::string GetSafeFileName(std::string originalName)
void PrintSelf(ostream &os, vtkIndent indent) override
static bool ExportSegmentsBinaryLabelmapRepresentationToFiles(std::string destinationFolder, vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *segmentIds=nullptr, std::string extension="nrrd", bool useCompression=false, vtkMRMLVolumeNode *referenceVolumeNode=nullptr, int extentComputationMode=vtkSegmentation::EXTENT_REFERENCE_GEOMETRY, vtkMRMLColorTableNode *colorTableNode=nullptr)
static const char * GetSegmentStatusAsHumanReadableString(int segmentStatus)
Get the human readable segment status from the SegmentStatus enum value.
static bool ClearSegment(vtkMRMLSegmentationNode *segmentationNode, std::string segmentID)
Clear the contents of a single segment.
static bool ApplyParentTransformToOrientedImageData(vtkMRMLTransformableNode *transformableNode, vtkOrientedImageData *orientedImageData, bool linearInterpolation=false, double backgroundColor[4]=nullptr)
static bool CreateLabelmapVolumeFromOrientedImageData(vtkOrientedImageData *orientedImageData, vtkMRMLLabelMapVolumeNode *labelmapVolumeNode)
bool SetTerminologyToSegmentationFromLabelmapNode(vtkMRMLSegmentationNode *segmentationNode, vtkMRMLLabelMapVolumeNode *labelmapNode, std::string terminologyContextName)
static bool ExportSegmentsClosedSurfaceRepresentationToObjFile(std::string destinationFolder, vtkMRMLSegmentationNode *segmentationNode, const std::vector< std::string > &segmentIDs, bool lps, double sizeScale)
static bool ExportVisibleSegmentsToModels(vtkMRMLSegmentationNode *segmentationNode, vtkIdType folderItemId)
void OnMRMLSceneNodeAdded(vtkMRMLNode *node) override
Handle MRML node added events.
static bool ImportLabelmapToSegmentationNode(vtkMRMLLabelMapVolumeNode *labelmapNode, vtkMRMLSegmentationNode *segmentationNode, std::string insertBeforeSegmentId="")
static vtkDataObject * CreateRepresentationForOneSegment(vtkSegmentation *segmentation, std::string segmentID, std::string representationName)
static bool ApplyParentTransformToPolyData(vtkMRMLTransformableNode *transformableNode, vtkPolyData *polyData)
static bool GetSegmentRepresentation(vtkMRMLSegmentationNode *segmentationNode, std::string segmentID, std::string representationName, vtkDataObject *segmentRepresentation, bool applyParentTransform=true)
static int GetSegmentStatusFromMachineReadableString(std::string statusString)
Get the enum segment status from a machine string.
vtkCallbackCommand * SubjectHierarchyUIDCallbackCommand
Command handling subject hierarchy UID added events.
static vtkSlicerSegmentationsModuleLogic * New()
static bool ExportSegmentsToModels(vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *segmentIds, vtkIdType folderItemId)
static bool CopyOrientedImageDataToVolumeNode(vtkOrientedImageData *orientedImageData, vtkMRMLVolumeNode *volumeNode, bool shallowCopy=true, bool shiftImageDataExtentToZeroStart=true)
static bool ImportLabelmapToSegmentationNode(vtkOrientedImageData *labelmapImage, vtkMRMLSegmentationNode *segmentationNode, vtkStringArray *updatedSegmentIDs, vtkGeneralTransform *labelmapToSegmentationTransform=nullptr)
static bool ImportLabelmapToSegmentationNode(vtkOrientedImageData *labelmapImage, vtkMRMLSegmentationNode *segmentationNode, std::string baseSegmentName="", std::string insertBeforeSegmentId="")