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,
125 EXTENT_UNION_OF_EFFECTIVE_SEGMENTS_PADDED
129 typedef std::map<std::string, vtkSmartPointer<vtkSegment> >
SegmentMap;
134 void PrintSelf(ostream& os, vtkIndent indent)
override;
137 virtual void ReadXMLAttributes(
const char** atts);
140 virtual void WriteXML(ostream& of,
int indent);
149 virtual void GetBounds(
double bounds[6]);
153 virtual void ApplyLinearTransform(vtkAbstractTransform* transform);
157 virtual void ApplyNonLinearTransform(vtkAbstractTransform* transform);
160 std::string DetermineCommonLabelmapGeometry(
int extentComputationMode = EXTENT_UNION_OF_SEGMENTS,
const std::vector<std::string>& segmentIDs = std::vector<std::string>());
175 void DetermineCommonLabelmapExtent(
int commonGeometryExtent[6],
vtkOrientedImageData* commonGeometryImage,
176 const std::vector<std::string>& segmentIDs = std::vector<std::string>(),
bool computeEffectiveExtent=
false,
bool addPadding=
false);
177 #endif // __VTK_WRAP__ 180 std::string DetermineCommonLabelmapGeometry(
int extentComputationMode, vtkStringArray* segmentIds);
183 void DetermineCommonLabelmapExtent(
int commonGeometryExtent[6],
vtkOrientedImageData* commonGeometryImage,
184 vtkStringArray* segmentIds,
bool computeEffectiveExtent=
false,
bool addPadding=
false);
188 bool SetImageGeometryFromCommonLabelmapGeometry(
vtkOrientedImageData* imageData, vtkStringArray* segmentIDs =
nullptr,
205 bool AddSegment(
vtkSegment* segment, std::string segmentId =
"", std::string insertBeforeSegmentId =
"");
210 std::string GenerateUniqueSegmentID(std::string
id);
214 void RemoveSegment(std::string segmentId);
221 void RemoveAllSegments();
225 vtkSegment* GetSegment(std::string segmentId);
228 void GetSegmentIDs(std::vector<std::string> &segmentIds);
231 void GetSegmentIDs(vtkStringArray* segmentIds);
234 int GetNumberOfSegments()
const;
237 vtkSegment* GetNthSegment(
unsigned int index)
const;
240 std::string GetNthSegmentID(
unsigned int index)
const;
245 int GetSegmentIndex(
const std::string& segmentId);
250 bool SetSegmentIndex(
const std::string& segmentId,
unsigned int newIndex);
256 void ReorderSegments(std::vector<std::string> segmentIdsToMove, std::string insertBeforeSegmentId =
"");
260 std::string GetSegmentIdBySegment(
vtkSegment* segment);
265 std::string GetSegmentIdBySegmentName(std::string name);
271 std::vector<vtkSegment*> GetSegmentsByTag(std::string tag, std::string value=
"");
274 vtkDataObject* GetSegmentRepresentation(std::string segmentId, std::string representationName);
282 bool CopySegmentFromSegmentation(
vtkSegmentation* fromSegmentation, std::string segmentId,
bool removeFromSource=
false);
289 void GetContainedRepresentationNames(std::vector<std::string>& representationNames);
294 bool ContainsRepresentation(std::string representationName);
297 bool IsMasterRepresentationPolyData();
300 bool IsMasterRepresentationImageData();
306 void InvalidateNonMasterRepresentations();
324 const std::vector<std::string>& segmentIDs = std::vector<std::string>(), vtkIntArray* labelValues =
nullptr);
325 #endif // __VTK_WRAP__ 330 bool IsSharedBinaryLabelmap(std::string segmentID);
337 void GetSegmentIDsSharingRepresentation(std::string originalSegmentId, std::string representationName,
338 std::vector<std::string>& sharedSegmentIds,
bool includeOriginalSegmentId=
true);
344 void GetSegmentIDsSharingBinaryLabelmapRepresentation(std::string originalSegmentId, std::vector<std::string> &sharedSegmentIds,
345 bool includeOriginalSegmentId=
true);
350 int GetUniqueLabelValueForSharedLabelmap(std::string segmentId);
360 void MergeSegmentLabelmaps(std::vector<std::string> mergeSegmentIds);
363 void SeparateSegmentLabelmap(std::string segmentId);
368 void ClearSegment(std::string segmentId);
374 int GetNumberOfLayers(std::string representationName=
"");
378 int GetLayerIndex(std::string segmentId, std::string representationName=
"");
382 vtkDataObject* GetLayerDataObject(
int layer, std::string representationName=
"");
386 void GetLayerObjects(vtkCollection* layerObjects, std::string representationName =
"");
390 std::vector<std::string> GetSegmentIDsForLayer(
int layer, std::string representationName =
"");
394 std::vector<std::string> GetSegmentIDsForDataObject(vtkDataObject* dataObject, std::string representationName =
"");
399 void CollapseBinaryLabelmaps(
bool forceToSingleLayer=
false);
413 bool CreateRepresentation(
const std::string& targetRepresentationName,
bool alwaysConvert=
false);
424 void RemoveRepresentation(
const std::string& representationName);
430 bool CanAcceptRepresentation(std::string representationName);
441 std::string AddEmptySegment(std::string segmentId=
"", std::string segmentName=
"",
double color[3]=
nullptr);
444 void GetPossibleConversions(
const std::string& targetRepresentationName,
448 void SetConversionParameter(
const std::string& name,
const std::string& value) { this->Converter->SetConversionParameter(name, value); };
460 std::string SerializeAllConversionParameters();
464 void DeserializeConversionParameters(std::string conversionParametersString);
469 vtkGetMacro(MasterRepresentationName, std::string);
473 virtual void SetMasterRepresentationName(
const std::string& representationName);
478 std::map<vtkDataObject*, vtkDataObject*>& cachedRepresentations);
492 bool ConvertSingleSegment(std::string segmentId, std::string targetRepresentationName);
496 void RemoveSegment(SegmentMap::iterator segmentIt);
502 bool SetMasterRepresentationModifiedEnabled(
bool enabled);
508 bool SetSegmentModifiedEnabled(
bool enabled);
513 static void OnSegmentModified(vtkObject* caller,
unsigned long eid,
void* clientData,
void* callData);
517 static void OnMasterRepresentationModified(vtkObject* caller,
unsigned long eid,
void* clientData,
void* callData);
521 void UpdateMasterRepresentationObservers();
566 friend class qMRMLSegmentEditorWidgetPrivate;
573 #endif // __vtkSegmentation_h 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.
Extent is computed as union of extent of all segments, with a single-voxel padding added on each side...
Extent is computed as union of extent of all segments.
Invoked if segment IDs order is changed. Not called when a segment is added or removed.
std::vector< ConversionPathAndCostType > ConversionPathAndCostListType
Invoked when content of any representation (including the master representation) in a segment is chan...
int SegmentIdAutogeneratorIndex
std::set< vtkSmartPointer< vtkDataObject > > MasterRepresentationCache
Invoked if new segment is added.
bool MasterRepresentationModifiedEnabled
Modified events of master representations are observed.
Invoked if a representation is created or removed in the segments (e.g., created by conversion from m...
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.
Invoked if a segment is removed.
vtkCallbackCommand * MasterRepresentationCallbackCommand
Command handling master representation modified events.
std::deque< std::string > SegmentIds
std::vector< vtkSegmentationConverterRule * > ConversionPathType
vtkCallbackCommand * SegmentCallbackCommand
Command handling segment modified events.
bool SegmentModifiedEnabled
Modified events of segments are observed.
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
Extent of common geometry is used as extent.
std::string GetConversionParameter(const std::string &name)
Extent is computed as union of effective extent of all segments.
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.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...
Class that can convert between different representations of a segment.