Slicer 5.4
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
93class vtkSegmentationCore_EXPORT vtkSegmentation : public vtkObject
94{
95public:
96 enum
97 {
99 SourceRepresentationModified = 62100,
113 };
114
115 enum
116 {
128 EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_AND_REFERENCE_GEOMETRY
129 };
130
132 typedef std::map<std::string, vtkSmartPointer<vtkSegment> > SegmentMap;
133
134public:
136 vtkTypeMacro(vtkSegmentation, vtkObject);
137 void PrintSelf(ostream& os, vtkIndent indent) override;
138
140 virtual void ReadXMLAttributes(const char** atts);
141
143 virtual void WriteXML(ostream& of, int indent);
144
146 virtual void DeepCopy(vtkSegmentation* aSegmentation);
147
149 virtual void CopyConversionParameters(vtkSegmentation* aSegmentation);
150
152 virtual void GetBounds(double bounds[6]);
153
156 virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
157
160 virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
161
162#ifndef __VTK_WRAP__
171 std::string DetermineCommonLabelmapGeometry(int extentComputationMode = EXTENT_UNION_OF_SEGMENTS, const std::vector<std::string>& segmentIDs = std::vector<std::string>());
172
178 void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
179 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), bool computeEffectiveExtent=false, bool addPadding=false);
180#endif // __VTK_WRAP__
181
183 std::string DetermineCommonLabelmapGeometry(int extentComputationMode, vtkStringArray* segmentIds);
184
186 void DetermineCommonLabelmapExtent(int commonGeometryExtent[6], vtkOrientedImageData* commonGeometryImage,
187 vtkStringArray* segmentIds, bool computeEffectiveExtent=false, bool addPadding=false);
188
191 bool SetImageGeometryFromCommonLabelmapGeometry(vtkOrientedImageData* imageData, vtkStringArray* segmentIDs = nullptr,
192 int extentComputationMode = vtkSegmentation::EXTENT_UNION_OF_EFFECTIVE_SEGMENTS);
193
194// Segment related methods
195
208 bool AddSegment(vtkSegment* segment, std::string segmentId = "", std::string insertBeforeSegmentId = "");
209
213 std::string GenerateUniqueSegmentID(std::string id);
214
217 void RemoveSegment(std::string segmentId);
218
221 void RemoveSegment(vtkSegment* segment);
222
225
228 vtkSegment* GetSegment(std::string segmentId);
229
231 void GetSegmentIDs(std::vector<std::string> &segmentIds);
232
234 void GetSegmentIDs(vtkStringArray* segmentIds);
235
237 std::vector<std::string> GetSegmentIDs();
238
241
243 vtkSegment* GetNthSegment(unsigned int index) const;
244
246 std::string GetNthSegmentID(unsigned int index) const;
247
251 int GetSegmentIndex(const std::string& segmentId);
252
256 bool SetSegmentIndex(const std::string& segmentId, unsigned int newIndex);
257
262 void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId = "");
263
266 std::string GetSegmentIdBySegment(vtkSegment* segment);
267
271 std::string GetSegmentIdBySegmentName(std::string name);
272
277 std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value="");
278
280 vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
281
288 bool CopySegmentFromSegmentation(vtkSegmentation* fromSegmentation, std::string segmentId, bool removeFromSource=false);
289
290// Representation related methods
291
295 void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
296
300 bool ContainsRepresentation(std::string representationName);
301
304
307 {
308 vtkWarningMacro("vtkSegmentation::IsMasterRepresentationPolyData() method is deprecated, please use IsSourceRepresentationPolyData method instead");
309 return this->IsSourceRepresentationPolyData();
310 };
311
314
317 {
318 vtkWarningMacro("vtkSegmentation::IsMasterRepresentationImageData() method is deprecated, please use IsSourceRepresentationImageData method instead");
319 return this->IsSourceRepresentationImageData();
320 };
321
323 void GetAvailableRepresentationNames(std::set<std::string>& representationNames) { this->Converter->GetAvailableRepresentationNames(representationNames); };
324
327
330 {
331 vtkWarningMacro("vtkSegmentation::InvalidateNonMasterRepresentations() method is deprecated, please use InvalidateNonSourceRepresentations method instead");
332 this->InvalidateNonSourceRepresentations();
333 };
334
336
337#ifndef __VTK_WRAP__
350 bool GenerateMergedLabelmap(vtkOrientedImageData* mergedImageData, int extentComputationMode, vtkOrientedImageData* mergedLabelmapGeometry = nullptr,
351 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues = nullptr);
352#endif // __VTK_WRAP__
353
355
357 bool IsSharedBinaryLabelmap(std::string segmentID);
358
364 void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName,
365 std::vector<std::string>& sharedSegmentIds, bool includeOriginalSegmentId=true);
366
371 void GetSegmentIDsSharingBinaryLabelmapRepresentation(std::string originalSegmentId, std::vector<std::string> &sharedSegmentIds,
372 bool includeOriginalSegmentId=true);
373
377 int GetUniqueLabelValueForSharedLabelmap(std::string segmentId);
378
382
387 void MergeSegmentLabelmaps(std::vector<std::string> mergeSegmentIds);
388
390 void SeparateSegmentLabelmap(std::string segmentId);
391
395 void ClearSegment(std::string segmentId);
396
398
401 int GetNumberOfLayers(std::string representationName="");
402
405 int GetLayerIndex(std::string segmentId, std::string representationName="");
406
409 vtkDataObject* GetLayerDataObject(int layer, std::string representationName="");
410
413 void GetLayerObjects(vtkCollection* layerObjects, std::string representationName = "");
414
417 std::vector<std::string> GetSegmentIDsForLayer(int layer, std::string representationName = "");
418
421 std::vector<std::string> GetSegmentIDsForDataObject(vtkDataObject* dataObject, std::string representationName = "");
422
426 void CollapseBinaryLabelmaps(bool forceToSingleLayer=false);
427
428 // Conversion related methods
429
440 bool CreateRepresentation(const std::string& targetRepresentationName, bool alwaysConvert=false);
441
449
451 void RemoveRepresentation(const std::string& representationName);
452
457 bool CanAcceptRepresentation(std::string representationName);
458
462
468 std::string AddEmptySegment(std::string segmentId="", std::string segmentName="", double color[3]=nullptr);
469
471 void GetPossibleConversions(const std::string& targetRepresentationName,
473
475 void SetConversionParameter(const std::string& name, const std::string& value) { this->Converter->SetConversionParameter(name, value); };
476
479 std::string GetConversionParameter(const std::string& name) { return this->Converter->GetConversionParameter(name); };
480
483 vtkSegmentationConversionPath* path) { this->Converter->GetConversionParametersForPath(conversionParameters, path); };
484
488
491 void DeserializeConversionParameters(std::string conversionParametersString);
492
493// Get/set methods
494
496 vtkGetMacro(SourceRepresentationName, std::string);
500 virtual void SetSourceRepresentationName(const std::string& representationName);
501
503 virtual void SetMasterRepresentationName(const std::string& representationName)
504 {
505 vtkWarningMacro("vtkSegmentation::SetMasterRepresentationName() method is deprecated, please use SetSourceRepresentationName method instead");
506 this->SetSourceRepresentationName(representationName);
507 };
508
510 virtual std::string GetMasterRepresentationName()
511 {
512 vtkWarningMacro("vtkSegmentation::GetMasterRepresentationName() method is deprecated, please use GetSourceRepresentationName method instead");
513 return this->GetSourceRepresentationName();
514 };
515
518 static void CopySegment(vtkSegment* destination, vtkSegment* source, vtkSegment* baseline,
519 std::map<vtkDataObject*, vtkDataObject*>& cachedRepresentations);
520
521protected:
522 bool ConvertSegmentsUsingPath(std::vector<std::string> segmentIDs, vtkSegmentationConversionPath* path, bool overwriteExisting = false);
523
530 bool ConvertSegmentUsingPath(vtkSegment* segment, vtkSegmentationConversionPath* path, bool overwriteExisting = false);
531
533 bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
534
537 void RemoveSegment(SegmentMap::iterator segmentIt);
538
544
549 bool SetSegmentModifiedEnabled(bool enabled);
550
551protected:
554 static void OnSegmentModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
555
558 static void OnSourceRepresentationModified(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
559
563
564protected:
567
568protected:
571
577
580
582 vtkCallbackCommand* SegmentCallbackCommand;
583
586
589
592
596
600 std::deque< std::string > SegmentIds;
601
602 std::set<vtkSmartPointer<vtkDataObject> > SourceRepresentationCache;
603
607 friend class qMRMLSegmentEditorWidgetPrivate;
608
609private:
610 vtkSegmentation(const vtkSegmentation&) = delete;
611 void operator=(const vtkSegmentation&) = delete;
612};
613
614#endif
MRML node containing segmentations.
Image data containing orientation information.
This class encapsulates a segment that is part of a segmentation.
Definition vtkSegment.h:46
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.