Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
vtkSegmentation.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 __vtkSegmentation_h
22#define __vtkSegmentation_h
23
24// VTK includes
25#include <vtkObject.h>
26#include <vtkSmartPointer.h>
27
28// STD includes
29#include <map>
30#include <deque>
31#include <vector>
32
33// SegmentationCore includes
34#include "vtkSegment.h"
37
38#include "vtkSegmentationCoreConfigure.h"
39
40#include <vtkSingleton.h>
41
42class vtkAbstractTransform;
43class vtkCallbackCommand;
44class vtkCollection;
45class vtkIntArray;
46class vtkMinimalStandardRandomSequence;
48class vtkStringArray;
49
95class vtkSegmentationCore_EXPORT vtkSegmentation : public vtkObject
96{
97public:
98 enum
99 {
115 };
116
117 enum
118 {
131 };
132
134 typedef std::map<std::string, vtkSmartPointer<vtkSegment> > SegmentMap;
135
136public:
138 vtkTypeMacro(vtkSegmentation, vtkObject);
139 void PrintSelf(ostream& os, vtkIndent indent) override;
140
142 virtual void ReadXMLAttributes(const char** atts);
143
145 virtual void WriteXML(ostream& of, int indent);
146
148 virtual void DeepCopy(vtkSegmentation* aSegmentation);
149
151 virtual void CopyConversionParameters(vtkSegmentation* aSegmentation);
152
154 virtual void GetBounds(double bounds[6]);
155
158 virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
159
162 virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
163
164#ifndef __VTK_WRAP__
173 std::string DetermineCommonLabelmapGeometry(int extentComputationMode = EXTENT_UNION_OF_SEGMENTS, const std::vector<std::string>& segmentIDs = std::vector<std::string>());
174
180 void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
181 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), bool computeEffectiveExtent=false, bool addPadding=false);
182#endif // __VTK_WRAP__
183
185 std::string DetermineCommonLabelmapGeometry(int extentComputationMode, vtkStringArray* segmentIds);
186
188 void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
189 vtkStringArray* segmentIds, bool computeEffectiveExtent=false, bool addPadding=false);
190
193 bool SetImageGeometryFromCommonLabelmapGeometry(vtkOrientedImageData* imageData, vtkStringArray* segmentIDs = nullptr,
194 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
195
196// Segment related methods
197
210 bool AddSegment(vtkSegment* segment, std::string segmentId = "", std::string insertBeforeSegmentId = "");
211
219 std::string GenerateUniqueSegmentID(std::string id = "");
220
223 void RemoveSegment(std::string segmentId);
224
227 void RemoveSegment(vtkSegment* segment);
228
231
234 vtkSegment* GetSegment(std::string segmentId);
235
237 void GetSegmentIDs(std::vector<std::string> &segmentIds);
238
240 void GetSegmentIDs(vtkStringArray* segmentIds);
241
243 std::vector<std::string> GetSegmentIDs();
244
247
249 vtkSegment* GetNthSegment(unsigned int index) const;
250
252 std::string GetNthSegmentID(unsigned int index) const;
253
257 int GetSegmentIndex(const std::string& segmentId);
258
262 bool SetSegmentIndex(const std::string& segmentId, unsigned int newIndex);
263
268 void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId = "");
269
272 std::string GetSegmentIdBySegment(vtkSegment* segment);
273
277 std::string GetSegmentIdBySegmentName(std::string name);
278
283 std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value="");
284
286 vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
287
294 bool CopySegmentFromSegmentation(vtkSegmentation* fromSegmentation, std::string segmentId, bool removeFromSource=false);
295
296// Representation related methods
297
301 void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
302
306 bool ContainsRepresentation(std::string representationName);
307
310
313 {
314 vtkWarningMacro("vtkSegmentation::IsMasterRepresentationPolyData() method is deprecated, please use IsSourceRepresentationPolyData method instead");
315 return this->IsSourceRepresentationPolyData();
316 };
317
320
323 {
324 vtkWarningMacro("vtkSegmentation::IsMasterRepresentationImageData() method is deprecated, please use IsSourceRepresentationImageData method instead");
325 return this->IsSourceRepresentationImageData();
326 };
327
329 void GetAvailableRepresentationNames(std::set<std::string>& representationNames) { this->Converter->GetAvailableRepresentationNames(representationNames); };
330
333
336 {
337 vtkWarningMacro("vtkSegmentation::InvalidateNonMasterRepresentations() method is deprecated, please use InvalidateNonSourceRepresentations method instead");
339 };
340
342
343#ifndef __VTK_WRAP__
356 bool GenerateMergedLabelmap(vtkOrientedImageData* mergedImageData, int extentComputationMode, vtkOrientedImageData* mergedLabelmapGeometry = nullptr,
357 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues = nullptr);
358#endif // __VTK_WRAP__
359
361
363 bool IsSharedBinaryLabelmap(std::string segmentID);
364
370 void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName,
371 std::vector<std::string>& sharedSegmentIds, bool includeOriginalSegmentId=true);
372
377 void GetSegmentIDsSharingBinaryLabelmapRepresentation(std::string originalSegmentId, std::vector<std::string> &sharedSegmentIds,
378 bool includeOriginalSegmentId=true);
379
383 int GetUniqueLabelValueForSharedLabelmap(std::string segmentId);
384
388
393 void MergeSegmentLabelmaps(std::vector<std::string> mergeSegmentIds);
394
396 void SeparateSegmentLabelmap(std::string segmentId);
397
401 void ClearSegment(std::string segmentId);
402
404
407 int GetNumberOfLayers(std::string representationName="");
408
411 int GetLayerIndex(std::string segmentId, std::string representationName="");
412
415 vtkDataObject* GetLayerDataObject(int layer, std::string representationName="");
416
419 void GetLayerObjects(vtkCollection* layerObjects, std::string representationName = "");
420
423 std::vector<std::string> GetSegmentIDsForLayer(int layer, std::string representationName = "");
424
427 std::vector<std::string> GetSegmentIDsForDataObject(vtkDataObject* dataObject, std::string representationName = "");
428
432 void CollapseBinaryLabelmaps(bool forceToSingleLayer=false);
433
434 // Conversion related methods
435
446 bool CreateRepresentation(const std::string& targetRepresentationName, bool alwaysConvert=false);
447
455
457 void RemoveRepresentation(const std::string& representationName);
458
463 bool CanAcceptRepresentation(std::string representationName);
464
468
474 std::string AddEmptySegment(std::string segmentId="", std::string segmentName="", double color[3]=nullptr);
475
477 void GetPossibleConversions(const std::string& targetRepresentationName,
479
481 void SetConversionParameter(const std::string& name, const std::string& value) { this->Converter->SetConversionParameter(name, value); };
482
485 std::string GetConversionParameter(const std::string& name) { return this->Converter->GetConversionParameter(name); };
486
489 vtkSegmentationConversionPath* path) { this->Converter->GetConversionParametersForPath(conversionParameters, path); };
490
494
497 void DeserializeConversionParameters(std::string conversionParametersString);
498
499// Get/set methods
500
502 vtkGetMacro(SourceRepresentationName, std::string);
506 virtual void SetSourceRepresentationName(const std::string& representationName);
507
509 virtual void SetMasterRepresentationName(const std::string& representationName)
510 {
511 vtkWarningMacro("vtkSegmentation::SetMasterRepresentationName() method is deprecated, please use SetSourceRepresentationName method instead");
512 this->SetSourceRepresentationName(representationName);
513 };
514
516 virtual std::string GetMasterRepresentationName()
517 {
518 vtkWarningMacro("vtkSegmentation::GetMasterRepresentationName() method is deprecated, please use GetSourceRepresentationName method instead");
519 return this->GetSourceRepresentationName();
520 };
521
524 static void CopySegment(vtkSegment* destination, vtkSegment* source, vtkSegment* baseline,
525 std::map<vtkDataObject*, vtkDataObject*>& cachedRepresentations);
526
527 vtkSetMacro(UUIDSegmentIDs, bool);
528 vtkGetMacro(UUIDSegmentIDs, bool);
529 vtkBooleanMacro(UUIDSegmentIDs, bool);
530
531 static vtkMinimalStandardRandomSequence* GetSegmentIDRandomSequenceInstance();
532
533protected:
534 bool ConvertSegmentsUsingPath(std::vector<std::string> segmentIDs, vtkSegmentationConversionPath* path, bool overwriteExisting = false);
535
542 bool ConvertSegmentUsingPath(vtkSegment* segment, vtkSegmentationConversionPath* path, bool overwriteExisting = false);
543
545 bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
546
549 void RemoveSegment(SegmentMap::iterator segmentIt);
550
556
561 bool SetSegmentModifiedEnabled(bool enabled);
562
563protected:
566 static void OnSegmentModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
567
570 static void OnSourceRepresentationModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
571
575
578 static std::string GenerateUUIDDerivedUID();
579
583 static std::string GenerateRandomSegmentID(int suffixLength, std::string validCharacters="");
584
590 std::string GenerateUniqueSegmentName(std::string base);
591
592protected:
595
596protected:
599
605
608
610 vtkCallbackCommand* SegmentCallbackCommand;
611
614
617
620
624
628 std::deque< std::string > SegmentIds;
629
630 std::set<vtkSmartPointer<vtkDataObject> > SourceRepresentationCache;
631
633
636
638 static void classInitialize();
639 static void classFinalize();
640
645
646private:
647 vtkSegmentation(const vtkSegmentation&) = delete;
648 void operator=(const vtkSegmentation&) = delete;
649};
650
651VTK_SINGLETON_DECLARE_INITIALIZER(vtkSegmentationCore_EXPORT, vtkSegmentationRandomSequence);
652
653#endif
Image data containing orientation information.
This class encapsulates a segment that is part of a segmentation.
Definition vtkSegment.h:45
Store a segmentation conversion path.
Store multiple segmentation conversion paths.
Class that can convert between different representations of a segment.
bool CopySegmentFromSegmentation(vtkSegmentation *fromSegmentation, std::string segmentId, bool removeFromSource=false)
friend class vtkSegmentationRandomSequenceInitialize
Singleton class managing vtkMinimalStandardRandomSequence used for randomizing segment IDs.
int GetLayerIndex(std::string segmentId, std::string representationName="")
void PrintSelf(ostream &os, vtkIndent indent) override
vtkCallbackCommand * SegmentCallbackCommand
Command handling segment modified events.
void RemoveSegment(std::string segmentId)
void InvalidateNonSourceRepresentations()
Invalidate (remove) non-source representations in all the segments if this segmentation node.
std::string DetermineCommonLabelmapGeometry(int extentComputationMode, vtkStringArray *segmentIds)
Determine common labelmap geometry for whole segmentation, for python compatibility.
std::string SerializeAllConversionParameters()
~vtkSegmentation() override
std::deque< std::string > SegmentIds
bool SetSegmentIndex(const std::string &segmentId, unsigned int newIndex)
void SeparateSegmentLabelmap(std::string segmentId)
Moves an existing segment from a shared labelmap into a separate labelmap containing only the specifi...
bool SetSourceRepresentationModifiedEnabled(bool enabled)
void DeserializeConversionParameters(std::string conversionParametersString)
vtkSegmentationConverter * Converter
Converter instance.
bool CanAcceptRepresentation(std::string representationName)
virtual void WriteXML(ostream &of, int indent)
Write this object's information to a MRML file in XML format.
vtkSegment * GetSegment(std::string segmentId)
static void CopySegment(vtkSegment *destination, vtkSegment *source, vtkSegment *baseline, std::map< vtkDataObject *, vtkDataObject * > &cachedRepresentations)
bool CreateRepresentation(const std::string &targetRepresentationName, bool alwaysConvert=false)
static void OnSegmentModified(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
void RemoveSegment(vtkSegment *segment)
friend class vtkSegmentationModifier
friend class vtkMRMLSegmentationNode
std::string GetNthSegmentID(unsigned int index) const
Get n-th segment ID. Return with "" if no segment is found by that index.
int GetNumberOfLayers(std::string representationName="")
Shared representation layer functions.
static std::string GenerateRandomSegmentID(int suffixLength, std::string validCharacters="")
bool IsMasterRepresentationImageData()
int GetUniqueLabelValueForSharedLabelmap(vtkOrientedImageData *labelmap)
bool SetSegmentModifiedEnabled(bool enabled)
void CollapseBinaryLabelmaps(bool forceToSingleLayer=false)
int GetSegmentIndex(const std::string &segmentId)
friend class vtkSlicerSegmentationsModuleLogic
bool ConvertSegmentUsingPath(vtkSegment *segment, vtkSegmentationConversionPath *path, bool overwriteExisting=false)
void GetContainedRepresentationNames(std::vector< std::string > &representationNames)
virtual void GetBounds(double bounds[6])
Get bounding box in global RAS in the form (xmin,xmax, ymin,ymax, zmin,zmax).
static std::string GenerateUUIDDerivedUID()
bool CreateRepresentation(vtkSegmentationConversionPath *path, vtkSegmentationConversionParameters *parameters)
std::vector< std::string > GetSegmentIDs()
Get IDs for all contained segments, for python compatibility.
virtual void SetSourceRepresentationName(const std::string &representationName)
bool CanAcceptSegment(vtkSegment *segment)
void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData *commonGeometryImage, const std::vector< std::string > &segmentIDs=std::vector< std::string >(), bool computeEffectiveExtent=false, bool addPadding=false)
bool IsSharedBinaryLabelmap(std::string segmentID)
Shared labelmap utility functions.
static vtkMinimalStandardRandomSequence * GetSegmentIDRandomSequenceInstance()
virtual std::string GetMasterRepresentationName()
std::set< vtkSmartPointer< vtkDataObject > > SourceRepresentationCache
void GetSegmentIDs(vtkStringArray *segmentIds)
Get IDs for all contained segments, for python compatibility.
void ClearSegment(std::string segmentId)
std::vector< std::string > GetSegmentIDsForLayer(int layer, std::string representationName="")
bool SegmentModifiedEnabled
Modified events of segments are observed.
std::map< std::string, vtkSmartPointer< vtkSegment > > SegmentMap
Container type for segments. Maps segment IDs to segment objects.
int GetUniqueLabelValueForSharedLabelmap(std::string segmentId)
virtual void ApplyNonLinearTransform(vtkAbstractTransform *transform)
void RemoveRepresentation(const std::string &representationName)
Removes a representation from all segments if present.
bool IsMasterRepresentationPolyData()
vtkSegment * GetNthSegment(unsigned int index) const
Request segment by index.
std::string GetSegmentIdBySegment(vtkSegment *segment)
bool ConvertSegmentsUsingPath(std::vector< std::string > segmentIDs, vtkSegmentationConversionPath *path, bool overwriteExisting=false)
std::string DetermineCommonLabelmapGeometry(int extentComputationMode=EXTENT_UNION_OF_SEGMENTS, const std::vector< std::string > &segmentIDs=std::vector< std::string >())
vtkDataObject * GetLayerDataObject(int layer, std::string representationName="")
virtual void ApplyLinearTransform(vtkAbstractTransform *transform)
bool SourceRepresentationModifiedEnabled
Modified events of source representations are observed.
@ SegmentsOrderModified
Invoked if segment IDs order is changed. Not called when a segment is added or removed.
@ RepresentationModified
Invoked when content of any representation (including the source representation) in a segment is chan...
@ SegmentAdded
Invoked if new segment is added.
@ SegmentRemoved
Invoked if a segment is removed.
@ SourceRepresentationModified
Invoked when content of the source representation in a segment is changed.
@ ContainedRepresentationNamesModified
Invoked if a representation is created or removed in the segments (e.g., created by conversion from m...
void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName, std::vector< std::string > &sharedSegmentIds, bool includeOriginalSegmentId=true)
friend class qMRMLSegmentEditorWidgetPrivate
void GetSegmentIDsSharingBinaryLabelmapRepresentation(std::string originalSegmentId, std::vector< std::string > &sharedSegmentIds, bool includeOriginalSegmentId=true)
bool GenerateMergedLabelmap(vtkOrientedImageData *mergedImageData, int extentComputationMode, vtkOrientedImageData *mergedLabelmapGeometry=nullptr, const std::vector< std::string > &segmentIDs=std::vector< std::string >(), vtkIntArray *labelValues=nullptr)
Merged labelmap functions.
std::string SourceRepresentationName
void InvalidateNonMasterRepresentations()
std::string GenerateUniqueSegmentID(std::string id="")
void RemoveSegment(SegmentMap::iterator segmentIt)
vtkDataObject * GetSegmentRepresentation(std::string segmentId, std::string representationName)
Get representation from segment.
static vtkSegmentation * New()
std::vector< std::string > GetSegmentIDsForDataObject(vtkDataObject *dataObject, std::string representationName="")
std::string AddEmptySegment(std::string segmentId="", std::string segmentName="", double color[3]=nullptr)
void GetConversionParametersForPath(vtkSegmentationConversionParameters *conversionParameters, vtkSegmentationConversionPath *path)
Get names of all conversion parameters used by the selected conversion path.
bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName)
Converts a single segment to a representation.
void UpdateSourceRepresentationObservers()
static void OnSourceRepresentationModified(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
bool AddSegment(vtkSegment *segment, std::string segmentId="", std::string insertBeforeSegmentId="")
virtual void DeepCopy(vtkSegmentation *aSegmentation)
Deep copy one segmentation into another.
void GetSegmentIDs(std::vector< std::string > &segmentIds)
Get IDs for all contained segments.
bool IsSourceRepresentationPolyData()
Determine if source representation is poly data type.
bool ContainsRepresentation(std::string representationName)
virtual void SetMasterRepresentationName(const std::string &representationName)
void GetPossibleConversions(const std::string &targetRepresentationName, vtkSegmentationConversionPaths *paths)
Get all possible conversions between the source representation and a specified target representation.
bool IsSourceRepresentationImageData()
Determine if source representation is (oriented) image data type.
virtual void CopyConversionParameters(vtkSegmentation *aSegmentation)
Copy conversion parameters from another segmentation.
void ReorderSegments(std::vector< std::string > segmentIdsToMove, std::string insertBeforeSegmentId="")
@ EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_AND_REFERENCE_GEOMETRY
Extent is computed as the reference geometry, expanded to contain the union of all segments.
@ EXTENT_UNION_OF_SEGMENTS_PADDED
Extent is computed as union of extent of all segments, with a single-voxel padding added on each side...
@ 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.
@ EXTENT_UNION_OF_SEGMENTS
Extent is computed as union of extent of all segments.
@ EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_PADDED
Extent is computed as union of effective extent of all segments, with a single-voxel padding added on...
vtkCallbackCommand * SourceRepresentationCallbackCommand
Command handling source representation modified events.
virtual std::string GetSourceRepresentationName()
Get source representation name.
std::vector< vtkSegment * > GetSegmentsByTag(std::string tag, std::string value="")
std::string GetSegmentIdBySegmentName(std::string name)
virtual void ReadXMLAttributes(const char **atts)
Set attributes from name/value pairs.
static void classFinalize()
void SetConversionParameter(const std::string &name, const std::string &value)
Set a conversion parameter to all rules having this parameter.
void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData *commonGeometryImage, vtkStringArray *segmentIds, bool computeEffectiveExtent=false, bool addPadding=false)
Determine common labelmap extent for whole segmentation, for python compatibility.
void GetAvailableRepresentationNames(std::set< std::string > &representationNames)
Get all representations supported by the converter.
int GetNumberOfSegments() const
Request the total number of segments, primarily used for iterating over all segments.
void GetLayerObjects(vtkCollection *layerObjects, std::string representationName="")
void MergeSegmentLabelmaps(std::vector< std::string > mergeSegmentIds)
std::string GetConversionParameter(const std::string &name)
bool SetImageGeometryFromCommonLabelmapGeometry(vtkOrientedImageData *imageData, vtkStringArray *segmentIDs=nullptr, int extentComputationMode=vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS)
void RemoveAllSegments()
Remove all segments.
static void classInitialize()
Singleton management functions.
SegmentMap Segments
Container of segments that belong to this segmentation.
std::string GenerateUniqueSegmentName(std::string base)
VTK_SINGLETON_DECLARE_INITIALIZER(vtkSegmentationCore_EXPORT, vtkSegmentationRandomSequence)