Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkSegmentEditorLogic.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 __vtkSegmentEditorLogic_h
24#define __vtkSegmentEditorLogic_h
25
26// Module export include
27#include "vtkSlicerSegmentationsModuleLogicExport.h"
28
29// MRML includes
32class vtkMRMLNode;
34class vtkMRMLScene;
41
42// vtkSegmentationCore includes
44class vtkSegment;
45class vtkSegmentation;
47
48// VTK includes
49#include <vtkCommand.h>
50#include <vtkObject.h>
51#include <vtkSmartPointer.h>
52#include <vtkWeakPointer.h>
53class vtkMatrix4x4;
54class vtkPolyData;
55
56// STD includes
57#include <string>
58#include <vector>
59
63class VTK_SLICER_SEGMENTATIONS_LOGIC_EXPORT vtkSegmentEditorLogic : public vtkObject
64{
65public:
67 vtkTypeMacro(vtkSegmentEditorLogic, vtkObject);
68
76
83
89 std::string AddEmptySegment(const std::string& segmentId = "", int segmentStatus = 0) const;
90
92 static void AppendImage(vtkOrientedImageData* inputImage, vtkOrientedImageData* appendedImage);
93
95 static void AppendPolyMask(vtkOrientedImageData* input, vtkPolyData* polyData, vtkMRMLSliceNode* sliceNode, vtkMRMLSegmentationNode* segmentationNode = nullptr);
96
98 bool CanAddSegments() const;
99
101 bool CanRedo() const;
102
105 bool CanRemoveSegments() const;
106
109
111 bool CanUndo() const;
112
114 void ClearUndoState() const;
115
118
122
125
127 static void CreateMaskImageFromPolyData(vtkPolyData* polyData, vtkOrientedImageData* outputMask, vtkMRMLSliceNode* sliceNode);
128
131
134
137 std::string GetCurrentSegmentID() const;
138
141
143 std::string GetDefaultTerminologyEntry() const;
144
147
150
153
158 std::string GetNextSegmentID(int offset, bool visibleOnly) const;
159
162
165
168
172
176 bool GetSegmentationIJKToRAS(vtkMatrix4x4* ijkToRas) const;
177
180
183
186
189
192
194 std::vector<std::string> GetSegmentIDs() const;
195
197 std::vector<std::string> GetVisibleSegmentIDs() const;
198
200 double GetSliceSpacing(vtkMRMLSliceNode* sliceNode) const;
201 static double GetSliceSpacing(vtkMRMLSliceNode* sliceNode, vtkMRMLSliceLogic* sliceLogic);
202
205 static void ImageToWorldMatrix(vtkMRMLVolumeNode* node, vtkMatrix4x4* ijkToRas);
206
209 static void ImageToWorldMatrix(vtkOrientedImageData* image, vtkMRMLSegmentationNode* node, vtkMatrix4x4* ijkToRas);
210
213
216
218 static bool IsSegmentIdInList(const std::string& segmentID, const std::vector<std::string>& visibleSegmentIDs);
219
221 bool IsSegmentIdValid(const std::string& segmentId) const;
222
224 bool IsSegmentIdVisible(const std::string& segmentID) const;
225
228
230 const char* segmentID,
231 vtkOrientedImageData* modifierLabelmap,
232 ModificationMode modificationMode,
233 bool isPerSegment,
234 bool bypassMasking);
235
237 const char* segmentID,
238 vtkOrientedImageData* modifierLabelmap,
239 ModificationMode modificationMode,
240 const int modificationExtent[6],
241 bool isPerSegment,
242 bool bypassMasking);
243
246
248 static std::array<int, 2> RasToXy(double ras[3], vtkMRMLSliceNode* sliceNode);
249
251 void Redo() const;
252
254 std::string RemoveSelectedSegment() const;
255
261
264
267 bool SaveStateForUndo() const;
268
270 void SelectPreviousSegment(bool visibleOnly) const;
271
273 void SelectNextSegment(bool visibleOnly) const;
274
276 void SelectFirstSegment(bool visibleOnly) const;
277
281 void SelectSegmentAtOffset(int offset, bool visibleOnly) const;
282
285
287 void SetDefaultTerminologyEntry(const std::string& entry);
288
291
293 void SetScene(vtkMRMLScene* newScene);
294
296 void SetCurrentSegmentID(const std::string& segmentID) const;
297
300
303
305 void SetSegmentationNodeID(const std::string& nodeID) const;
306
309 void SetSegmentationHistory(const vtkSmartPointer<vtkSegmentationHistory>& segmentationHistory);
310
315
317 void SetSourceVolumeNodeID(const std::string& nodeID) const;
318
326
328 void ToggleSegmentationSurfaceRepresentation(bool isSurfaceRepresentationOn) const;
329
332
339
341 void Undo() const;
342
349 void UpdateVolume(void* volumeToUpdate, bool& success);
350
353
356
361 bool UpdateMaskLabelmap() const;
362
365
370 static void XyzToRas(double inputXyz[3], double outputRas[3], vtkMRMLSliceNode* sliceNode);
371 static std::array<double, 3> XyzToRas(double inputXyz[3], vtkMRMLSliceNode* sliceNode);
372
374 static void XyToRas(int xy[2], double outputRas[3], vtkMRMLSliceNode* sliceNode);
376 static void XyToRas(double xy[2], double outputRas[3], vtkMRMLSliceNode* sliceNode);
378 static std::array<double, 3> XyToRas(int xy[2], vtkMRMLSliceNode* sliceNode);
380 static void XyzToIjk(double inputXyz[3], int outputIjk[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
382 static std::array<int, 3> XyzToIjk(double inputXyz[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
384 static void XyToIjk(int xy[2], int outputIjk[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
386 static void XyToIjk(double xy[2], int outputIjk[3], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
388 static std::array<int, 3> XyToIjk(int xy[2], vtkMRMLSliceNode* sliceNode, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
389
390protected:
393
394private:
395 void ReconnectSegmentationNodeObserver();
396 void SynchronizeSegmentationHistorySegmentation() const;
397
399 vtkWeakPointer<vtkMRMLSegmentEditorNode> SegmentEditorNode;
400 vtkSmartPointer<vtkSegmentationHistory> SegmentationHistory;
401
404 vtkSmartPointer<vtkOrientedImageData> AlignedSourceVolume;
407 vtkSmartPointer<vtkOrientedImageData> ModifierLabelmap;
408 vtkSmartPointer<vtkOrientedImageData> SelectedSegmentLabelmap;
409 vtkSmartPointer<vtkOrientedImageData> MaskLabelmap;
411 vtkSmartPointer<vtkOrientedImageData> ReferenceGeometryImage;
412
415 vtkMRMLVolumeNode* AlignedSourceVolumeUpdateSourceVolumeNode;
416 vtkMRMLTransformNode* AlignedSourceVolumeUpdateSourceVolumeNodeTransform;
417 vtkMRMLTransformNode* AlignedSourceVolumeUpdateSegmentationNodeTransform;
418
419 std::string DefaultTerminologyEntry;
420
421 vtkMRMLScene* MRMLScene;
422
423 unsigned long SegmentEditorNodeObs;
424 unsigned long SegmentHistoryObs;
425 std::tuple<unsigned long, vtkWeakPointer<vtkMRMLSegmentationNode>> SegmentationObs;
426 vtkMRMLApplicationLogic* ApplicationLogic;
427};
428
429#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.
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)
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.
bool CanRedo() const
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,.
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.
bool CanUndo() const
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.
Definition vtkSegment.h:45
This class encapsulates a segmentation that can contain multiple segments and multiple representation...