Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkSlicerSegmentEditorLogic.h
Go to the documentation of this file.
1/*==============================================================================
2
3Program: 3D Slicer
4
5Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
6 Queen's University, Kingston, ON, Canada. All Rights Reserved.
7
8 See COPYRIGHT.txt
9 or http://www.slicer.org/copyright/copyright.txt for details.
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 This file was originally developed by Csaba Pinter, PerkLab, Queen's University
18 and was supported through the Applied Cancer Research Unit program of Cancer Care
19 Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
20
21==============================================================================*/
22
23#ifndef __vtkSlicerSegmentEditorLogic_h
24#define __vtkSlicerSegmentEditorLogic_h
25
26// Module export include
27#include "vtkSlicerSegmentationsModuleLogicExport.h"
28
29// MRML includes
33class vtkMRMLNode;
35class vtkMRMLScene;
42
43// vtkSegmentationCore includes
45class vtkSegment;
46class vtkSegmentation;
48
49// VTK includes
50#include <vtkCommand.h>
51#include <vtkSmartPointer.h>
52class vtkMatrix4x4;
53class vtkPolyData;
54
55// STD includes
56#include <string>
57#include <vector>
58
62class VTK_SLICER_SEGMENTATIONS_LOGIC_EXPORT vtkSlicerSegmentEditorLogic : public vtkMRMLAbstractLogic
63{
64public:
67
75
82
88 std::string AddEmptySegment(const std::string& segmentId = "", int segmentStatus = 0) const;
89
91 static void AppendImage(vtkOrientedImageData* inputImage, vtkOrientedImageData* appendedImage);
92
94 static void AppendPolyMask(vtkOrientedImageData* input, vtkPolyData* polyData, vtkMRMLSliceNode* sliceNode, vtkMRMLSegmentationNode* segmentationNode = nullptr);
95
97 bool CanAddSegments() const;
98
100 bool CanRedo() const;
101
104 bool CanRemoveSegments() const;
105
108
110 bool CanUndo() const;
111
113 void ClearUndoState() const;
114
117
121
124
126 static void CreateMaskImageFromPolyData(vtkPolyData* polyData, vtkOrientedImageData* outputMask, vtkMRMLSliceNode* sliceNode);
127
130
133
136 std::string GetCurrentSegmentID() const;
137
140
142 std::string GetDefaultTerminologyEntry() const;
143
146
149
152
157 std::string GetNextSegmentID(int offset, bool visibleOnly) const;
158
161
164
167
171
175 bool GetSegmentationIJKToRAS(vtkMatrix4x4* ijkToRas) const;
176
179
182
185
188
191
193 std::vector<std::string> GetSegmentIDs() const;
194
196 std::vector<std::string> GetVisibleSegmentIDs() const;
197
199 double GetSliceSpacing(vtkMRMLSliceNode* sliceNode) const;
200 static double GetSliceSpacing(vtkMRMLSliceNode* sliceNode, vtkMRMLSliceLogic* sliceLogic);
201
203 bool GetVerbose() const;
204
207 static void ImageToWorldMatrix(vtkMRMLVolumeNode* node, vtkMatrix4x4* ijkToRas);
208
211 static void ImageToWorldMatrix(vtkOrientedImageData* image, vtkMRMLSegmentationNode* node, vtkMatrix4x4* ijkToRas);
212
215
218
220 static bool IsSegmentIdInList(const std::string& segmentID, const std::vector<std::string>& visibleSegmentIDs);
221
223 bool IsSegmentIdValid(const std::string& segmentId) const;
224
226 bool IsSegmentIdVisible(const std::string& segmentID) const;
227
230
232 const char* segmentID,
233 vtkOrientedImageData* modifierLabelmap,
234 ModificationMode modificationMode,
235 bool isPerSegment,
236 bool bypassMasking);
237
239 const char* segmentID,
240 vtkOrientedImageData* modifierLabelmap,
241 ModificationMode modificationMode,
242 const int modificationExtent[6],
243 bool isPerSegment,
244 bool bypassMasking);
245
248
250 static std::array<int, 2> RasToXy(double ras[3], vtkMRMLSliceNode* sliceNode);
251
253 void Redo() const;
254
256 std::string RemoveSelectedSegment() const;
257
263
266
269 bool SaveStateForUndo() const;
270
272 void SelectPreviousSegment(bool visibleOnly) const;
273
275 void SelectNextSegment(bool visibleOnly) const;
276
278 void SelectFirstSegment(bool visibleOnly) const;
279
283 void SelectSegmentAtOffset(int offset, bool visibleOnly) const;
284
286 void SetDefaultTerminologyEntry(const std::string& entry);
287
290
292 void SetCurrentSegmentID(const std::string& segmentID) const;
293
296
299
301 void SetSegmentationNodeID(const std::string& nodeID) const;
302
305 void SetSegmentationHistory(const vtkSmartPointer<vtkSegmentationHistory>& segmentationHistory);
306
311
313 void SetSourceVolumeNodeID(const std::string& nodeID) const;
314
322
326 void SetVerbose(bool isVerbose);
327
329 void ToggleSegmentationSurfaceRepresentation(bool isSurfaceRepresentationOn) const;
330
333
340
342 void Undo() const;
343
350 void UpdateVolume(void* volumeToUpdate, bool& success);
351
354
357
362 bool UpdateMaskLabelmap() const;
363
366
371 static void XyzToRas(double inputXyz[3], double outputRas[3], vtkMRMLSliceNode* sliceNode);
372 static std::array<double, 3> XyzToRas(double inputXyz[3], vtkMRMLSliceNode* sliceNode);
373
375 static void XyToRas(int xy[2], double outputRas[3], vtkMRMLSliceNode* sliceNode);
377 static void XyToRas(double xy[2], double outputRas[3], vtkMRMLSliceNode* sliceNode);
379 static std::array<double, 3> XyToRas(int xy[2], vtkMRMLSliceNode* sliceNode);
381 static void XyzToIjk(double inputXyz[3], int outputIjk[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
383 static std::array<int, 3> XyzToIjk(double inputXyz[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
385 static void XyToIjk(int xy[2], int outputIjk[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
387 static void XyToIjk(double xy[2], int outputIjk[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
389 static std::array<int, 3> XyToIjk(int xy[2], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
390
391protected:
393 void ProcessMRMLNodesEvents(vtkObject* caller, unsigned long event, void* callData) override;
394
397
398private:
399 void UpdateSegmentationNodeObserver(vtkMRMLSegmentationNode* segmentationNode);
400
402 vtkMRMLSegmentEditorNode* SegmentEditorNode;
403 vtkSmartPointer<vtkSegmentationHistory> SegmentationHistory;
404
407 vtkSmartPointer<vtkOrientedImageData> AlignedSourceVolume;
410 vtkSmartPointer<vtkOrientedImageData> ModifierLabelmap;
411 vtkSmartPointer<vtkOrientedImageData> SelectedSegmentLabelmap;
412 vtkSmartPointer<vtkOrientedImageData> MaskLabelmap;
414 vtkSmartPointer<vtkOrientedImageData> ReferenceGeometryImage;
415
418 vtkMRMLVolumeNode* AlignedSourceVolumeUpdateSourceVolumeNode;
419 vtkMRMLTransformNode* AlignedSourceVolumeUpdateSourceVolumeNodeTransform;
420 vtkMRMLTransformNode* AlignedSourceVolumeUpdateSegmentationNodeTransform;
421
422 std::string DefaultTerminologyEntry;
423
424 unsigned long SegmentHistoryObs;
425 vtkMRMLSegmentationNode* SegmentationNodeObs;
426
427 // Warning verbosity level. Default = no warnings.
428 bool IsVerbose;
429};
430
431#endif
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 transformation between this node space and a parent node 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.
Definition vtkSegment.h:45
This class encapsulates a segmentation that can contain multiple segments and multiple representation...
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.
void SetSegmentationNode(vtkMRMLNode *node) const
Set segmentation MRML node.
void Redo() const
Restores next saved state of the segmentation.
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.
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,.
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
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 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.