Slicer  5.3
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerSegmentEditorAbstractEffect.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
4  Queen's University, Kingston, ON, Canada. All Rights Reserved.
5 
6  See COPYRIGHT.txt
7  or http://www.slicer.org/copyright/copyright.txt for details.
8 
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  See the License for the specific language governing permissions and
13  limitations under the License.
14 
15  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
16  and was supported through the Applied Cancer Research Unit program of Cancer Care
17  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
18 
19 ==============================================================================*/
20 
21 #ifndef __qSlicerSegmentEditorAbstractEffect_h
22 #define __qSlicerSegmentEditorAbstractEffect_h
23 
24 // Segmentations Editor Effects includes
25 #include "qSlicerSegmentationsEditorEffectsExport.h"
26 
27 // Qt includes
28 #include <QCursor>
29 #include <QIcon>
30 #include <QPoint>
31 #include <QList>
32 #include <QVector3D>
33 
34 // VTK includes
35 #include "vtkWeakPointer.h"
36 
37 class qSlicerSegmentEditorAbstractEffectPrivate;
38 
39 class vtkActor2D;
41 class vtkMRMLScene;
46 class vtkSegment;
47 class vtkRenderer;
48 class vtkRenderWindow;
49 class vtkRenderWindowInteractor;
51 class vtkProp3D;
52 class qMRMLWidget;
53 class qMRMLSliceWidget;
54 class QColor;
55 class QFormLayout;
56 class QFrame;
57 class QLayout;
58 
61 class Q_SLICER_SEGMENTATIONS_EFFECTS_EXPORT qSlicerSegmentEditorAbstractEffect : public QObject
62 {
63 public:
64  Q_OBJECT
65  Q_ENUMS(ConfirmationResult)
66  Q_ENUMS(ModificationMode)
67 
68 
69  Q_PROPERTY(QString name READ name WRITE setName)
72 
73 
74  Q_PROPERTY(bool perSegment READ perSegment WRITE setPerSegment)
78 
79 
80  Q_PROPERTY(bool requireSegments READ requireSegments WRITE setRequireSegments)
84 
85 
86  Q_PROPERTY(bool showEffectCursorInSliceView READ showEffectCursorInSliceView WRITE setShowEffectCursorInSliceView)
88 
89 
90  Q_PROPERTY(bool showEffectCursorInThreeDView READ showEffectCursorInThreeDView WRITE setShowEffectCursorInThreeDView)
92 
93 public:
94  typedef QObject Superclass;
95  qSlicerSegmentEditorAbstractEffect(QObject* parent = nullptr);
97 
98 // API: Methods that are to be reimplemented in the effect subclasses
99 public:
100 
102  {
106  ModificationModeRemoveAll
107  };
108 
110  {
114  };
115 
117  virtual QIcon icon() { return QIcon(); };
118 
120  Q_INVOKABLE virtual const QString helpText()const { return QString(); };
121 
123  virtual qSlicerSegmentEditorAbstractEffect* clone() = 0;
124 
127  Q_INVOKABLE virtual void activate();
128 
131  Q_INVOKABLE virtual void deactivate();
132 
134  Q_INVOKABLE virtual bool active();
135 
136  Q_INVOKABLE virtual void modifySelectedSegmentByLabelmap(vtkOrientedImageData* modifierLabelmap,
137  ModificationMode modificationMode, const int modificationExtent[6],bool bypassMasking = false);
138  Q_INVOKABLE virtual void modifySelectedSegmentByLabelmap(vtkOrientedImageData* modifierLabelmap,
139  ModificationMode modificationMode, bool bypassMasking = false);
140  Q_INVOKABLE virtual void modifySelectedSegmentByLabelmap(vtkOrientedImageData* modifierLabelmap,
141  ModificationMode modificationMode, QList<int> extent, bool bypassMasking = false);
142  Q_INVOKABLE virtual void modifySegmentByLabelmap(vtkMRMLSegmentationNode* segmentationNode, const char* segmentID,
143  vtkOrientedImageData* modifierLabelmap, ModificationMode modificationMode, bool bypassMasking = false);
144  Q_INVOKABLE virtual void modifySegmentByLabelmap(vtkMRMLSegmentationNode* segmentationNode, const char* segmentID,
145  vtkOrientedImageData* modifierLabelmap, ModificationMode modificationMode, const int modificationExtent[6], bool bypassMasking = false);
146 
150  Q_INVOKABLE static void applyImageMask(vtkOrientedImageData* input, vtkOrientedImageData* mask, double fillValue, bool notMask = false);
151 
154  virtual void setupOptionsFrame() { };
155 
157  virtual QCursor createCursor(qMRMLWidget* viewWidget);
158 
164  virtual bool processInteractionEvents(vtkRenderWindowInteractor* callerInteractor, unsigned long eid, qMRMLWidget* viewWidget)
165  { Q_UNUSED(callerInteractor); Q_UNUSED(eid); Q_UNUSED(viewWidget); return false; };
166 
171  virtual void processViewNodeEvents(vtkMRMLAbstractViewNode* callerViewNode, unsigned long eid, qMRMLWidget* viewWidget)
172  { Q_UNUSED(callerViewNode); Q_UNUSED(eid); Q_UNUSED(viewWidget); };
173 
176  virtual void setMRMLDefaults() = 0;
177 
180  virtual void referenceGeometryChanged() { };
183  virtual void sourceVolumeNodeChanged() { };
185  virtual void masterVolumeNodeChanged() { };
187  virtual void layoutChanged() { };
190  virtual void interactionNodeModified(vtkMRMLInteractionNode* interactionNode);
191 
192 public slots:
195  virtual void updateGUIFromMRML() = 0;
196 
199  virtual void updateMRMLFromGUI() = 0;
200 
201 // Get/set methods
202 public:
204  Q_INVOKABLE vtkMRMLSegmentEditorNode* parameterSetNode();
206  Q_INVOKABLE void setParameterSetNode(vtkMRMLSegmentEditorNode* node);
207 
209  Q_INVOKABLE vtkMRMLScene* scene();
210 
212  Q_INVOKABLE QFrame* optionsFrame();
213 
215  Q_INVOKABLE QFormLayout* optionsLayout();
216 
219  Q_INVOKABLE void addActor2D(qMRMLWidget* viewWidget, vtkActor2D* actor);
220 
222  Q_INVOKABLE void removeActor2D(qMRMLWidget* viewWidget, vtkActor2D* actor);
223 
226  Q_INVOKABLE void addActor3D(qMRMLWidget* viewWidget, vtkProp3D* actor);
227 
229  Q_INVOKABLE void removeActor3D(qMRMLWidget* viewWidget, vtkProp3D* actor);
230 
234  Q_INVOKABLE void addOptionsWidget(QWidget* newOptionsWidget);
235  Q_INVOKABLE void addOptionsWidget(QLayout* newOptionsWidget);
236 
237  Q_INVOKABLE QWidget* addLabeledOptionsWidget(QString label, QWidget* newOptionsWidget);
238  Q_INVOKABLE QWidget* addLabeledOptionsWidget(QString label, QLayout* newOptionsWidget);
239 
241  virtual QString name()const;
244  virtual void setName(QString name);
245 
247  virtual bool perSegment()const;
250  virtual void setPerSegment(bool perSegment);
251 
253  virtual bool requireSegments()const;
255  virtual void setRequireSegments(bool requireSegments);
256 
257 
259  Q_INVOKABLE void cursorOff(qMRMLWidget* viewWidget);
261  Q_INVOKABLE void cursorOn(qMRMLWidget* viewWidget);
262 
265  Q_INVOKABLE void selectEffect(QString effectName);
266 
271  void setCallbackSlots(QObject* receiver, const char* selectEffectSlot, const char* updateVolumeSlot, const char* saveStateForUndoSlot);
272 
274  void setVolumes(vtkOrientedImageData* alignedSourceVolume, vtkOrientedImageData* modifierLabelmap,
275  vtkOrientedImageData* maskLabelmap, vtkOrientedImageData* selectedSegmentLabelmap, vtkOrientedImageData* referenceGeometryImage);
276 
277 // Effect parameter functions
278 public:
280  Q_INVOKABLE QString parameter(QString name);
281 
283  Q_INVOKABLE int integerParameter(QString name);
284 
286  Q_INVOKABLE double doubleParameter(QString name);
287 
291  Q_INVOKABLE void setParameter(QString name, QString value);
294  Q_INVOKABLE void setParameterDefault(QString name, QString value);
301  Q_INVOKABLE void setCommonParameter(QString name, QString value);
304  Q_INVOKABLE void setCommonParameterDefault(QString name, QString value);
305 
309  Q_INVOKABLE void setParameter(QString name, int value);
312  Q_INVOKABLE void setParameterDefault(QString name, int value);
314  Q_INVOKABLE void setCommonParameter(QString name, int value);
317  Q_INVOKABLE void setCommonParameterDefault(QString name, int value);
318 
322  Q_INVOKABLE void setParameter(QString name, double value);
325  Q_INVOKABLE void setParameterDefault(QString name, double value);
327  Q_INVOKABLE void setCommonParameter(QString name, double value);
330  Q_INVOKABLE void setCommonParameterDefault(QString name, double value);
331 
332 // Utility functions
333 public:
335  Q_INVOKABLE bool parameterDefined(QString name);
336 
338  Q_INVOKABLE bool commonParameterDefined(QString name);
339 
345  Q_INVOKABLE int confirmCurrentSegmentVisible();
346 
347  Q_INVOKABLE vtkOrientedImageData* modifierLabelmap();
348 
351  Q_INVOKABLE vtkOrientedImageData* defaultModifierLabelmap();
352 
353  Q_INVOKABLE vtkOrientedImageData* maskLabelmap();
354 
355  Q_INVOKABLE vtkOrientedImageData* selectedSegmentLabelmap();
356 
357  Q_INVOKABLE vtkOrientedImageData* referenceGeometryImage();
358 
359  void setShowEffectCursorInSliceView(bool show);
360  void setShowEffectCursorInThreeDView(bool show);
361 
362  bool showEffectCursorInSliceView();
363  bool showEffectCursorInThreeDView();
364 
367  Q_INVOKABLE vtkOrientedImageData* sourceVolumeImageData();
368 
370  Q_INVOKABLE vtkOrientedImageData* masterVolumeImageData();
371 
374  Q_INVOKABLE void saveStateForUndo();
375 
377  Q_INVOKABLE static vtkRenderWindow* renderWindow(qMRMLWidget* viewWidget);
379  Q_INVOKABLE static vtkRenderer* renderer(qMRMLWidget* viewWidget);
381  Q_INVOKABLE static vtkMRMLAbstractViewNode* viewNode(qMRMLWidget* viewWidget);
382 
384  static QPoint rasToXy(double ras[3], qMRMLSliceWidget* sliceWidget);
386  Q_INVOKABLE static QPoint rasToXy(QVector3D ras, qMRMLSliceWidget* sliceWidget);
391  static void xyzToRas(double inputXyz[3], double outputRas[3], qMRMLSliceWidget* sliceWidget);
393  Q_INVOKABLE static QVector3D xyzToRas(QVector3D inputXyz, qMRMLSliceWidget* sliceWidget);
395  static void xyToRas(QPoint xy, double outputRas[3], qMRMLSliceWidget* sliceWidget);
397  static void xyToRas(double xy[2], double outputRas[3], qMRMLSliceWidget* sliceWidget);
399  Q_INVOKABLE static QVector3D xyToRas(QPoint xy, qMRMLSliceWidget* sliceWidget);
401  static void xyzToIjk(double inputXyz[3], int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
403  Q_INVOKABLE static QVector3D xyzToIjk(QVector3D inputXyz, qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
405  static void xyToIjk(QPoint xy, int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
407  static void xyToIjk(double xy[2], int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
409  Q_INVOKABLE static QVector3D xyToIjk(QPoint xy, qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image, vtkMRMLTransformNode* parentTransform = nullptr);
410 
411  Q_INVOKABLE static void forceRender(qMRMLWidget* viewWidget);
412  Q_INVOKABLE static void scheduleRender(qMRMLWidget* viewWidget);
413 
414  Q_INVOKABLE static double sliceSpacing(qMRMLSliceWidget* sliceWidget);
415 
416  Q_INVOKABLE bool segmentationDisplayableInView(vtkMRMLAbstractViewNode* viewNode);
417 
418 protected:
420  QString m_Name;
421  bool m_Active{false};
422 
427  bool m_PerSegment{true};
428 
429  bool m_RequireSegments{true};
430 
431  bool m_ShowEffectCursorInSliceView{true};
432  bool m_ShowEffectCursorInThreeDView{false};
433 
434  double m_FillValue{1.0};
435  double m_EraseValue{0.0};
436 
439  vtkWeakPointer<vtkSegment> m_AlreadyConfirmedSegmentVisible;
440 
441 protected:
442  QScopedPointer<qSlicerSegmentEditorAbstractEffectPrivate> d_ptr;
443 
444 private:
445  Q_DECLARE_PRIVATE(qSlicerSegmentEditorAbstractEffect);
446  Q_DISABLE_COPY(qSlicerSegmentEditorAbstractEffect);
447 };
448 
449 #endif
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
vtkWeakPointer< vtkSegment > m_AlreadyConfirmedSegmentVisible
MRML node for representing a transformation between this node space and a parent node space...
virtual bool processInteractionEvents(vtkRenderWindowInteractor *callerInteractor, unsigned long eid, qMRMLWidget *viewWidget)
virtual Q_INVOKABLE const QString helpText() const
Get help text for effect to be displayed in the help box.
Abstract class for segment editor effects.
virtual void masterVolumeNodeChanged()
Deprecated. Override sourceVolumeNodeChanged() method instead.
Image data containing orientation information.
Abstract MRML node to represent a view. The class holds the properties common to any view type (3D...
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
Parameter set node for the segment editor widget.
Base class for any widget that requires a MRML Scene.
Definition: qMRMLWidget.h:35
QScopedPointer< qSlicerSegmentEditorAbstractEffectPrivate > d_ptr
virtual void processViewNodeEvents(vtkMRMLAbstractViewNode *callerViewNode, unsigned long eid, qMRMLWidget *viewWidget)
virtual QIcon icon()
Get icon for effect to be displayed in segment editor.
virtual void layoutChanged()
Simple mechanism to let the effects know that the layout has changed.
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...