21#ifndef __vtkSegmentation_h
22#define __vtkSegmentation_h
26#include <vtkSmartPointer.h>
38#include "vtkSegmentationCoreConfigure.h"
40#include <vtkSingleton.h>
42class vtkAbstractTransform;
43class vtkCallbackCommand;
46class vtkMinimalStandardRandomSequence;
134 typedef std::map<std::string, vtkSmartPointer<vtkSegment> >
SegmentMap;
181 const std::vector<std::string>& segmentIDs = std::vector<std::string>(),
bool computeEffectiveExtent=
false,
bool addPadding=
false);
189 vtkStringArray* segmentIds,
bool computeEffectiveExtent=
false,
bool addPadding=
false);
268 void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId =
"");
314 vtkWarningMacro(
"vtkSegmentation::IsMasterRepresentationPolyData() method is deprecated, please use IsSourceRepresentationPolyData method instead");
324 vtkWarningMacro(
"vtkSegmentation::IsMasterRepresentationImageData() method is deprecated, please use IsSourceRepresentationImageData method instead");
337 vtkWarningMacro(
"vtkSegmentation::InvalidateNonMasterRepresentations() method is deprecated, please use InvalidateNonSourceRepresentations method instead");
357 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues =
nullptr);
371 std::vector<std::string>& sharedSegmentIds,
bool includeOriginalSegmentId=
true);
378 bool includeOriginalSegmentId=
true);
411 int GetLayerIndex(std::string segmentId, std::string representationName=
"");
419 void GetLayerObjects(vtkCollection* layerObjects, std::string representationName =
"");
474 std::string
AddEmptySegment(std::string segmentId=
"", std::string segmentName=
"",
double color[3]=
nullptr);
511 vtkWarningMacro(
"vtkSegmentation::SetMasterRepresentationName() method is deprecated, please use SetSourceRepresentationName method instead");
518 vtkWarningMacro(
"vtkSegmentation::GetMasterRepresentationName() method is deprecated, please use GetSourceRepresentationName method instead");
525 std::map<vtkDataObject*, vtkDataObject*>& cachedRepresentations);
566 static void OnSegmentModified(vtkObject* caller,
unsigned long eid,
void* clientData,
void* callData);
Image data containing orientation information.
This class encapsulates a segment that is part of a segmentation.
Store a list of conversion parameters.
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)
int SegmentIdAutogeneratorIndex
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)