Slicer  5.2
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 sourceVolumeNodeSelectorVisible READ sourceVolumeNodeSelectorVisible WRITE setSourceVolumeNodeSelectorVisible)
71  Q_PROPERTY(bool autoShowSourceVolumeNode READ autoShowSourceVolumeNode WRITE setAutoShowSourceVolumeNode)
72  Q_PROPERTY(bool masterVolumeNodeSelectorVisible READ masterVolumeNodeSelectorVisible WRITE setMasterVolumeNodeSelectorVisible) // deprecated
73  Q_PROPERTY(bool autoShowMasterVolumeNode READ autoShowMasterVolumeNode WRITE setAutoShowMasterVolumeNode) // deprecated
74  Q_PROPERTY(bool switchToSegmentationsButtonVisible READ switchToSegmentationsButtonVisible WRITE setSwitchToSegmentationsButtonVisible)
75  Q_PROPERTY(bool undoEnabled READ undoEnabled WRITE setUndoEnabled)
76  Q_PROPERTY(int maximumNumberOfUndoStates READ maximumNumberOfUndoStates WRITE setMaximumNumberOfUndoStates)
77  Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
78  Q_PROPERTY(Qt::ToolButtonStyle effectButtonStyle READ effectButtonStyle WRITE setEffectButtonStyle)
79  Q_PROPERTY(int effectColumnCount READ effectColumnCount WRITE setEffectColumnCount)
80  Q_PROPERTY(bool unorderedEffectsVisible READ unorderedEffectsVisible WRITE setUnorderedEffectsVisible)
81  Q_PROPERTY(QString defaultTerminologyEntrySettingsKey READ defaultTerminologyEntrySettingsKey WRITE setDefaultTerminologyEntrySettingsKey)
82  Q_PROPERTY(QString defaultTerminologyEntry READ defaultTerminologyEntry WRITE setDefaultTerminologyEntry)
83  Q_PROPERTY(bool jumpToSelectedSegmentEnabled READ jumpToSelectedSegmentEnabled WRITE setJumpToSelectedSegmentEnabled)
84 
85 public:
88  explicit qMRMLSegmentEditorWidget(QWidget* parent = nullptr);
90  ~qMRMLSegmentEditorWidget() override;
91 
93  Q_INVOKABLE vtkMRMLSegmentEditorNode* mrmlSegmentEditorNode()const;
94 
96  Q_INVOKABLE vtkMRMLNode* segmentationNode()const;
98  Q_INVOKABLE QString segmentationNodeID()const;
100  Q_INVOKABLE vtkMRMLNode* sourceVolumeNode()const;
102  Q_INVOKABLE QString sourceVolumeNodeID()const;
103 
105  Q_INVOKABLE vtkMRMLNode* masterVolumeNode()const
106  {
107  qWarning("qMRMLSegmentEditorWidget::masterVolumeNode is deprecated, use sourceVolumeNode() method instead.");
108  return this->sourceVolumeNode();
109  };
111  Q_INVOKABLE QString masterVolumeNodeID()const
112  {
113  qWarning("qMRMLSegmentEditorWidget::masterVolumeNodeID is deprecated, use sourceVolumeNodeID() method instead.");
114  return this->sourceVolumeNodeID();
115  };
117  Q_INVOKABLE QString currentSegmentID()const;
118 
121  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* activeEffect()const;
124  Q_INVOKABLE void setActiveEffect(qSlicerSegmentEditorAbstractEffect* effect);
125 
128  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByName(QString name);
129 
131  Q_INVOKABLE QStringList availableEffectNames();
132 
135  Q_INVOKABLE void setEffectNameOrder(const QStringList& effectNames);
136 
140  Q_INVOKABLE QStringList effectNameOrder() const;
141 
145  void setUnorderedEffectsVisible(bool visible);
146 
149  bool unorderedEffectsVisible() const;
150 
153  Q_INVOKABLE int effectCount();
154 
157  Q_INVOKABLE qSlicerSegmentEditorAbstractEffect* effectByIndex(int index);
158 
163  Q_INVOKABLE void setupViewObservations();
164 
168  Q_INVOKABLE void removeViewObservations();
169 
171  bool segmentationNodeSelectorVisible() const;
173  bool sourceVolumeNodeSelectorVisible() const;
177  bool autoShowSourceVolumeNode() const;
178 
181  {
182  qWarning("qMRMLSegmentEditorWidget::masterVolumeNodeSelectorVisible is deprecated, use sourceVolumeNodeSelectorVisible() method instead.");
183  return this->sourceVolumeNodeSelectorVisible();
184  };
187  {
188  qWarning("qMRMLSegmentEditorWidget::autoShowMasterVolumeNode is deprecated, use autoShowSourceVolumeNode() method instead.");
189  return this->autoShowSourceVolumeNode();
190  };
191 
193  bool switchToSegmentationsButtonVisible() const;
195  bool undoEnabled() const;
197  int maximumNumberOfUndoStates() const;
199  bool readOnly() const;
200 
203  Qt::ToolButtonStyle effectButtonStyle() const;
204 
207  int effectColumnCount() const;
208 
211  Q_INVOKABLE void segmentationNodeSelectorAddAttribute(const QString& nodeType,
212  const QString& attributeName,
213  const QVariant& attributeValue = QVariant());
216  Q_INVOKABLE void segmentationNodeSelectorRemoveAttribute(const QString& nodeType,
217  const QString& attributeName);
218 
221  Q_INVOKABLE void sourceVolumeNodeSelectorAddAttribute(const QString& nodeType,
222  const QString& attributeName,
223  const QVariant& attributeValue = QVariant());
226  Q_INVOKABLE void sourceVolumeNodeSelectorRemoveAttribute(const QString& nodeType,
227  const QString& attributeName);
228 
230  Q_INVOKABLE void masterVolumeNodeSelectorAddAttribute(const QString& nodeType,
231  const QString& attributeName,
232  const QVariant& attributeValue = QVariant())
233  {
234  qWarning("qMRMLSegmentEditorWidget::masterVolumeNodeSelectorAddAttribute is deprecated, use sourceVolumeNodeSelectorAddAttribute method instead.");
235  this->sourceVolumeNodeSelectorAddAttribute(nodeType, attributeName, attributeValue);
236  }
238  Q_INVOKABLE void masterVolumeNodeSelectorRemoveAttribute(const QString& nodeType,
239  const QString& attributeName)
240  {
241  qWarning("qMRMLSegmentEditorWidget::masterVolumeNodeSelectorRemoveAttribute is deprecated,"
242  " use sourceVolumeNodeSelectorRemoveAttribute instead.");
243  this->sourceVolumeNodeSelectorRemoveAttribute(nodeType, attributeName);
244  }
245 
248  Q_INVOKABLE vtkMRMLInteractionNode* interactionNode() const;
249 
256  void setDefaultTerminologyEntrySettingsKey(const QString& terminologyEntrySettingsKey);
259  QString defaultTerminologyEntrySettingsKey() const;
260 
263  void setDefaultTerminologyEntry(const QString& terminologyEntry);
266  QString defaultTerminologyEntry();
267 
269  bool jumpToSelectedSegmentEnabled()const;
270 
271 public slots:
273  void setMRMLScene(vtkMRMLScene* newScene) override;
274 
276  void setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode);
277 
279  virtual void updateWidgetFromMRML();
280 
282  void setSegmentationNode(vtkMRMLNode* node);
284  void setSegmentationNodeID(const QString& nodeID);
288  void setSourceVolumeNode(vtkMRMLNode* node);
290  void setSourceVolumeNodeID(const QString& nodeID);
291 
294  {
295  qWarning("qMRMLSegmentEditorWidget::setMasterVolumeNode is deprecated, use setSourceVolumeNode method instead.");
296  this->setSourceVolumeNode(node);
297  }
299  void setMasterVolumeNodeID(const QString& nodeID)
300  {
301  qWarning("qMRMLSegmentEditorWidget::setMasterVolumeNodeID is deprecated, use setSourceVolumeNodeID method instead.");
302  this->setSourceVolumeNodeID(nodeID);
303  }
304 
306  void setCurrentSegmentID(const QString segmentID);
307 
309  void setActiveEffectByName(QString effectName);
310 
313  void saveStateForUndo();
314 
316  void updateVolume(void* volumePtr, bool& success);
317 
319  void setSegmentationNodeSelectorVisible(bool);
321  void setSourceVolumeNodeSelectorVisible(bool);
325  void setAutoShowSourceVolumeNode(bool);
327  void setSwitchToSegmentationsButtonVisible(bool);
329  void setUndoEnabled(bool);
331  void setMaximumNumberOfUndoStates(int);
333  void setReadOnly(bool aReadOnly);
335  void toggleSourceVolumeIntensityMaskEnabled();
336 
339  {
340  qWarning("qMRMLSegmentEditorWidget::setMasterVolumeNodeSelectorVisible is deprecated, use setSourceVolumeNodeSelectorVisible method instead.");
341  this->setSourceVolumeNodeSelectorVisible(visible);
342  }
344  void setAutoShowMasterVolumeNode(bool autoShow)
345  {
346  qWarning("qMRMLSegmentEditorWidget::setAutoShowMasterVolumeNode is deprecated, use setAutoShowSourceVolumeNode method instead.");
347  this->setAutoShowSourceVolumeNode(autoShow);
348  }
351  {
352  qWarning("qMRMLSegmentEditorWidget::toggleMasterVolumeIntensityMaskEnabled is deprecated, use toggleSourceVolumeIntensityMaskEnabled method instead.");
353  this->toggleSourceVolumeIntensityMaskEnabled();
354  }
355 
357  void undo();
358 
360  void redo();
361 
365  void installKeyboardShortcuts(QWidget* parent = nullptr);
366 
368  void uninstallKeyboardShortcuts();
369 
373  bool turnOffLightboxes();
374 
376  void hideLabelLayer();
377 
380  void setEffectButtonStyle(Qt::ToolButtonStyle toolButtonStyle);
381 
383  void setEffectColumnCount(int columnCount);
384 
388  void updateEffectList();
389 
394  void showSourceVolumeInSliceViewers(bool forceShowInBackground = false, bool fitSlice = false);
395 
396  // Deprecated. Use showSourceVolumeInSliceViewers method instead.
397  void showMasterVolumeInSliceViewers(bool forceShowInBackground = false, bool fitSlice = false)
398  {
399  qWarning("qMRMLSegmentEditorWidget::showMasterVolumeInSliceViewers is deprecated, use showSourceVolumeInSliceViewers method instead.");
400  this->showSourceVolumeInSliceViewers(forceShowInBackground, fitSlice);
401  }
402 
405  void rotateSliceViewsToSegmentation();
406 
409  void setInteractionNode(vtkMRMLInteractionNode* interactionNode);
410 
412  void selectPreviousSegment();
413 
415  void selectNextSegment();
416 
420  void selectSegmentAtOffset (int offset);
421 
424  void jumpSlices();
425 
427  void setJumpToSelectedSegmentEnabled(bool enable);
428 
429 signals:
431  void currentSegmentIDChanged(const QString&);
432 
435  void sourceVolumeNodeChanged(vtkMRMLVolumeNode*);
436 
438  void masterVolumeNodeChanged(vtkMRMLVolumeNode*);
439 
442  void segmentationNodeChanged(vtkMRMLSegmentationNode*);
443 
444 protected slots:
446  void onSegmentationNodeChanged(vtkMRMLNode* node);
448  void onSourceVolumeNodeChanged(vtkMRMLNode* node);
450  void onSegmentSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
451 
453  void onInteractionNodeModified();
454 
456  void onEffectButtonClicked(QAbstractButton* button);
457 
461  void onSelectEffectShortcut();
462 
464  void onSelectSegmentShortcut();
465 
467  void onAddSegment();
469  void onRemoveSegment();
471  void onSwitchToSegmentations();
473  void onCreateSurfaceToggled(bool on);
475  void onSegmentAddedRemoved();
477  void onSourceVolumeImageDataModified();
479  void onLayoutChanged(int layoutIndex);
481  void onSegmentationDisplayModified();
482 
484  void onMaskModeChanged(int);
485 
487  void onSourceVolumeIntensityMaskChecked(bool checked);
489  void onSourceVolumeIntensityMaskRangeChanged(double low, double high);
490 
492  void onOverwriteModeChanged(int);
493 
495  void onMRMLSceneEndCloseEvent();
496 
498  void onMRMLSceneEndBatchProcessEvent();
499 
501  void initializeParameterSetNode();
502 
504  void updateUndoRedoButtonsState();
505 
507  void onSegmentationHistoryChanged();
508 
510  void onImportExportActionClicked();
512  void onExportToFilesActionClicked();
513 
515  void updateMaskingSection();
516 
518  void updateSliceRotateWarningButtonVisibility();
519 
521  void showSegmentationGeometryDialog();
522 
523 protected:
525  static void processEvents(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
526 
527  void updateWidgetFromSegmentationNode();
528  void updateWidgetFromSourceVolumeNode();
529  void updateEffectsSectionFromMRML();
530 
533  bool setMasterRepresentationToBinaryLabelmap();
534 
536  qSlicerAbstractModuleWidget* switchToSegmentationsModule();
537 
538 protected:
539  QScopedPointer<qMRMLSegmentEditorWidgetPrivate> d_ptr;
540 
541 private:
542  Q_DECLARE_PRIVATE(qMRMLSegmentEditorWidget);
543  Q_DISABLE_COPY(qMRMLSegmentEditorWidget);
544 };
545 
546 #endif
void toggleMasterVolumeIntensityMaskEnabled()
Deprecated. Use toggleSourceVolumeIntensityMaskEnabled method instead.
void showMasterVolumeInSliceViewers(bool forceShowInBackground=false, bool fitSlice=false)
void setMasterVolumeNodeID(const QString &nodeID)
Deprecated. Use setSourceVolumeNodeID method instead.
Q_INVOKABLE void masterVolumeNodeSelectorRemoveAttribute(const QString &nodeType, const QString &attributeName)
Deprecated use sourceVolumeNodeSelectorRemoveAttribute method instead.
Abstract class for segment editor effects.
void setMasterVolumeNodeSelectorVisible(bool visible)
Deprecated. Use setSourceVolumeNodeSelectorVisible method instead.
Q_INVOKABLE void masterVolumeNodeSelectorAddAttribute(const QString &nodeType, const QString &attributeName, const QVariant &attributeValue=QVariant())
Deprecated use sourceVolumeNodeSelectorAddAttribute method instead.
void setMasterVolumeNode(vtkMRMLNode *node)
Deprecated. Use setSourceVolumeNode method instead.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
bool masterVolumeNodeSelectorVisible() const
Deprecated. Use sourceVolumeNodeSelectorVisible() method instead.
bool autoShowMasterVolumeNode() const
Deprecated. Use autoShowSourceVolumeNode() method instead.
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).
virtual void setMRMLScene(vtkMRMLScene *newScene)
Set the MRML scene associated with the widget.
void setAutoShowMasterVolumeNode(bool autoShow)
Deprecated. Use setAutoShowSourceVolumeNode method instead.
QScopedPointer< qMRMLSegmentEditorWidgetPrivate > d_ptr
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
Q_INVOKABLE QString masterVolumeNodeID() const
Deprecated. Use sourceVolumeNodeID() method instead.
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...