Medical Imaging Interaction Toolkit  2023.12.99-f298153c
Medical Imaging Interaction Toolkit
QmitkMultiLabelInspector.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkMultiLabelInspector_h
14 #define QmitkMultiLabelInspector_h
15 
17 #include <mitkWeakPointer.h>
18 #include <mitkLabelSetImage.h>
19 #include <mitkDataNode.h>
20 
21 #include <QWidget>
22 #include <QItemSelectionModel>
23 
25 class QStyledItemDelegate;
26 class QWidgetAction;
27 
28 namespace Ui
29 {
31 }
32 
33 /*
34 * @brief This is an inspector that offers a tree view on the labels and groups of a MultiLabelSegmentation instance.
35 * It also allows some manipulation operations an the labels/groups accordin to the UI/selection state.
36 */
38 {
39  Q_OBJECT
40 
41 public:
42  QmitkMultiLabelInspector(QWidget* parent = nullptr);
44 
45  bool GetMultiSelectionMode() const;
46 
47  bool GetAllowVisibilityModification() const;
48  bool GetAllowLockModification() const;
49  bool GetAllowLabelModification() const;
52  bool GetModelManipulationOngoing() const;
53 
56 
60  LabelValueVectorType GetSelectedLabels() const;
61 
69  mitk::Label* GetCurrentLabel() const;
70 
71  enum class IndexLevelType
72  {
73  Group,
74  LabelClass,
75  LabelInstance
76  };
77 
82  IndexLevelType GetCurrentLevelType() const;
83 
90  LabelValueVectorType GetCurrentlyAffactedLabelInstances() const;
91 
96  LabelValueVectorType GetLabelInstancesOfSelectedFirstLabel() const;
97 
98 Q_SIGNALS:
104  void CurrentSelectionChanged(LabelValueVectorType labels) const;
105 
113  void GoToLabel(LabelValueType label, const mitk::Point3D& point) const;
114 
122  void LabelRenameRequested(mitk::Label* label, bool rename) const;
123 
125  void ModelUpdated() const;
126 
128  void SegmentationChanged() const;
129 
130 public Q_SLOTS:
131 
138  void SetSelectedLabels(const LabelValueVectorType& selectedLabels);
145  void SetSelectedLabel(mitk::LabelSetImage::LabelValueType selectedLabel);
146 
154  void SetMultiLabelSegmentation(mitk::LabelSetImage* segmentation);
155  mitk::LabelSetImage* GetMultiLabelSegmentation() const;
156 
167  void SetMultiLabelNode(mitk::DataNode* node);
168  mitk::DataNode* GetMultiLabelNode() const;
169 
170  void SetMultiSelectionMode(bool multiMode);
171 
172  void SetAllowVisibilityModification(bool visiblityMod);
173  void SetAllowLockModification(bool lockMod);
174  void SetAllowLabelModification(bool labelMod);
175 
176  void SetDefaultLabelNaming(bool defaultLabelNaming);
177 
189  mitk::Label* AddNewLabelInstance();
190 
197  mitk::Label* AddNewLabel();
198 
204  void DeleteLabelInstance();
205 
211  void DeleteLabel();
212 
216  mitk::Label* AddNewGroup();
217 
222  void RemoveGroup();
223 
224  void SetVisibilityOfAffectedLabels(bool visible) const;
225  void SetLockOfAffectedLabels(bool visible) const;
226 
227 protected:
228  void Initialize();
229  void OnModelReset();
230  void OnDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
231  const QList<int>& roles = QList<int>());
232 
235 
237  QStyledItemDelegate* m_LockItemDelegate;
238  QStyledItemDelegate* m_ColorItemDelegate;
239  QStyledItemDelegate* m_VisibilityItemDelegate;
240 
241  Ui::QmitkMultiLabelInspector* m_Controls;
242 
243  LabelValueVectorType GetSelectedLabelsFromSelectionModel() const;
244  void UpdateSelectionModel(const LabelValueVectorType& selectedLabels);
245 
248  mitk::Label* GetFirstSelectedLabelObject() const;
249 
250  mitk::Label* AddNewLabelInternal(const mitk::LabelSetImage::GroupIndexType& containingGroup);
251 
254  mitk::Label* AddNewLabelInstanceInternal(mitk::Label* templateLabel);
255 
256  void RemoveGroupInternal(const mitk::LabelSetImage::GroupIndexType& groupID);
257  void DeleteLabelInternal(const LabelValueVectorType& labelValues);
258 
259 private Q_SLOTS:
269  void OnChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected);
270 
271  void OnContextMenuRequested(const QPoint&);
272 
273  void OnAddLabel();
274  void OnAddLabelInstance();
275  void OnDeleteGroup();
276  void OnDeleteAffectedLabel();
277  void OnDeleteLabels(bool);
278  void OnClearLabels(bool);
279  void OnMergeLabels(bool);
280 
281  void OnRenameLabel(bool);
282  void OnClearLabel(bool);
283 
284  void OnUnlockAffectedLabels();
285  void OnLockAffectedLabels();
286 
287  void OnSetAffectedLabelsVisible();
288  void OnSetAffectedLabelsInvisible();
289  void OnSetOnlyActiveLabelVisible(bool);
290 
291  void OnItemDoubleClicked(const QModelIndex& index);
292 
293  void WaitCursorOn() const;
294  void WaitCursorOff() const;
295  void RestoreOverrideCursor() const;
296 
297  void PrepareGoToLabel(LabelValueType labelID) const;
298 
299  void OnEntered(const QModelIndex& index);
300  void OnMouseLeave();
301 
302  QWidgetAction* CreateOpacityAction();
303 
304 private:
305  bool m_ShowVisibility = true;
306  bool m_ShowLock = true;
307  bool m_ShowOther = false;
308 
313  bool m_AllowVisibilityModification = true;
314 
317  bool m_AllowLockModification = true;
318 
321  bool m_AllowLabelModification = false;
322 
323  bool m_DefaultLabelNaming = true;
324 
325  bool m_ModelManipulationOngoing = false;
326 
327  bool m_AboutToShowContextMenu = false;
328  mitk::DataNode::Pointer m_SegmentationNode;
329  unsigned long m_SegmentationNodeDataMTime;
330  mitk::ITKEventObserverGuard m_SegmentationObserver;
331 };
332 
333 #endif
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelInspector::m_LastValidSelectedLabels
LabelValueVectorType m_LastValidSelectedLabels
Definition: QmitkMultiLabelInspector.h:236
QmitkMultiLabelInspector::m_ColorItemDelegate
QStyledItemDelegate * m_ColorItemDelegate
Definition: QmitkMultiLabelInspector.h:238
mitk::ITKEventObserverGuard
Convenience class that helps to manage the lifetime of itk event observers.
Definition: mitkITKEventObserverGuard.h:55
QmitkMultiLabelInspector::LabelValueType
mitk::LabelSetImage::LabelValueType LabelValueType
Definition: QmitkMultiLabelInspector.h:54
QmitkMultiLabelInspector::LabelValueVectorType
mitk::LabelSetImage::LabelValueVectorType LabelValueVectorType
Definition: QmitkMultiLabelInspector.h:55
QmitkMultiLabelTreeModel
Definition: QmitkMultiLabelTreeModel.h:32
itk::SmartPointer< Self >
QmitkMultiLabelInspector::m_LockItemDelegate
QStyledItemDelegate * m_LockItemDelegate
Definition: QmitkMultiLabelInspector.h:237
QmitkMultiLabelInspector::m_Model
QmitkMultiLabelTreeModel * m_Model
Definition: QmitkMultiLabelInspector.h:233
QmitkMultiLabelInspector::m_VisibilityItemDelegate
QStyledItemDelegate * m_VisibilityItemDelegate
Definition: QmitkMultiLabelInspector.h:239
Ui
Definition: BlueBerryExampleLauncherDialog.h:21
mitk::Label
A data structure describing a label.
Definition: mitkLabel.h:29
mitk::Point< ScalarType, 3 >
QmitkMultiLabelInspector::m_Controls
Ui::QmitkMultiLabelInspector * m_Controls
Definition: QmitkMultiLabelInspector.h:241
mitk::Image::Pointer
itk::SmartPointer< Self > Pointer
Definition: mitkImage.h:81
mitkDataNode.h
mitkWeakPointer.h
QmitkMultiLabelInspector
Definition: QmitkMultiLabelInspector.h:37
MitkSegmentationUIExports.h
QmitkMultiLabelInspector::m_Segmentation
mitk::LabelSetImage::Pointer m_Segmentation
Definition: QmitkMultiLabelInspector.h:234
mitk::LabelSetImage::GroupIndexType
std::size_t GroupIndexType
Definition: mitkLabelSetImage.h:74
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
mitk::LabelSetImage::LabelValueVectorType
std::vector< LabelValueType > LabelValueVectorType
Definition: mitkLabelSetImage.h:78
mitk::LabelSetImage
LabelSetImage class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
QmitkMultiLabelInspector::IndexLevelType
IndexLevelType
Definition: QmitkMultiLabelInspector.h:71
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:75
mitkLabelSetImage.h