23#ifndef __vtkSegmentEditorLogic_h
24#define __vtkSegmentEditorLogic_h
27#include "vtkSlicerSegmentationsModuleLogicExport.h"
49#include <vtkCommand.h>
51#include <vtkSmartPointer.h>
52#include <vtkWeakPointer.h>
89 std::string
AddEmptySegment(
const std::string& segmentId =
"",
int segmentStatus = 0)
const;
218 static bool IsSegmentIdInList(
const std::string& segmentID,
const std::vector<std::string>& visibleSegmentIDs);
230 const char* segmentID,
237 const char* segmentID,
240 const int modificationExtent[6],
395 void ReconnectSegmentationNodeObserver();
396 void SynchronizeSegmentationHistorySegmentation()
const;
399 vtkWeakPointer<vtkMRMLSegmentEditorNode> SegmentEditorNode;
400 vtkSmartPointer<vtkSegmentationHistory> SegmentationHistory;
404 vtkSmartPointer<vtkOrientedImageData> AlignedSourceVolume;
407 vtkSmartPointer<vtkOrientedImageData> ModifierLabelmap;
408 vtkSmartPointer<vtkOrientedImageData> SelectedSegmentLabelmap;
409 vtkSmartPointer<vtkOrientedImageData> MaskLabelmap;
411 vtkSmartPointer<vtkOrientedImageData> ReferenceGeometryImage;
419 std::string DefaultTerminologyEntry;
423 unsigned long SegmentEditorNodeObs;
424 unsigned long SegmentHistoryObs;
425 std::tuple<unsigned long, vtkWeakPointer<vtkMRMLSegmentationNode>> SegmentationObs;
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D,...
Abstract Superclass for all specific types of MRML nodes.
MRML node for representing a volume (image stack).
A set of MRML Nodes that supports serialization and undo/redo.
Parameter set node for the segment editor widget.
MRML node containing segmentations.
Slicer logic class for slice manipulation.
MRML node for storing a slice through RAS space.
MRML node for representing a volume (image stack).
Image data containing orientation information.
void ToggleSegmentationSurfaceRepresentation(bool isSurfaceRepresentationOn) const
Create/remove closed surface model for the segmentation that is automatically updated when editing.
double GetSliceSpacing(vtkMRMLSliceNode *sliceNode) const
Return the slice spacing matching the input slice node.
std::string GetNextSegmentID(int offset, bool visibleOnly) const
Returns the segment ID at given offset.
static std::array< int, 2 > RasToXy(double ras[3], vtkMRMLSliceNode *sliceNode)
Convert RAS position to XY in-slice position.
bool TrivialSetSourceRepresentationToBinaryLabelmap() const
std::string GetCurrentSegmentID() const
bool GetSegmentationIJKToRAS(vtkMatrix4x4 *ijkToRas) const
bool IsSegmentIdValid(const std::string &segmentId) const
Return true when Segment ID is defined and present in the current segmentation.
vtkSegmentation * GetSegmentation() const
Current segmentation associated with the segmentation node.
void SetSegmentationNode(vtkMRMLNode *node) const
Set segmentation MRML node.
bool IsSelectedSegmentVisible() const
Return true if the current segment is visible in any view.
static void XyToRas(int xy[2], double outputRas[3], vtkMRMLSliceNode *sliceNode)
Convert XY in-slice position to RAS position.
void ModifySegmentByLabelmap(vtkMRMLSegmentationNode *segmentationNode, const char *segmentID, vtkOrientedImageData *modifierLabelmap, ModificationMode modificationMode, const int modificationExtent[6], bool isPerSegment, bool bypassMasking)
void Redo() const
Restores next saved state of the segmentation.
void SelectNextSegment(bool visibleOnly) const
Selects the next segment in the current segmentation.
bool IsSegmentIdVisible(const std::string &segmentID) const
Return true if the segment ID is visible in any view. False if not visible or invalid.
void CreateAndSetBlankSourceVolumeFromSegmentationGeometry() const
Creates a blank source volume matching the segmentation geometry. Usually called when no source volum...
int GetMaximumNumberOfUndoStates() const
Get maximum number of saved undo/redo states.
void SelectSegmentAtOffset(int offset, bool visibleOnly) const
static void XyToIjk(int xy[2], int outputIjk[3], vtkMRMLSliceNode *sliceNode, vtkOrientedImageData *image, vtkMRMLTransformNode *parentTransform=nullptr)
Convert XY in-slice position to image IJK position.
static void ImageToWorldMatrix(vtkOrientedImageData *image, vtkMRMLSegmentationNode *node, vtkMatrix4x4 *ijkToRas)
static double GetSliceSpacing(vtkMRMLSliceNode *sliceNode, vtkMRMLSliceLogic *sliceLogic)
std::vector< std::string > GetVisibleSegmentIDs() const
Return all segment currently visible in any view.
void SetScene(vtkMRMLScene *newScene)
Set the MRML scene associated with the widget.
void Undo() const
Restores previous saved state of the segmentation.
void ModifySegmentByLabelmap(vtkMRMLSegmentationNode *segmentationNode, const char *segmentID, vtkOrientedImageData *modifierLabelmap, ModificationMode modificationMode, bool isPerSegment, bool bypassMasking)
vtkSegment * GetSelectedSegment() const
Get the current segment. nullptr if invalid or no selection.
static void XyToIjk(double xy[2], int outputIjk[3], vtkMRMLSliceNode *sliceNode, vtkOrientedImageData *image, vtkMRMLTransformNode *parentTransform=nullptr)
Convert XY in-slice position to image IJK position.
bool ContainsClosedSurfaceRepresentation() const
true if the current segmentation is valid and contains a closed surface representation
vtkOrientedImageData * GetMaskLabelmap() const
Returns the current mask labelmap.
bool IsSegmentationDisplayableInView(vtkMRMLAbstractViewNode *viewNode) const
Return true if the current segmentation is displayed in the input view node. False if invalid segment...
bool UpdateMaskLabelmap() const
vtkMRMLSegmentEditorNode * GetSegmentEditorNode() const
Get the segment editor parameter set node.
void SetCurrentSegmentID(const std::string &segmentID) const
Set selected segment by its ID.
void SetApplicationLogic(vtkMRMLApplicationLogic *applicationLogic)
Set the current MRML application logic.
std::string RemoveSelectedSegment() const
Remove the current segment and return the following segment in the list if any valid.
static void ImageToWorldMatrix(vtkMRMLVolumeNode *node, vtkMatrix4x4 *ijkToRas)
@ ModificationModeRemoveAll
std::string AddEmptySegment(const std::string &segmentId="", int segmentStatus=0) const
int GetCurrentSegmentIndex() const
Returns the current segmentation segment index. -1 if invalid.
vtkOrientedImageData * GetAlignedSourceVolume() const
Current aligned source volume.
vtkOrientedImageData * GetSelectedSegmentLabelmap() const
Get the current segments labelmap.
void ExportSegmentationToColorTableNode() const
Export the current segmentation to a new color table node.
static std::array< int, 3 > XyzToIjk(double inputXyz[3], vtkMRMLSliceNode *sliceNode, vtkOrientedImageData *image, vtkMRMLTransformNode *parentTransform=nullptr)
Convert XYZ slice view position to image IJK position, python accessor method,.
bool IsSegmentationNodeValid() const
Return true if the current segmentation node is valid.
void ClearUndoState() const
Clears the Undo/Redo history.
static void AppendPolyMask(vtkOrientedImageData *input, vtkPolyData *polyData, vtkMRMLSliceNode *sliceNode, vtkMRMLSegmentationNode *segmentationNode=nullptr)
Rasterize a poly data onto the input image into the slice view.
static std::array< int, 3 > XyToIjk(int xy[2], vtkMRMLSliceNode *sliceNode, vtkOrientedImageData *image, vtkMRMLTransformNode *parentTransform=nullptr)
Convert XY in-slice position to image IJK position, python accessor method.
void SetSourceVolumeNode(vtkMRMLNode *node) const
static std::string GetReferenceImageGeometryStringFromSegmentation(vtkSegmentation *segmentation)
Returns the reference geometry string matching the input segmentation.
void ResumeRender()
Trigger the ResumeRenderEvent.
vtkMRMLScalarVolumeNode * GetSourceVolumeNode() const
Get the current volume node.
void SelectFirstSegment(bool visibleOnly) const
Selects the first segment in the current segmentation.
bool UpdateSelectedSegmentLabelmap() const
Updates selected segment labelmap in a geometry aligned with default modifierLabelmap.
void SetSegmentationNodeID(const std::string &nodeID) const
Set segmentation MRML node by its ID.
static void XyToRas(double xy[2], double outputRas[3], vtkMRMLSliceNode *sliceNode)
Convert XY in-slice position to RAS position.
void SetSegmentationHistory(const vtkSmartPointer< vtkSegmentationHistory > &segmentationHistory)
bool UpdateReferenceGeometryImage() const
Update the reference geometry image to the current segmentation.
bool CanTriviallyConvertSourceRepresentationToBinaryLabelMap() const
void SetSegmentEditorNode(vtkMRMLSegmentEditorNode *newSegmentEditorNode)
Set the segment editor parameter set node.
std::vector< std::string > GetSegmentIDs() const
Return all the segment IDS present in the segmentation. Empty if invalid or no segment.
static void XyzToIjk(double inputXyz[3], int outputIjk[3], vtkMRMLSliceNode *sliceNode, vtkOrientedImageData *image, vtkMRMLTransformNode *parentTransform=nullptr)
Convert XYZ slice view position to image IJK position,.
@ SegmentationHistoryChangedEvent
static void CreateMaskImageFromPolyData(vtkPolyData *polyData, vtkOrientedImageData *outputMask, vtkMRMLSliceNode *sliceNode)
Create a slice view screen space (2D) mask image for the given polydata.
~vtkSegmentEditorLogic() override
static void XyzToRas(double inputXyz[3], double outputRas[3], vtkMRMLSliceNode *sliceNode)
vtkOrientedImageData * GetModifierLabelmap() const
Returns the current modifier label map.
bool SaveStateForUndo() const
vtkMRMLSegmentationNode * GetSegmentationNode() const
Get currently selected segmentation MRML node.
void SetDefaultTerminologyEntry(const std::string &entry)
Set the default terminology to use when adding new segments.
void UpdateVolume(void *volumeToUpdate, bool &success)
std::string GetDefaultTerminologyEntry() const
Returns the terminology entry value used as default when adding empty segments.
void SetSourceVolumeNodeID(const std::string &nodeID) const
Set source volume MRML node by its ID.
static std::array< double, 3 > XyToRas(int xy[2], vtkMRMLSliceNode *sliceNode)
Convert XY in-slice position to RAS position, python accessor method.
bool SetSourceRepresentationToBinaryLabelMap() const
bool CanAddSegments() const
void CreateAndSetBlankSourceVolumeIfNeeded() const
If no source volume is selected but a valid geometry is specified then create and store a blank sourc...
bool CanRemoveSegments() const
vtkOrientedImageData * GetReferenceGeometryImage() const
Returns the current reference geometry image.
static bool IsSegmentIdInList(const std::string &segmentID, const std::vector< std::string > &visibleSegmentIDs)
Return true if the segment ID is present in the input list.
std::string GetReferenceImageGeometryString() const
Returns the current reference geometry string.
bool UpdateAlignedSourceVolume()
Updates a resampled source volume in a geometry aligned with default modifierLabelmap.
static std::array< double, 3 > XyzToRas(double inputXyz[3], vtkMRMLSliceNode *sliceNode)
void ToggleSourceVolumeIntensityMask() const
Toggle the intensity mask currently set on the segmentation.
void SetMaximumNumberOfUndoStates(int) const
Set maximum number of saved undo/redo states.
void PauseRender()
Trigger the PauseRenderEvent.
void SelectPreviousSegment(bool visibleOnly) const
Selects the previous segment in the current segmentation.
static void AppendImage(vtkOrientedImageData *inputImage, vtkOrientedImageData *appendedImage)
Append image onto image. Resamples appended image and saves result in input image.
bool ResetModifierLabelmapToDefault() const
static vtkSegmentEditorLogic * New()
This class encapsulates a segment that is part of a segmentation.
This class encapsulates a segmentation that can contain multiple segments and multiple representation...