Slicer 5.6
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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
40class vtkAbstractTransform;
41class vtkCallbackCommand;
42class vtkCollection;
43class vtkIntArray;
45class vtkStringArray;
46
92class vtkSegmentationCore_EXPORT vtkSegmentation : public vtkObject
93{
94public:
95 enum
96 {
98 SourceRepresentationModified = 62100,
112 };
113
114 enum
115 {
127 EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_AND_REFERENCE_GEOMETRY
128 };
129
131 typedef std::map<std::string, vtkSmartPointer<vtkSegment> > SegmentMap;
132
133public:
135 vtkTypeMacro(vtkSegmentation, vtkObject);
136 void PrintSelf(ostream& os, vtkIndent indent) override;
137
139 virtual void ReadXMLAttributes(const char** atts);
140
142 virtual void WriteXML(ostream& of, int indent);
143
145 virtual void DeepCopy(vtkSegmentation* aSegmentation);
146
148 virtual void CopyConversionParameters(vtkSegmentation* aSegmentation);
149
151 virtual void GetBounds(double bounds[6]);
152
155 virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
156
159 virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
160
161#ifndef __VTK_WRAP__
170 std::string DetermineCommonLabelmapGeometry(int extentComputationMode = EXTENT_UNION_OF_SEGMENTS, const std::vector<std::string>& segmentIDs = std::vector<std::string>());
171
177 void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
178 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), bool computeEffectiveExtent=false, bool addPadding=false);
179#endif // __VTK_WRAP__
180
182 std::string DetermineCommonLabelmapGeometry(int extentComputationMode, vtkStringArray* segmentIds);
183
185 void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
186 vtkStringArray* segmentIds, bool computeEffectiveExtent=false, bool addPadding=false);
187
190 bool SetImageGeometryFromCommonLabelmapGeometry(vtkOrientedImageData* imageData, vtkStringArray* segmentIDs = nullptr,
191 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
192
193// Segment related methods
194
207 bool AddSegment(vtkSegment* segment, std::string segmentId = "", std::string insertBeforeSegmentId = "");
208
212 std::string GenerateUniqueSegmentID(std::string id);
213
216 void RemoveSegment(std::string segmentId);
217
220 void RemoveSegment(vtkSegment* segment);
221
224
227 vtkSegment* GetSegment(std::string segmentId);
228
230 void GetSegmentIDs(std::vector<std::string> &segmentIds);
231
233 void GetSegmentIDs(vtkStringArray* segmentIds);
234
236 std::vector<std::string> GetSegmentIDs();
237
240
242 vtkSegment* GetNthSegment(unsigned int index) const;
243
245 std::string GetNthSegmentID(unsigned int index) const;
246
250 int GetSegmentIndex(const std::string& segmentId);
251
255 bool SetSegmentIndex(const std::string& segmentId, unsigned int newIndex);
256
261 void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId = "");
262
265 std::string GetSegmentIdBySegment(vtkSegment* segment);
266
270 std::string GetSegmentIdBySegmentName(std::string name);
271
276 std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value="");
277
279 vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
280
287 bool CopySegmentFromSegmentation(vtkSegmentation* fromSegmentation, std::string segmentId, bool removeFromSource=false);
288
289// Representation related methods
290
294 void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
295
299 bool ContainsRepresentation(std::string representationName);
300
303
306 {
307 vtkWarningMacro("vtkSegmentation::IsMasterRepresentationPolyData() method is deprecated, please use IsSourceRepresentationPolyData method instead");
308 return this->IsSourceRepresentationPolyData();
309 };
310
313
316 {
317 vtkWarningMacro("vtkSegmentation::IsMasterRepresentationImageData() method is deprecated, please use IsSourceRepresentationImageData method instead");
318 return this->IsSourceRepresentationImageData();
319 };
320
322 void GetAvailableRepresentationNames(std::set<std::string>& representationNames) { this->Converter->GetAvailableRepresentationNames(representationNames); };
323
326
329 {
330 vtkWarningMacro("vtkSegmentation::InvalidateNonMasterRepresentations() method is deprecated, please use InvalidateNonSourceRepresentations method instead");
331 this->InvalidateNonSourceRepresentations();
332 };
333
335
336#ifndef __VTK_WRAP__
349 bool GenerateMergedLabelmap(vtkOrientedImageData* mergedImageData, int extentComputationMode, vtkOrientedImageData* mergedLabelmapGeometry = nullptr,
350 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues = nullptr);
351#endif // __VTK_WRAP__
352
354
356 bool IsSharedBinaryLabelmap(std::string segmentID);
357
363 void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName,
364 std::vector<std::string>& sharedSegmentIds, bool includeOriginalSegmentId=true);
365
370 void GetSegmentIDsSharingBinaryLabelmapRepresentation(std::string originalSegmentId, std::vector<std::string> &sharedSegmentIds,
371 bool includeOriginalSegmentId=true);
372
376 int GetUniqueLabelValueForSharedLabelmap(std::string segmentId);
377
381
386 void MergeSegmentLabelmaps(std::vector<std::string> mergeSegmentIds);
387
389 void SeparateSegmentLabelmap(std::string segmentId);
390
394 void ClearSegment(std::string segmentId);
395
397
400 int GetNumberOfLayers(std::string representationName="");
401
404 int GetLayerIndex(std::string segmentId, std::string representationName="");
405
408 vtkDataObject* GetLayerDataObject(int layer, std::string representationName="");
409
412 void GetLayerObjects(vtkCollection* layerObjects, std::string representationName = "");
413
416 std::vector<std::string> GetSegmentIDsForLayer(int layer, std::string representationName = "");
417
420 std::vector<std::string> GetSegmentIDsForDataObject(vtkDataObject* dataObject, std::string representationName = "");
421
425 void CollapseBinaryLabelmaps(bool forceToSingleLayer=false);
426
427 // Conversion related methods
428
439 bool CreateRepresentation(const std::string& targetRepresentationName, bool alwaysConvert=false);
440
448
450 void RemoveRepresentation(const std::string& representationName);
451
456 bool CanAcceptRepresentation(std::string representationName);
457
461
467 std::string AddEmptySegment(std::string segmentId="", std::string segmentName="", double color[3]=nullptr);
468
470 void GetPossibleConversions(const std::string& targetRepresentationName,
472
474 void SetConversionParameter(const std::string& name, const std::string& value) { this->Converter->SetConversionParameter(name, value); };
475
478 std::string GetConversionParameter(const std::string& name) { return this->Converter->GetConversionParameter(name); };
479
482 vtkSegmentationConversionPath* path) { this->Converter->GetConversionParametersForPath(conversionParameters, path); };
483
487
490 void DeserializeConversionParameters(std::string conversionParametersString);
491
492// Get/set methods
493
495 vtkGetMacro(SourceRepresentationName, std::string);
499 virtual void SetSourceRepresentationName(const std::string& representationName);
500
502 virtual void SetMasterRepresentationName(const std::string& representationName)
503 {
504 vtkWarningMacro("vtkSegmentation::SetMasterRepresentationName() method is deprecated, please use SetSourceRepresentationName method instead");
505 this->SetSourceRepresentationName(representationName);
506 };
507
509 virtual std::string GetMasterRepresentationName()
510 {
511 vtkWarningMacro("vtkSegmentation::GetMasterRepresentationName() method is deprecated, please use GetSourceRepresentationName method instead");
512 return this->GetSourceRepresentationName();
513 };
514
517 static void CopySegment(vtkSegment* destination, vtkSegment* source, vtkSegment* baseline,
518 std::map<vtkDataObject*, vtkDataObject*>& cachedRepresentations);
519
520protected:
521 bool ConvertSegmentsUsingPath(std::vector<std::string> segmentIDs, vtkSegmentationConversionPath* path, bool overwriteExisting = false);
522
529 bool ConvertSegmentUsingPath(vtkSegment* segment, vtkSegmentationConversionPath* path, bool overwriteExisting = false);
530
532 bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
533
536 void RemoveSegment(SegmentMap::iterator segmentIt);
537
543
548 bool SetSegmentModifiedEnabled(bool enabled);
549
550protected:
553 static void OnSegmentModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
554
557 static void OnSourceRepresentationModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
558
562
563protected:
566
567protected:
570
576
579
581 vtkCallbackCommand* SegmentCallbackCommand;
582
585
588
591
595
599 std::deque< std::string > SegmentIds;
600
601 std::set<vtkSmartPointer<vtkDataObject> > SourceRepresentationCache;
602
606 friend class qMRMLSegmentEditorWidgetPrivate;
607
608private:
609 vtkSegmentation(const vtkSegmentation&) = delete;
610 void operator=(const vtkSegmentation&) = delete;
611};
612
613#endif
MRML node containing segmentations.
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.
Utility functions for resampling oriented image data.
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
bool CopySegmentFromSegmentation(vtkSegmentation *fromSegmentation, std::string segmentId, bool removeFromSource=false)
int GetLayerIndex(std::string segmentId, std::string representationName="")
void PrintSelf(ostream &os, vtkIndent indent) override
vtkCallbackCommand * SegmentCallbackCommand
Command handling segment modified events.
@ 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.
@ ContainedRepresentationNamesModified
Invoked if a representation is created or removed in the segments (e.g., created by conversion from m...
void RemoveSegment(std::string segmentId)
std::string GenerateUniqueSegmentID(std::string id)
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)
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.
bool IsMasterRepresentationImageData()
int GetUniqueLabelValueForSharedLabelmap(vtkOrientedImageData *labelmap)
bool SetSegmentModifiedEnabled(bool enabled)
void CollapseBinaryLabelmaps(bool forceToSingleLayer=false)
int GetSegmentIndex(const std::string &segmentId)
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).
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.
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.
void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName, std::vector< std::string > &sharedSegmentIds, bool includeOriginalSegmentId=true)
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()
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.
@ 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...
virtual void CopyConversionParameters(vtkSegmentation *aSegmentation)
Copy conversion parameters from another segmentation.
void ReorderSegments(std::vector< std::string > segmentIdsToMove, std::string insertBeforeSegmentId="")
vtkCallbackCommand * SourceRepresentationCallbackCommand
Command handling source representation modified events.
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.
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.
SegmentMap Segments
Container of segments that belong to this segmentation.