Slicer  4.11
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 class qSlicerSegmentEditorAbstractEffectPrivate;
35 
36 class vtkActor2D;
38 class vtkMRMLScene;
42 class vtkSegment;
43 class vtkRenderer;
44 class vtkRenderWindow;
45 class vtkRenderWindowInteractor;
47 class vtkProp3D;
48 class qMRMLWidget;
49 class qMRMLSliceWidget;
50 class QColor;
51 class QFormLayout;
52 class QFrame;
53 class QLayout;
54 
57 class Q_SLICER_SEGMENTATIONS_EFFECTS_EXPORT qSlicerSegmentEditorAbstractEffect : public QObject
58 {
59 public:
60  Q_OBJECT
61  Q_ENUMS(ModificationMode)
62 
63 
64  Q_PROPERTY(QString name READ name WRITE setName)
67 
68 
69  Q_PROPERTY(bool perSegment READ perSegment WRITE setPerSegment)
73 
74 
75  Q_PROPERTY(bool requireSegments READ requireSegments WRITE setRequireSegments)
79 
80 
81  Q_PROPERTY(bool showEffectCursorInSliceView READ showEffectCursorInSliceView WRITE setShowEffectCursorInSliceView)
83 
84 
85  Q_PROPERTY(bool showEffectCursorInThreeDView READ showEffectCursorInThreeDView WRITE setShowEffectCursorInThreeDView)
87 
88 public:
89  typedef QObject Superclass;
90  qSlicerSegmentEditorAbstractEffect(QObject* parent = nullptr);
92 
93 // API: Methods that are to be reimplemented in the effect subclasses
94 public:
95 
97  {
101  ModificationModeRemoveAll
102  };
103 
105  virtual QIcon icon() { return QIcon(); };
106 
108  Q_INVOKABLE virtual const QString helpText()const { return QString(); };
109 
111  virtual qSlicerSegmentEditorAbstractEffect* clone() = 0;
112 
115  Q_INVOKABLE virtual void activate();
116 
119  Q_INVOKABLE virtual void deactivate();
120 
122  Q_INVOKABLE virtual bool active();
123 
124  Q_INVOKABLE virtual void modifySelectedSegmentByLabelmap(vtkOrientedImageData* modifierLabelmap,
125  ModificationMode modificationMode, const int modificationExtent[6],bool bypassMasking = false);
126  Q_INVOKABLE virtual void modifySelectedSegmentByLabelmap(vtkOrientedImageData* modifierLabelmap,
127  ModificationMode modificationMode, bool bypassMasking = false);
128  Q_INVOKABLE virtual void modifySelectedSegmentByLabelmap(vtkOrientedImageData* modifierLabelmap,
129  ModificationMode modificationMode, QList<int> extent, bool bypassMasking = false);
130  Q_INVOKABLE virtual void modifySegmentByLabelmap(vtkMRMLSegmentationNode* segmentationNode, const char* segmentID,
131  vtkOrientedImageData* modifierLabelmap, ModificationMode modificationMode, bool bypassMasking = false);
132  Q_INVOKABLE virtual void modifySegmentByLabelmap(vtkMRMLSegmentationNode* segmentationNode, const char* segmentID,
133  vtkOrientedImageData* modifierLabelmap, ModificationMode modificationMode, const int modificationExtent[6], bool bypassMasking = false);
134 
138  Q_INVOKABLE static void applyImageMask(vtkOrientedImageData* input, vtkOrientedImageData* mask, double fillValue, bool notMask = false);
139 
142  virtual void setupOptionsFrame() { };
143 
145  virtual QCursor createCursor(qMRMLWidget* viewWidget);
146 
152  virtual bool processInteractionEvents(vtkRenderWindowInteractor* callerInteractor, unsigned long eid, qMRMLWidget* viewWidget)
153  { Q_UNUSED(callerInteractor); Q_UNUSED(eid); Q_UNUSED(viewWidget); return false; };
154 
159  virtual void processViewNodeEvents(vtkMRMLAbstractViewNode* callerViewNode, unsigned long eid, qMRMLWidget* viewWidget)
160  { Q_UNUSED(callerViewNode); Q_UNUSED(eid); Q_UNUSED(viewWidget); };
161 
164  virtual void setMRMLDefaults() = 0;
165 
168  virtual void referenceGeometryChanged() { };
171  virtual void masterVolumeNodeChanged() { };
173  virtual void layoutChanged() { };
176  virtual void interactionNodeModified(vtkMRMLInteractionNode* interactionNode);
177 
178 public slots:
181  virtual void updateGUIFromMRML() = 0;
182 
185  virtual void updateMRMLFromGUI() = 0;
186 
187 // Get/set methods
188 public:
190  Q_INVOKABLE vtkMRMLSegmentEditorNode* parameterSetNode();
192  Q_INVOKABLE void setParameterSetNode(vtkMRMLSegmentEditorNode* node);
193 
195  Q_INVOKABLE vtkMRMLScene* scene();
196 
198  Q_INVOKABLE QFrame* optionsFrame();
199 
201  Q_INVOKABLE QFormLayout* optionsLayout();
202 
205  Q_INVOKABLE void addActor2D(qMRMLWidget* viewWidget, vtkActor2D* actor);
206 
208  Q_INVOKABLE void removeActor2D(qMRMLWidget* viewWidget, vtkActor2D* actor);
209 
212  Q_INVOKABLE void addActor3D(qMRMLWidget* viewWidget, vtkProp3D* actor);
213 
215  Q_INVOKABLE void removeActor3D(qMRMLWidget* viewWidget, vtkProp3D* actor);
216 
220  Q_INVOKABLE void addOptionsWidget(QWidget* newOptionsWidget);
221  Q_INVOKABLE void addOptionsWidget(QLayout* newOptionsWidget);
222 
223  Q_INVOKABLE QWidget* addLabeledOptionsWidget(QString label, QWidget* newOptionsWidget);
224  Q_INVOKABLE QWidget* addLabeledOptionsWidget(QString label, QLayout* newOptionsWidget);
225 
227  virtual QString name()const;
230  virtual void setName(QString name);
231 
233  virtual bool perSegment()const;
236  virtual void setPerSegment(bool perSegment);
237 
239  virtual bool requireSegments()const;
241  virtual void setRequireSegments(bool requireSegments);
242 
243 
245  Q_INVOKABLE void cursorOff(qMRMLWidget* viewWidget);
247  Q_INVOKABLE void cursorOn(qMRMLWidget* viewWidget);
248 
251  Q_INVOKABLE void selectEffect(QString effectName);
252 
257  void setCallbackSlots(QObject* receiver, const char* selectEffectSlot, const char* updateVolumeSlot, const char* saveStateForUndoSlot);
258 
260  void setVolumes(vtkOrientedImageData* alignedMasterVolume, vtkOrientedImageData* modifierLabelmap,
261  vtkOrientedImageData* maskLabelmap, vtkOrientedImageData* selectedSegmentLabelmap, vtkOrientedImageData* referenceGeometryImage);
262 
263 // Effect parameter functions
264 public:
266  Q_INVOKABLE QString parameter(QString name);
267 
269  Q_INVOKABLE int integerParameter(QString name);
270 
272  Q_INVOKABLE double doubleParameter(QString name);
273 
277  Q_INVOKABLE void setParameter(QString name, QString value);
280  Q_INVOKABLE void setParameterDefault(QString name, QString value);
287  Q_INVOKABLE void setCommonParameter(QString name, QString value);
290  Q_INVOKABLE void setCommonParameterDefault(QString name, QString value);
291 
295  Q_INVOKABLE void setParameter(QString name, int value);
298  Q_INVOKABLE void setParameterDefault(QString name, int value);
300  Q_INVOKABLE void setCommonParameter(QString name, int value);
303  Q_INVOKABLE void setCommonParameterDefault(QString name, int value);
304 
308  Q_INVOKABLE void setParameter(QString name, double value);
311  Q_INVOKABLE void setParameterDefault(QString name, double value);
313  Q_INVOKABLE void setCommonParameter(QString name, double value);
316  Q_INVOKABLE void setCommonParameterDefault(QString name, double value);
317 
318 // Utility functions
319 public:
321  Q_INVOKABLE bool parameterDefined(QString name);
322 
324  Q_INVOKABLE bool commonParameterDefined(QString name);
325 
326  Q_INVOKABLE vtkOrientedImageData* modifierLabelmap();
327 
330  Q_INVOKABLE vtkOrientedImageData* defaultModifierLabelmap();
331 
332  Q_INVOKABLE vtkOrientedImageData* maskLabelmap();
333 
334  Q_INVOKABLE vtkOrientedImageData* selectedSegmentLabelmap();
335 
336  Q_INVOKABLE vtkOrientedImageData* referenceGeometryImage();
337 
338  void setShowEffectCursorInSliceView(bool show);
339  void setShowEffectCursorInThreeDView(bool show);
340 
341  bool showEffectCursorInSliceView();
342  bool showEffectCursorInThreeDView();
343 
346  Q_INVOKABLE vtkOrientedImageData* masterVolumeImageData();
347 
350  Q_INVOKABLE void saveStateForUndo();
351 
353  Q_INVOKABLE static vtkRenderWindow* renderWindow(qMRMLWidget* viewWidget);
355  Q_INVOKABLE static vtkRenderer* renderer(qMRMLWidget* viewWidget);
357  Q_INVOKABLE static vtkMRMLAbstractViewNode* viewNode(qMRMLWidget* viewWidget);
358 
360  static QPoint rasToXy(double ras[3], qMRMLSliceWidget* sliceWidget);
362  Q_INVOKABLE static QPoint rasToXy(QVector3D ras, qMRMLSliceWidget* sliceWidget);
367  static void xyzToRas(double inputXyz[3], double outputRas[3], qMRMLSliceWidget* sliceWidget);
369  Q_INVOKABLE static QVector3D xyzToRas(QVector3D inputXyz, qMRMLSliceWidget* sliceWidget);
371  static void xyToRas(QPoint xy, double outputRas[3], qMRMLSliceWidget* sliceWidget);
373  static void xyToRas(double xy[2], double outputRas[3], qMRMLSliceWidget* sliceWidget);
375  Q_INVOKABLE static QVector3D xyToRas(QPoint xy, qMRMLSliceWidget* sliceWidget);
377  static void xyzToIjk(double inputXyz[3], int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image);
379  Q_INVOKABLE static QVector3D xyzToIjk(QVector3D inputXyz, qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image);
381  static void xyToIjk(QPoint xy, int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image);
383  static void xyToIjk(double xy[2], int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image);
385  Q_INVOKABLE static QVector3D xyToIjk(QPoint xy, qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image);
386 
387  Q_INVOKABLE static void forceRender(qMRMLWidget* viewWidget);
388  Q_INVOKABLE static void scheduleRender(qMRMLWidget* viewWidget);
389 
390  Q_INVOKABLE static double sliceSpacing(qMRMLSliceWidget* sliceWidget);
391 
392  Q_INVOKABLE bool segmentationDisplayableInView(vtkMRMLAbstractViewNode* viewNode);
393 
394 protected:
396  QString m_Name;
397  bool m_Active;
398 
404 
406 
409 
410  double m_FillValue;
411  double m_EraseValue;
412 
413 protected:
414  QScopedPointer<qSlicerSegmentEditorAbstractEffectPrivate> d_ptr;
415 
416 private:
417  Q_DECLARE_PRIVATE(qSlicerSegmentEditorAbstractEffect);
418  Q_DISABLE_COPY(qSlicerSegmentEditorAbstractEffect);
419 };
420 
421 #endif
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
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.
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:56
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 ...