Slicer  4.11
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  Q_PROPERTY(QString defaultTerminologyEntrySettingsKey READ defaultTerminologyEntrySettingsKey WRITE setDefaultTerminologyEntrySettingsKey)
79  Q_PROPERTY(QString defaultTerminologyEntry READ defaultTerminologyEntry WRITE setDefaultTerminologyEntry)
80  Q_PROPERTY(bool jumpToSelectedSegmentEnabled READ jumpToSelectedSegmentEnabled WRITE setJumpToSelectedSegmentEnabled)
81 
82 public:
85  explicit qMRMLSegmentEditorWidget(QWidget* parent = nullptr);
87  ~qMRMLSegmentEditorWidget() override;
88 
90  Q_INVOKABLE vtkMRMLSegmentEditorNode* mrmlSegmentEditorNode()const;
91 
93  Q_INVOKABLE vtkMRMLNode* segmentationNode()const;
95  Q_INVOKABLE QString segmentationNodeID()const;
97  Q_INVOKABLE vtkMRMLNode* masterVolumeNode()const;
99  Q_INVOKABLE QString masterVolumeNodeID()const;
100 
102  Q_INVOKABLE QString currentSegmentID()const;
103 
106  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* activeEffect()const;
109  Q_INVOKABLE void setActiveEffect(qSlicerSegmentEditorAbstractEffect* effect);
110 
113  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByName(QString name);
114 
116  Q_INVOKABLE QStringList availableEffectNames();
117 
120  Q_INVOKABLE void setEffectNameOrder(const QStringList& effectNames);
121 
125  Q_INVOKABLE QStringList effectNameOrder() const;
126 
130  void setUnorderedEffectsVisible(bool visible);
131 
134  bool unorderedEffectsVisible() const;
135 
138  Q_INVOKABLE int effectCount();
139 
142  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByIndex(int index);
143 
148  Q_INVOKABLE void setupViewObservations();
149 
153  Q_INVOKABLE void removeViewObservations();
154 
156  bool segmentationNodeSelectorVisible() const;
158  bool masterVolumeNodeSelectorVisible() const;
162  bool autoShowMasterVolumeNode() const;
164  bool switchToSegmentationsButtonVisible() const;
166  bool undoEnabled() const;
168  int maximumNumberOfUndoStates() const;
170  bool readOnly() const;
171 
174  Qt::ToolButtonStyle effectButtonStyle() const;
175 
178  Q_INVOKABLE void segmentationNodeSelectorAddAttribute(const QString& nodeType,
179  const QString& attributeName,
180  const QVariant& attributeValue = QVariant());
183  Q_INVOKABLE void segmentationNodeSelectorRemoveAttribute(const QString& nodeType,
184  const QString& attributeName);
185 
188  Q_INVOKABLE void masterVolumeNodeSelectorAddAttribute(const QString& nodeType,
189  const QString& attributeName,
190  const QVariant& attributeValue = QVariant());
193  Q_INVOKABLE void masterVolumeNodeSelectorRemoveAttribute(const QString& nodeType,
194  const QString& attributeName);
195 
198  Q_INVOKABLE vtkMRMLInteractionNode* interactionNode() const;
199 
206  void setDefaultTerminologyEntrySettingsKey(const QString& terminologyEntrySettingsKey);
209  QString defaultTerminologyEntrySettingsKey() const;
210 
213  void setDefaultTerminologyEntry(const QString& terminologyEntry);
216  QString defaultTerminologyEntry();
217 
219  bool jumpToSelectedSegmentEnabled()const;
220 
221 public slots:
223  void setMRMLScene(vtkMRMLScene* newScene) override;
224 
226  void setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode);
227 
229  virtual void updateWidgetFromMRML();
230 
232  void setSegmentationNode(vtkMRMLNode* node);
234  void setSegmentationNodeID(const QString& nodeID);
238  void setMasterVolumeNode(vtkMRMLNode* node);
240  void setMasterVolumeNodeID(const QString& nodeID);
241 
243  void setCurrentSegmentID(const QString segmentID);
244 
246  void setActiveEffectByName(QString effectName);
247 
250  void saveStateForUndo();
251 
253  void updateVolume(void* volumePtr, bool& success);
254 
256  void setSegmentationNodeSelectorVisible(bool);
258  void setMasterVolumeNodeSelectorVisible(bool);
262  void setAutoShowMasterVolumeNode(bool);
264  void setSwitchToSegmentationsButtonVisible(bool);
266  void setUndoEnabled(bool);
268  void setMaximumNumberOfUndoStates(int);
270  void setReadOnly(bool aReadOnly);
272  void toggleMasterVolumeIntensityMaskEnabled();
273 
275  void undo();
276 
278  void redo();
279 
283  void installKeyboardShortcuts(QWidget* parent = nullptr);
284 
286  void uninstallKeyboardShortcuts();
287 
291  bool turnOffLightboxes();
292 
294  void hideLabelLayer();
295 
298  void setEffectButtonStyle(Qt::ToolButtonStyle toolButtonStyle);
299 
301  void updateEffectLayouts();
302 
306  void updateEffectList();
307 
312  void showMasterVolumeInSliceViewers(bool forceShowInBackground = false, bool fitSlice = false);
313 
316  void rotateSliceViewsToSegmentation();
317 
320  void setInteractionNode(vtkMRMLInteractionNode* interactionNode);
321 
323  void selectPreviousSegment();
324 
326  void selectNextSegment();
327 
331  void selectSegmentAtOffset (int offset);
332 
335  void jumpSlices();
336 
338  void setJumpToSelectedSegmentEnabled(bool enable);
339 
340 signals:
342  void currentSegmentIDChanged(const QString&);
343 
346  void masterVolumeNodeChanged(vtkMRMLVolumeNode*);
347 
350  void segmentationNodeChanged(vtkMRMLSegmentationNode*);
351 
352 protected slots:
354  void onSegmentationNodeChanged(vtkMRMLNode* node);
356  void onMasterVolumeNodeChanged(vtkMRMLNode* node);
358  void onSegmentSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
359 
361  void onInteractionNodeModified();
362 
364  void onEffectButtonClicked(QAbstractButton* button);
365 
369  void onSelectEffectShortcut();
370 
372  void onSelectSegmentShortcut();
373 
375  void onAddSegment();
377  void onRemoveSegment();
379  void onSwitchToSegmentations();
381  void onCreateSurfaceToggled(bool on);
383  void onSegmentAddedRemoved();
385  void onMasterVolumeImageDataModified();
387  void onLayoutChanged(int layoutIndex);
389  void onSegmentationDisplayModified();
390 
392  void onMaskModeChanged(int);
393 
395  void onMasterVolumeIntensityMaskChecked(bool checked);
397  void onMasterVolumeIntensityMaskRangeChanged(double low, double high);
398 
400  void onOverwriteModeChanged(int);
401 
403  void onMRMLSceneEndCloseEvent();
404 
406  void initializeParameterSetNode();
407 
409  void onSegmentationHistoryChanged();
410 
412  void anchorClicked(const QUrl &url);
413 
415  void onEnableSurfaceSmoothingToggled(bool enabled);
416  void onSurfaceSmoothingFactorChanged(double newSmoothingFactor);
418  void onImportExportActionClicked();
420  void onExportToFilesActionClicked();
421 
423  void updateMaskingSection();
424 
426  void updateSliceRotateWarningButtonVisibility();
427 
429  void showSegmentationGeometryDialog();
430 
431 protected:
433  static void processEvents(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
434 
435  void updateWidgetFromSegmentationNode();
436  void updateWidgetFromMasterVolumeNode();
437  void updateEffectsSectionFromMRML();
438 
441  bool setMasterRepresentationToBinaryLabelmap();
442 
444  qSlicerAbstractModuleWidget* switchToSegmentationsModule();
445 
446 protected:
447  QScopedPointer<qMRMLSegmentEditorWidgetPrivate> d_ptr;
448 
449 private:
450  Q_DECLARE_PRIVATE(qMRMLSegmentEditorWidget);
451  Q_DISABLE_COPY(qMRMLSegmentEditorWidget);
452 };
453 
454 #endif
Abstract class for segment editor effects.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:61
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:167
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...