Slicer  5.1
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(int effectColumnCount READ effectColumnCount WRITE setEffectColumnCount)
78  Q_PROPERTY(bool unorderedEffectsVisible READ unorderedEffectsVisible WRITE setUnorderedEffectsVisible)
79  Q_PROPERTY(QString defaultTerminologyEntrySettingsKey READ defaultTerminologyEntrySettingsKey WRITE setDefaultTerminologyEntrySettingsKey)
80  Q_PROPERTY(QString defaultTerminologyEntry READ defaultTerminologyEntry WRITE setDefaultTerminologyEntry)
81  Q_PROPERTY(bool jumpToSelectedSegmentEnabled READ jumpToSelectedSegmentEnabled WRITE setJumpToSelectedSegmentEnabled)
82 
83 public:
86  explicit qMRMLSegmentEditorWidget(QWidget* parent = nullptr);
88  ~qMRMLSegmentEditorWidget() override;
89 
91  Q_INVOKABLE vtkMRMLSegmentEditorNode* mrmlSegmentEditorNode()const;
92 
94  Q_INVOKABLE vtkMRMLNode* segmentationNode()const;
96  Q_INVOKABLE QString segmentationNodeID()const;
98  Q_INVOKABLE vtkMRMLNode* masterVolumeNode()const;
100  Q_INVOKABLE QString masterVolumeNodeID()const;
101 
103  Q_INVOKABLE QString currentSegmentID()const;
104 
107  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* activeEffect()const;
110  Q_INVOKABLE void setActiveEffect(qSlicerSegmentEditorAbstractEffect* effect);
111 
114  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByName(QString name);
115 
117  Q_INVOKABLE QStringList availableEffectNames();
118 
121  Q_INVOKABLE void setEffectNameOrder(const QStringList& effectNames);
122 
126  Q_INVOKABLE QStringList effectNameOrder() const;
127 
131  void setUnorderedEffectsVisible(bool visible);
132 
135  bool unorderedEffectsVisible() const;
136 
139  Q_INVOKABLE int effectCount();
140 
143  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByIndex(int index);
144 
149  Q_INVOKABLE void setupViewObservations();
150 
154  Q_INVOKABLE void removeViewObservations();
155 
157  bool segmentationNodeSelectorVisible() const;
159  bool masterVolumeNodeSelectorVisible() const;
163  bool autoShowMasterVolumeNode() const;
165  bool switchToSegmentationsButtonVisible() const;
167  bool undoEnabled() const;
169  int maximumNumberOfUndoStates() const;
171  bool readOnly() const;
172 
175  Qt::ToolButtonStyle effectButtonStyle() const;
176 
179  int effectColumnCount() const;
180 
183  Q_INVOKABLE void segmentationNodeSelectorAddAttribute(const QString& nodeType,
184  const QString& attributeName,
185  const QVariant& attributeValue = QVariant());
188  Q_INVOKABLE void segmentationNodeSelectorRemoveAttribute(const QString& nodeType,
189  const QString& attributeName);
190 
193  Q_INVOKABLE void masterVolumeNodeSelectorAddAttribute(const QString& nodeType,
194  const QString& attributeName,
195  const QVariant& attributeValue = QVariant());
198  Q_INVOKABLE void masterVolumeNodeSelectorRemoveAttribute(const QString& nodeType,
199  const QString& attributeName);
200 
203  Q_INVOKABLE vtkMRMLInteractionNode* interactionNode() const;
204 
211  void setDefaultTerminologyEntrySettingsKey(const QString& terminologyEntrySettingsKey);
214  QString defaultTerminologyEntrySettingsKey() const;
215 
218  void setDefaultTerminologyEntry(const QString& terminologyEntry);
221  QString defaultTerminologyEntry();
222 
224  bool jumpToSelectedSegmentEnabled()const;
225 
226 public slots:
228  void setMRMLScene(vtkMRMLScene* newScene) override;
229 
231  void setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode);
232 
234  virtual void updateWidgetFromMRML();
235 
237  void setSegmentationNode(vtkMRMLNode* node);
239  void setSegmentationNodeID(const QString& nodeID);
243  void setMasterVolumeNode(vtkMRMLNode* node);
245  void setMasterVolumeNodeID(const QString& nodeID);
246 
248  void setCurrentSegmentID(const QString segmentID);
249 
251  void setActiveEffectByName(QString effectName);
252 
255  void saveStateForUndo();
256 
258  void updateVolume(void* volumePtr, bool& success);
259 
261  void setSegmentationNodeSelectorVisible(bool);
263  void setMasterVolumeNodeSelectorVisible(bool);
267  void setAutoShowMasterVolumeNode(bool);
269  void setSwitchToSegmentationsButtonVisible(bool);
271  void setUndoEnabled(bool);
273  void setMaximumNumberOfUndoStates(int);
275  void setReadOnly(bool aReadOnly);
277  void toggleMasterVolumeIntensityMaskEnabled();
278 
280  void undo();
281 
283  void redo();
284 
288  void installKeyboardShortcuts(QWidget* parent = nullptr);
289 
291  void uninstallKeyboardShortcuts();
292 
296  bool turnOffLightboxes();
297 
299  void hideLabelLayer();
300 
303  void setEffectButtonStyle(Qt::ToolButtonStyle toolButtonStyle);
304 
306  void setEffectColumnCount(int columnCount);
307 
311  void updateEffectList();
312 
317  void showMasterVolumeInSliceViewers(bool forceShowInBackground = false, bool fitSlice = false);
318 
321  void rotateSliceViewsToSegmentation();
322 
325  void setInteractionNode(vtkMRMLInteractionNode* interactionNode);
326 
328  void selectPreviousSegment();
329 
331  void selectNextSegment();
332 
336  void selectSegmentAtOffset (int offset);
337 
340  void jumpSlices();
341 
343  void setJumpToSelectedSegmentEnabled(bool enable);
344 
345 signals:
347  void currentSegmentIDChanged(const QString&);
348 
351  void masterVolumeNodeChanged(vtkMRMLVolumeNode*);
352 
355  void segmentationNodeChanged(vtkMRMLSegmentationNode*);
356 
357 protected slots:
359  void onSegmentationNodeChanged(vtkMRMLNode* node);
361  void onMasterVolumeNodeChanged(vtkMRMLNode* node);
363  void onSegmentSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
364 
366  void onInteractionNodeModified();
367 
369  void onEffectButtonClicked(QAbstractButton* button);
370 
374  void onSelectEffectShortcut();
375 
377  void onSelectSegmentShortcut();
378 
380  void onAddSegment();
382  void onRemoveSegment();
384  void onSwitchToSegmentations();
386  void onCreateSurfaceToggled(bool on);
388  void onSegmentAddedRemoved();
390  void onMasterVolumeImageDataModified();
392  void onLayoutChanged(int layoutIndex);
394  void onSegmentationDisplayModified();
395 
397  void onMaskModeChanged(int);
398 
400  void onMasterVolumeIntensityMaskChecked(bool checked);
402  void onMasterVolumeIntensityMaskRangeChanged(double low, double high);
403 
405  void onOverwriteModeChanged(int);
406 
408  void onMRMLSceneEndCloseEvent();
409 
411  void initializeParameterSetNode();
412 
414  void updateUndoRedoButtonsState();
415 
417  void onSegmentationHistoryChanged();
418 
420  void onImportExportActionClicked();
422  void onExportToFilesActionClicked();
423 
425  void updateMaskingSection();
426 
428  void updateSliceRotateWarningButtonVisibility();
429 
431  void showSegmentationGeometryDialog();
432 
433 protected:
435  static void processEvents(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
436 
437  void updateWidgetFromSegmentationNode();
438  void updateWidgetFromMasterVolumeNode();
439  void updateEffectsSectionFromMRML();
440 
443  bool setMasterRepresentationToBinaryLabelmap();
444 
446  qSlicerAbstractModuleWidget* switchToSegmentationsModule();
447 
448 protected:
449  QScopedPointer<qMRMLSegmentEditorWidgetPrivate> d_ptr;
450 
451 private:
452  Q_DECLARE_PRIVATE(qMRMLSegmentEditorWidget);
453  Q_DISABLE_COPY(qMRMLSegmentEditorWidget);
454 };
455 
456 #endif
Abstract class for segment editor effects.
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
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...