21 #ifndef __vtkSegmentation_h 22 #define __vtkSegmentation_h 25 #include <vtkObject.h> 26 #include <vtkSmartPointer.h> 38 #include "vtkSegmentationCoreConfigure.h" 40 class vtkAbstractTransform;
41 class vtkCallbackCommand;
98 MasterRepresentationModified = 62100,
127 EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_AND_REFERENCE_GEOMETRY
131 typedef std::map<std::string, vtkSmartPointer<vtkSegment> >
SegmentMap;
136 void PrintSelf(ostream& os, vtkIndent indent)
override;
139 virtual void ReadXMLAttributes(
const char** atts);
142 virtual void WriteXML(ostream& of,
int indent);
151 virtual void GetBounds(
double bounds[6]);
155 virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
159 virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
162 std::string DetermineCommonLabelmapGeometry(
int extentComputationMode = EXTENT_UNION_OF_SEGMENTS,
const std::vector<std::string>& segmentIDs = std::vector<std::string>());
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__ 182 std::string DetermineCommonLabelmapGeometry(
int extentComputationMode, vtkStringArray* segmentIds);
185 void DetermineCommonLabelmapExtent(
int commonGeometryExtent[6],
vtkOrientedImageData* commonGeometryImage,
186 vtkStringArray* segmentIds,
bool computeEffectiveExtent=
false,
bool addPadding=
false);
190 bool SetImageGeometryFromCommonLabelmapGeometry(
vtkOrientedImageData* imageData, vtkStringArray* segmentIDs =
nullptr,
207 bool AddSegment(
vtkSegment* segment, std::string segmentId =
"", std::string insertBeforeSegmentId =
"");
212 std::string GenerateUniqueSegmentID(std::string
id);
216 void RemoveSegment(std::string segmentId);
223 void RemoveAllSegments();
227 vtkSegment* GetSegment(std::string segmentId);
230 void GetSegmentIDs(std::vector<std::string> &segmentIds);
233 void GetSegmentIDs(vtkStringArray* segmentIds);
236 std::vector<std::string> GetSegmentIDs();
239 int GetNumberOfSegments()
const;
242 vtkSegment* GetNthSegment(
unsigned int index)
const;
245 std::string GetNthSegmentID(
unsigned int index)
const;
250 int GetSegmentIndex(
const std::string& segmentId);
255 bool SetSegmentIndex(
const std::string& segmentId,
unsigned int newIndex);
261 void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId =
"");
265 std::string GetSegmentIdBySegment(
vtkSegment* segment);
270 std::string GetSegmentIdBySegmentName(std::string name);
276 std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value=
"");
279 vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
287 bool CopySegmentFromSegmentation(
vtkSegmentation* fromSegmentation, std::string segmentId,
bool removeFromSource=
false);
294 void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
299 bool ContainsRepresentation(std::string representationName);
302 bool IsMasterRepresentationPolyData();
305 bool IsMasterRepresentationImageData();
311 void InvalidateNonMasterRepresentations();
329 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues =
nullptr);
330 #endif // __VTK_WRAP__ 335 bool IsSharedBinaryLabelmap(std::string segmentID);
342 void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName,
343 std::vector<std::string>& sharedSegmentIds,
bool includeOriginalSegmentId=
true);
349 void GetSegmentIDsSharingBinaryLabelmapRepresentation(std::string originalSegmentId, std::vector<std::string> &sharedSegmentIds,
350 bool includeOriginalSegmentId=
true);
355 int GetUniqueLabelValueForSharedLabelmap(std::string segmentId);
365 void MergeSegmentLabelmaps(std::vector<std::string> mergeSegmentIds);
368 void SeparateSegmentLabelmap(std::string segmentId);
373 void ClearSegment(std::string segmentId);
379 int GetNumberOfLayers(std::string representationName=
"");
383 int GetLayerIndex(std::string segmentId, std::string representationName=
"");
387 vtkDataObject* GetLayerDataObject(
int layer, std::string representationName=
"");
391 void GetLayerObjects(vtkCollection* layerObjects, std::string representationName =
"");
395 std::vector<std::string> GetSegmentIDsForLayer(
int layer, std::string representationName =
"");
399 std::vector<std::string> GetSegmentIDsForDataObject(vtkDataObject* dataObject, std::string representationName =
"");
404 void CollapseBinaryLabelmaps(
bool forceToSingleLayer=
false);
418 bool CreateRepresentation(
const std::string& targetRepresentationName,
bool alwaysConvert=
false);
429 void RemoveRepresentation(
const std::string& representationName);
435 bool CanAcceptRepresentation(std::string representationName);
446 std::string AddEmptySegment(std::string segmentId=
"", std::string segmentName=
"",
double color[3]=
nullptr);
449 void GetPossibleConversions(
const std::string& targetRepresentationName,
453 void SetConversionParameter(
const std::string& name,
const std::string& value) { this->Converter->SetConversionParameter(name, value); };
465 std::string SerializeAllConversionParameters();
469 void DeserializeConversionParameters(std::string conversionParametersString);
474 vtkGetMacro(MasterRepresentationName, std::string);
478 virtual void SetMasterRepresentationName(
const std::string& representationName);
483 std::map<vtkDataObject*, vtkDataObject*>& cachedRepresentations);
497 bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
501 void RemoveSegment(SegmentMap::iterator segmentIt);
507 bool SetMasterRepresentationModifiedEnabled(
bool enabled);
513 bool SetSegmentModifiedEnabled(
bool enabled);
518 static void OnSegmentModified(vtkObject* caller,
unsigned long eid,
void* clientData,
void* callData);
522 static void OnMasterRepresentationModified(vtkObject* caller,
unsigned long eid,
void* clientData,
void* callData);
526 void UpdateMasterRepresentationObservers();
571 friend class qMRMLSegmentEditorWidgetPrivate;
578 #endif // __vtkSegmentation_h Invoked if a representation is created or removed in the segments (e.g., created by conversion from m...
This class encapsulates a segment that is part of a segmentation.
void GetAvailableRepresentationNames(std::set< std::string > &representationNames)
Get all representations supported by the converter.
std::vector< ConversionPathAndCostType > ConversionPathAndCostListType
int SegmentIdAutogeneratorIndex
Extent is computed as union of extent of all segments, with a single-voxel padding added on each side...
std::set< vtkSmartPointer< vtkDataObject > > MasterRepresentationCache
bool MasterRepresentationModifiedEnabled
Modified events of master representations are observed.
void GetConversionParametersForPath(vtkSegmentationConverterRule::ConversionParameterListType &conversionParameters, const vtkSegmentationConverter::ConversionPathType &path)
Get names of all conversion parameters used by the selected conversion path.
Image data containing orientation information.
vtkCallbackCommand * MasterRepresentationCallbackCommand
Command handling master representation modified events.
std::deque< std::string > SegmentIds
Invoked if new segment is added.
std::vector< vtkSegmentationConverterRule * > ConversionPathType
vtkCallbackCommand * SegmentCallbackCommand
Command handling segment modified events.
bool SegmentModifiedEnabled
Modified events of segments are observed.
Invoked if segment IDs order is changed. Not called when a segment is added or removed.
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
std::map< std::string, std::pair< std::string, std::string > > ConversionParameterListType
std::string MasterRepresentationName
std::string GetConversionParameter(const std::string &name)
Extent is computed as union of extent of all segments.
Extent is computed as union of effective extent of all segments.
Invoked when content of any representation (including the master representation) in a segment is chan...
Extent is computed as union of effective extent of all segments, with a single-voxel padding added on...
Invoked if a segment is removed.
void SetConversionParameter(const std::string &name, const std::string &value)
Set a conversion parameter to all rules having this parameter.
Utility functions for resampling oriented image data.
vtkSegmentationConverter * Converter
Converter instance.
std::map< std::string, vtkSmartPointer< vtkSegment > > SegmentMap
Container type for segments. Maps segment IDs to segment objects.
SegmentMap Segments
Container of segments that belong to this segmentation.
Extent of common geometry is used as extent.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...
Class that can convert between different representations of a segment.