23#ifndef __vtkSlicerSegmentEditorLogic_h
24#define __vtkSlicerSegmentEditorLogic_h
27#include "vtkSlicerSegmentationsModuleLogicExport.h"
50#include <vtkCommand.h>
51#include <vtkSmartPointer.h>
88 std::string
AddEmptySegment(
const std::string& segmentId =
"",
int segmentStatus = 0)
const;
220 static bool IsSegmentIdInList(
const std::string& segmentID,
const std::vector<std::string>& visibleSegmentIDs);
232 const char* segmentID,
239 const char* segmentID,
242 const int modificationExtent[6],
403 vtkSmartPointer<vtkSegmentationHistory> SegmentationHistory;
407 vtkSmartPointer<vtkOrientedImageData> AlignedSourceVolume;
410 vtkSmartPointer<vtkOrientedImageData> ModifierLabelmap;
411 vtkSmartPointer<vtkOrientedImageData> SelectedSegmentLabelmap;
412 vtkSmartPointer<vtkOrientedImageData> MaskLabelmap;
414 vtkSmartPointer<vtkOrientedImageData> ReferenceGeometryImage;
422 std::string DefaultTerminologyEntry;
424 unsigned long SegmentHistoryObs;
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.
This class encapsulates a segment that is part of a segmentation.
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
bool CanAddSegments() const
std::string GetCurrentSegmentID() const
static void AppendPolyMask(vtkOrientedImageData *input, vtkPolyData *polyData, vtkMRMLSliceNode *sliceNode, vtkMRMLSegmentationNode *segmentationNode=nullptr)
Rasterize a poly data onto the input image into the slice view.
bool IsSegmentIdVisible(const std::string &segmentID) const
Return true if the segment ID is visible in any view. False if not visible or invalid.
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.
static std::array< double, 3 > XyzToRas(double inputXyz[3], vtkMRMLSliceNode *sliceNode)
void ExportSegmentationToColorTableNode() const
Export the current segmentation to a new color table node.
bool UpdateAlignedSourceVolume()
Updates a resampled source volume in a geometry aligned with default modifierLabelmap.
vtkMRMLSegmentEditorNode * GetSegmentEditorNode() const
Get the segment editor parameter set node.
static void ImageToWorldMatrix(vtkOrientedImageData *image, vtkMRMLSegmentationNode *node, vtkMatrix4x4 *ijkToRas)
std::vector< std::string > GetSegmentIDs() const
Return all the segment IDS present in the segmentation. Empty if invalid or no segment.
bool GetVerbose() const
Returns warning verbosity.
bool SetSourceRepresentationToBinaryLabelMap() const
void SetVerbose(bool isVerbose)
bool IsSelectedSegmentVisible() const
Return true if the current segment is visible in any view.
void SelectSegmentAtOffset(int offset, bool visibleOnly) const
vtkMRMLSegmentationNode * GetSegmentationNode() const
Get currently selected segmentation MRML node.
vtkOrientedImageData * GetMaskLabelmap() const
Returns the current mask labelmap.
bool CanRemoveSegments() const
void SetSegmentationNode(vtkMRMLNode *node) const
Set segmentation MRML node.
void Redo() const
Restores next saved state of the segmentation.
vtkSlicerSegmentEditorLogic()
vtkOrientedImageData * GetModifierLabelmap() const
Returns the current modifier label map.
std::string RemoveSelectedSegment() const
Remove the current segment and return the following segment in the list if any valid.
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.
void UpdateVolume(void *volumeToUpdate, bool &success)
vtkOrientedImageData * GetSelectedSegmentLabelmap() const
Get the current segments labelmap.
std::string AddEmptySegment(const std::string &segmentId="", int segmentStatus=0) const
void SelectFirstSegment(bool visibleOnly) const
Selects the first segment in the current segmentation.
static void XyToRas(double xy[2], double outputRas[3], vtkMRMLSliceNode *sliceNode)
Convert XY in-slice position to RAS position.
static std::string GetReferenceImageGeometryStringFromSegmentation(vtkSegmentation *segmentation)
Returns the reference geometry string matching the input segmentation.
vtkOrientedImageData * GetReferenceGeometryImage() const
Returns the current reference geometry image.
int GetMaximumNumberOfUndoStates() const
Get maximum number of saved undo/redo states.
double GetSliceSpacing(vtkMRMLSliceNode *sliceNode) const
Return the slice spacing matching the input slice node.
void PauseRender()
Trigger the PauseRenderEvent.
static void CreateMaskImageFromPolyData(vtkPolyData *polyData, vtkOrientedImageData *outputMask, vtkMRMLSliceNode *sliceNode)
Create a slice view screen space (2D) mask image for the given polydata.
void ToggleSourceVolumeIntensityMask() const
Toggle the intensity mask currently set on the segmentation.
void CreateAndSetBlankSourceVolumeIfNeeded() const
If no source volume is selected but a valid geometry is specified then create and store a blank sourc...
std::string GetNextSegmentID(int offset, bool visibleOnly) const
Returns the segment ID at given offset.
bool IsSegmentIdValid(const std::string &segmentId) const
Return true when Segment ID is defined and present in the current segmentation.
void ResumeRender()
Trigger the ResumeRenderEvent.
void ProcessMRMLNodesEvents(vtkObject *caller, unsigned long event, void *callData) override
Update segment editor node, segmentation node and segment history observers.
void ModifySegmentByLabelmap(vtkMRMLSegmentationNode *segmentationNode, const char *segmentID, vtkOrientedImageData *modifierLabelmap, ModificationMode modificationMode, bool isPerSegment, bool bypassMasking)
void SetMaximumNumberOfUndoStates(int) const
Set maximum number of saved undo/redo states.
bool IsSegmentationNodeValid() const
Return true if the current segmentation node is valid.
static double GetSliceSpacing(vtkMRMLSliceNode *sliceNode, vtkMRMLSliceLogic *sliceLogic)
void ClearUndoState() const
Clears the Undo/Redo history.
static void XyzToRas(double inputXyz[3], double outputRas[3], vtkMRMLSliceNode *sliceNode)
void Undo() const
Restores previous saved state of the segmentation.
bool SaveStateForUndo() const
int GetCurrentSegmentIndex() const
Returns the current segmentation segment index. -1 if invalid.
std::string GetReferenceImageGeometryString() const
Returns the current reference geometry string.
void CreateAndSetBlankSourceVolumeFromSegmentationGeometry() const
Creates a blank source volume matching the segmentation geometry. Usually called when no source volum...
std::string GetDefaultTerminologyEntry() const
Returns the terminology entry value used as default when adding empty segments.
void SetSegmentationNodeID(const std::string &nodeID) const
Set segmentation MRML node by its ID.
bool UpdateSelectedSegmentLabelmap() const
Updates selected segment labelmap in a geometry aligned with default modifierLabelmap.
void SetSegmentEditorNode(vtkMRMLSegmentEditorNode *newSegmentEditorNode)
Set the segment editor parameter set node.
static std::array< int, 2 > RasToXy(double ras[3], vtkMRMLSliceNode *sliceNode)
Convert RAS position to XY in-slice position.
static std::array< double, 3 > XyToRas(int xy[2], vtkMRMLSliceNode *sliceNode)
Convert XY in-slice position to RAS position, python accessor method.
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 XyzToIjk(double inputXyz[3], int outputIjk[3], vtkMRMLSliceNode *sliceNode, vtkOrientedImageData *image, vtkMRMLTransformNode *parentTransform=nullptr)
Convert XYZ slice view position to image IJK position,.
vtkSegmentation * GetSegmentation() const
Current segmentation associated with the segmentation node.
void SetDefaultTerminologyEntry(const std::string &entry)
Set the default terminology to use when adding new segments.
void SetSourceVolumeNode(vtkMRMLNode *node) const
static vtkSlicerSegmentEditorLogic * New()
void SetSegmentationHistory(const vtkSmartPointer< vtkSegmentationHistory > &segmentationHistory)
vtkOrientedImageData * GetAlignedSourceVolume() const
Current aligned source volume.
bool UpdateReferenceGeometryImage() const
Update the reference geometry image to the current segmentation.
vtkMRMLScalarVolumeNode * GetSourceVolumeNode() const
Get the current volume node.
void SelectNextSegment(bool visibleOnly) const
Selects the next segment in the current segmentation.
void ModifySegmentByLabelmap(vtkMRMLSegmentationNode *segmentationNode, const char *segmentID, vtkOrientedImageData *modifierLabelmap, ModificationMode modificationMode, const int modificationExtent[6], bool isPerSegment, bool bypassMasking)
std::vector< std::string > GetVisibleSegmentIDs() const
Return all segment currently visible in any view.
static void ImageToWorldMatrix(vtkMRMLVolumeNode *node, vtkMatrix4x4 *ijkToRas)
bool CanTriviallyConvertSourceRepresentationToBinaryLabelMap() const
static void XyToRas(int xy[2], double outputRas[3], vtkMRMLSliceNode *sliceNode)
Convert XY in-slice position to RAS position.
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,.
@ SegmentationHistoryChangedEvent
void SelectPreviousSegment(bool visibleOnly) const
Selects the previous segment in the current segmentation.
bool TrivialSetSourceRepresentationToBinaryLabelmap() const
bool IsSegmentationDisplayableInView(vtkMRMLAbstractViewNode *viewNode) const
Return true if the current segmentation is displayed in the input view node. False if invalid segment...
bool GetSegmentationIJKToRAS(vtkMatrix4x4 *ijkToRas) const
void SetSourceVolumeNodeID(const std::string &nodeID) const
Set source volume MRML node by its ID.
bool ContainsClosedSurfaceRepresentation() const
true if the current segmentation is valid and contains a closed surface representation
@ ModificationModeRemoveAll
void SetCurrentSegmentID(const std::string &segmentID) const
Set selected segment by its ID.
void ToggleSegmentationSurfaceRepresentation(bool isSurfaceRepresentationOn) const
Create/remove closed surface model for the segmentation that is automatically updated when editing.
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.
bool UpdateMaskLabelmap() const
bool ResetModifierLabelmapToDefault() const
vtkSegment * GetSelectedSegment() const
Get the current segment. nullptr if invalid or no selection.
~vtkSlicerSegmentEditorLogic() override
static void AppendImage(vtkOrientedImageData *inputImage, vtkOrientedImageData *appendedImage)
Append image onto image. Resamples appended image and saves result in input image.