Slicer  4.10
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLSegmentEditorWidget.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (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 __qMRMLSegmentEditorWidget_h
24 #define __qMRMLSegmentEditorWidget_h
25 
26 // Segmentations includes
27 #include "qSlicerSegmentationsModuleWidgetsExport.h"
28 
29 // MRMLWidgets includes
30 #include "qMRMLWidget.h"
31 
32 // Qt includes
33 #include <QVariant>
34 
35 // CTK includes
36 #include <ctkVTKObject.h>
37 
38 // STD includes
39 #include <cstdlib>
40 
41 class vtkMRMLNode;
45 class vtkMRMLVolumeNode;
46 class vtkObject;
47 class QItemSelection;
48 class QAbstractButton;
49 class qMRMLSegmentEditorWidgetPrivate;
52 
65 class Q_SLICER_MODULE_SEGMENTATIONS_WIDGETS_EXPORT qMRMLSegmentEditorWidget : public qMRMLWidget
66 {
67  Q_OBJECT
68  QVTK_OBJECT
69  Q_PROPERTY(bool segmentationNodeSelectorVisible READ segmentationNodeSelectorVisible WRITE setSegmentationNodeSelectorVisible)
70  Q_PROPERTY(bool masterVolumeNodeSelectorVisible READ masterVolumeNodeSelectorVisible WRITE setMasterVolumeNodeSelectorVisible)
71  Q_PROPERTY(bool autoShowMasterVolumeNode READ autoShowMasterVolumeNode WRITE setAutoShowMasterVolumeNode)
72  Q_PROPERTY(bool switchToSegmentationsButtonVisible READ switchToSegmentationsButtonVisible WRITE setSwitchToSegmentationsButtonVisible)
73  Q_PROPERTY(bool undoEnabled READ undoEnabled WRITE setUndoEnabled)
74  Q_PROPERTY(int maximumNumberOfUndoStates READ maximumNumberOfUndoStates WRITE setMaximumNumberOfUndoStates)
75  Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
76  Q_PROPERTY(Qt::ToolButtonStyle effectButtonStyle READ effectButtonStyle WRITE setEffectButtonStyle)
77  Q_PROPERTY(bool unorderedEffectsVisible READ unorderedEffectsVisible WRITE setUnorderedEffectsVisible)
78 
79 public:
82  explicit qMRMLSegmentEditorWidget(QWidget* parent = 0);
84  virtual ~qMRMLSegmentEditorWidget();
85 
87  Q_INVOKABLE vtkMRMLSegmentEditorNode* mrmlSegmentEditorNode()const;
88 
90  Q_INVOKABLE vtkMRMLNode* segmentationNode()const;
92  Q_INVOKABLE QString segmentationNodeID()const;
94  Q_INVOKABLE vtkMRMLNode* masterVolumeNode()const;
96  Q_INVOKABLE QString masterVolumeNodeID()const;
97 
99  Q_INVOKABLE QString currentSegmentID()const;
100 
103  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* activeEffect()const;
106  Q_INVOKABLE void setActiveEffect(qSlicerSegmentEditorAbstractEffect* effect);
107 
110  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByName(QString name);
111 
113  Q_INVOKABLE QStringList availableEffectNames();
114 
117  Q_INVOKABLE void setEffectNameOrder(const QStringList& effectNames);
118 
122  Q_INVOKABLE QStringList effectNameOrder() const;
123 
127  void setUnorderedEffectsVisible(bool visible);
128 
131  bool unorderedEffectsVisible() const;
132 
135  Q_INVOKABLE int effectCount();
136 
139  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByIndex(int index);
140 
145  Q_INVOKABLE void setupViewObservations();
146 
150  Q_INVOKABLE void removeViewObservations();
151 
153  bool segmentationNodeSelectorVisible() const;
155  bool masterVolumeNodeSelectorVisible() const;
159  bool autoShowMasterVolumeNode() const;
161  bool switchToSegmentationsButtonVisible() const;
163  bool undoEnabled() const;
165  int maximumNumberOfUndoStates() const;
167  bool readOnly() const;
168 
171  Qt::ToolButtonStyle effectButtonStyle() const;
172 
175  Q_INVOKABLE void segmentationNodeSelectorAddAttribute(const QString& nodeType,
176  const QString& attributeName,
177  const QVariant& attributeValue = QVariant());
180  Q_INVOKABLE void segmentationNodeSelectorRemoveAttribute(const QString& nodeType,
181  const QString& attributeName);
182 
185  Q_INVOKABLE void masterVolumeNodeSelectorAddAttribute(const QString& nodeType,
186  const QString& attributeName,
187  const QVariant& attributeValue = QVariant());
190  Q_INVOKABLE void masterVolumeNodeSelectorRemoveAttribute(const QString& nodeType,
191  const QString& attributeName);
192 
195  Q_INVOKABLE vtkMRMLInteractionNode* interactionNode() const;
196 
197 public slots:
199  virtual void setMRMLScene(vtkMRMLScene* newScene);
200 
202  void setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode);
203 
205  virtual void updateWidgetFromMRML();
206 
208  void setSegmentationNode(vtkMRMLNode* node);
210  void setSegmentationNodeID(const QString& nodeID);
214  void setMasterVolumeNode(vtkMRMLNode* node);
216  void setMasterVolumeNodeID(const QString& nodeID);
217 
219  void setCurrentSegmentID(const QString segmentID);
220 
222  void setActiveEffectByName(QString effectName);
223 
226  void saveStateForUndo();
227 
229  void updateVolume(void* volumePtr, bool& success);
230 
232  void setSegmentationNodeSelectorVisible(bool);
234  void setMasterVolumeNodeSelectorVisible(bool);
238  void setAutoShowMasterVolumeNode(bool);
240  void setSwitchToSegmentationsButtonVisible(bool);
242  void setUndoEnabled(bool);
244  void setMaximumNumberOfUndoStates(int);
246  void setReadOnly(bool aReadOnly);
248  void toggleMasterVolumeIntensityMaskEnabled();
249 
251  void undo();
252 
254  void redo();
255 
259  void installKeyboardShortcuts(QWidget* parent = NULL);
260 
262  void uninstallKeyboardShortcuts();
263 
267  bool turnOffLightboxes();
268 
270  void hideLabelLayer();
271 
274  void setEffectButtonStyle(Qt::ToolButtonStyle toolButtonStyle);
275 
277  void updateEffectLayouts();
278 
282  void updateEffectList();
283 
288  void showMasterVolumeInSliceViewers(bool forceShowInBackground = false, bool fitSlice = false);
289 
292  void rotateSliceViewsToSegmentation();
293 
296  void setInteractionNode(vtkMRMLInteractionNode* interactionNode);
297 
298 signals:
300  void currentSegmentIDChanged(const QString&);
301 
304  void masterVolumeNodeChanged(vtkMRMLVolumeNode*);
305 
308  void segmentationNodeChanged(vtkMRMLSegmentationNode*);
309 
310 protected slots:
312  void onSegmentationNodeChanged(vtkMRMLNode* node);
314  void onMasterVolumeNodeChanged(vtkMRMLNode* node);
316  void onSegmentSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
317 
319  void onInteractionNodeModified();
320 
322  void onEffectButtonClicked(QAbstractButton* button);
323 
327  void onSelectEffectShortcut();
328 
330  void onSelectSegmentShortcut();
331 
333  void onAddSegment();
335  void onRemoveSegment();
337  void onSwitchToSegmentations();
339  void onCreateSurfaceToggled(bool on);
341  void onSegmentAddedRemoved();
343  void onMasterVolumeImageDataModified();
345  void onLayoutChanged(int layoutIndex);
347  void onSegmentationDisplayModified();
348 
350  void onMaskModeChanged(int);
351 
353  void onMasterVolumeIntensityMaskChecked(bool checked);
355  void onMasterVolumeIntensityMaskRangeChanged(double low, double high);
356 
358  void onOverwriteModeChanged(int);
359 
361  void onMRMLSceneEndCloseEvent();
362 
364  void initializeParameterSetNode();
365 
367  void onSegmentationHistoryChanged();
368 
370  void anchorClicked(const QUrl &url);
371 
373  void onEnableSurfaceSmoothingToggled(bool enabled);
374  void onSurfaceSmoothingFactorChanged(double newSmoothingFactor);
376  void onImportExportActionClicked();
378  void onExportToFilesActionClicked();
379 
381  void updateMaskingSection();
382 
384  void updateSliceRotateWarningButtonVisibility();
385 
387  void showSegmentationGeometryDialog();
388 
389 protected:
391  static void processEvents(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
392 
393  void updateWidgetFromSegmentationNode();
394  void updateWidgetFromMasterVolumeNode();
395  void updateEffectsSectionFromMRML();
396 
399  bool setMasterRepresentationToBinaryLabelmap();
400 
402  qSlicerAbstractModuleWidget* switchToSegmentationsModule();
403 
404 protected:
405  QScopedPointer<qMRMLSegmentEditorWidgetPrivate> d_ptr;
406 
407 private:
408  Q_DECLARE_PRIVATE(qMRMLSegmentEditorWidget);
409  Q_DISABLE_COPY(qMRMLSegmentEditorWidget);
410 };
411 
412 #endif
Abstract class for segment editor effects.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:54
Parameter set node for the segment editor widget.
Base class for any widget that requires a MRML Scene.
Definition: qMRMLWidget.h:35
QWidget Superclass
Definition: qMRMLWidget.h:40
MRML node for representing a volume (image stack).
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:138
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...
Qt widget for editing a segment from a segmentation using Editor effects.Widget for editing segmentat...