Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
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>
21 
22 #include <QWidget>
23 #include <QItemSelectionModel>
24 
26 class QStyledItemDelegate;
27 class QWidgetAction;
28 
29 namespace Ui
30 {
32 }
33 
34 /*
35 * @brief This is an inspector that offers a tree view on the labels and groups of a MultiLabelSegmentation instance.
36 * It also allows some manipulation operations an the labels/groups according to the UI/selection state.
37 */
39 {
40  Q_OBJECT
41 
42 public:
43  QmitkMultiLabelInspector(QWidget* parent = nullptr);
45 
46  bool GetMultiSelectionMode() const;
47 
48  bool GetAllowVisibilityModification() const;
49  bool GetAllowLockModification() const;
50  bool GetAllowLabelModification() const;
53  bool GetModelManipulationOngoing() const;
54 
57 
61  LabelValueVectorType GetSelectedLabels() const;
62 
70  mitk::Label* GetCurrentLabel() const;
71 
72  enum class IndexLevelType
73  {
74  Group,
75  LabelClass,
76  LabelInstance
77  };
78 
83  IndexLevelType GetCurrentLevelType() const;
84 
91  LabelValueVectorType GetCurrentlyAffactedLabelInstances() const;
92 
97  LabelValueVectorType GetLabelInstancesOfSelectedFirstLabel() const;
98 
99 Q_SIGNALS:
105  void CurrentSelectionChanged(LabelValueVectorType labels) const;
106 
114  void GoToLabel(LabelValueType label, const mitk::Point3D& point) const;
115 
124  void LabelRenameRequested(mitk::Label* label, bool rename, bool& canceled) const;
125 
127  void ModelUpdated() const;
128 
130  void SegmentationChanged() const;
131 
132 public Q_SLOTS:
133 
140  void SetSelectedLabels(const LabelValueVectorType& selectedLabels);
147  void SetSelectedLabel(mitk::MultiLabelSegmentation::LabelValueType selectedLabel);
148 
156  void SetMultiLabelSegmentation(mitk::MultiLabelSegmentation* segmentation);
157  mitk::MultiLabelSegmentation* GetMultiLabelSegmentation() const;
158 
169  void SetMultiLabelNode(mitk::DataNode* node);
170  mitk::DataNode* GetMultiLabelNode() const;
171 
172  void SetMultiSelectionMode(bool multiMode);
173 
174  void SetAllowVisibilityModification(bool visiblityMod);
175  void SetAllowLockModification(bool lockMod);
176  void SetAllowLabelModification(bool labelMod);
177 
178  void SetDefaultLabelNaming(bool defaultLabelNaming);
179 
191  mitk::Label* AddNewLabelInstance();
192 
199  mitk::Label* AddNewLabel();
200 
206  void DeleteLabelInstance();
207 
213  void DeleteLabel();
214 
218  mitk::Label* AddNewGroup();
219 
224  void RemoveGroup();
225 
231  void OnCopyToGroup();
232 
233  void SetVisibilityOfAffectedLabels(bool visible) const;
234  void SetLockOfAffectedLabels(bool visible) const;
235 
236 protected Q_SLOTS:
237  void OnModelReset();
238  void OnModelChanged();
239  void OnDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
240  const QList<int>& roles = QList<int>());
241 
242 protected:
243  void Initialize();
244 
247 
249  QStyledItemDelegate* m_LockItemDelegate;
250  QStyledItemDelegate* m_ColorItemDelegate;
251  QStyledItemDelegate* m_VisibilityItemDelegate;
252 
253  Ui::QmitkMultiLabelInspector* m_Controls;
254 
255  LabelValueVectorType GetSelectedLabelsFromSelectionModel() const;
256  void UpdateSelectionModel(const LabelValueVectorType& selectedLabels);
257 
260  mitk::Label* GetFirstSelectedLabelObject() const;
261 
262  mitk::Label* AddNewLabelInternal(const mitk::MultiLabelSegmentation::GroupIndexType& containingGroup);
263 
266  mitk::Label* AddNewLabelInstanceInternal(mitk::Label* templateLabel);
267 
268  void RemoveGroupInternal(const mitk::MultiLabelSegmentation::GroupIndexType& groupID);
269  void DeleteLabelInternal(const LabelValueVectorType& labelValues);
270 
271  void keyPressEvent(QKeyEvent* event) override;
272  void keyReleaseEvent(QKeyEvent* event) override;
273 
274 private Q_SLOTS:
284  void OnChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected);
285 
286  void OnContextMenuRequested(const QPoint&);
287 
288  void OnAddLabel();
289  void OnAddLabelInstance();
290  void OnDeleteGroup();
291  void OnDeleteAffectedLabel();
292  void OnDeleteLabels(bool);
293  void OnClearLabels(bool);
294  void OnMergeLabels(bool);
295 
296  void OnRenameGroup();
297  void OnRenameLabel(bool);
298  void OnClearLabel(bool);
299 
300  void OnUnlockAffectedLabels();
301  void OnLockAffectedLabels();
302 
303  void OnSetAffectedLabelsVisible();
304  void OnSetAffectedLabelsInvisible();
305  void OnSetOnlyActiveLabelVisible(bool);
306 
307  void OnItemDoubleClicked(const QModelIndex& index);
308 
309  void WaitCursorOn() const;
310  void WaitCursorOff() const;
311  void RestoreOverrideCursor() const;
312 
313  void PrepareGoToLabel(LabelValueType labelID) const;
314 
315  void OnEntered(const QModelIndex& index);
316  void OnMouseLeave();
317 
318  QWidgetAction* CreateOpacityAction();
319 
320 private:
321  bool m_ShowVisibility = true;
322  bool m_ShowLock = true;
323  bool m_ShowOther = false;
324 
329  bool m_AllowVisibilityModification = true;
330 
333  bool m_AllowLockModification = true;
334 
337  bool m_AllowLabelModification = false;
338 
339  bool m_DefaultLabelNaming = true;
340 
341  bool m_ModelManipulationOngoing = false;
342 
343  bool m_AboutToShowContextMenu = false;
344 
345  bool m_CheckSelectionDueToExternalModelChange = true;
346 
347  mitk::DataNode::Pointer m_SegmentationNode;
348  unsigned long m_SegmentationNodeDataMTime;
349  mitk::ITKEventObserverGuard m_SegmentationObserver;
350  mitk::LabelHighlightGuard m_LabelHighlightGuard;
351 };
352 
353 #endif
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelInspector::m_LastValidSelectedLabels
LabelValueVectorType m_LastValidSelectedLabels
Definition: QmitkMultiLabelInspector.h:248
mitk::LabelHighlightGuard
Definition: mitkLabelHighlightGuard.h:29
QmitkMultiLabelInspector::m_ColorItemDelegate
QStyledItemDelegate * m_ColorItemDelegate
Definition: QmitkMultiLabelInspector.h:250
mitk::ITKEventObserverGuard
Convenience class that helps to manage the lifetime of itk event observers.
Definition: mitkITKEventObserverGuard.h:55
QmitkMultiLabelInspector::LabelValueVectorType
mitk::MultiLabelSegmentation::LabelValueVectorType LabelValueVectorType
Definition: QmitkMultiLabelInspector.h:56
mitk::SlicedData::Pointer
itk::SmartPointer< Self > Pointer
Definition: mitkSlicedData.h:40
QmitkMultiLabelTreeModel
Definition: QmitkMultiLabelTreeModel.h:32
itk::SmartPointer< Self >
QmitkMultiLabelInspector::m_LockItemDelegate
QStyledItemDelegate * m_LockItemDelegate
Definition: QmitkMultiLabelInspector.h:249
QmitkMultiLabelInspector::m_Model
QmitkMultiLabelTreeModel * m_Model
Definition: QmitkMultiLabelInspector.h:245
mitk::MultiLabelSegmentation::GroupIndexType
std::size_t GroupIndexType
Definition: mitkLabelSetImage.h:56
mitk::MultiLabelSegmentation::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:57
QmitkMultiLabelInspector::m_Segmentation
mitk::MultiLabelSegmentation::Pointer m_Segmentation
Definition: QmitkMultiLabelInspector.h:246
QmitkMultiLabelInspector::m_VisibilityItemDelegate
QStyledItemDelegate * m_VisibilityItemDelegate
Definition: QmitkMultiLabelInspector.h:251
mitkLabelHighlightGuard.h
mitk::MultiLabelSegmentation::LabelValueVectorType
std::vector< LabelValueType > LabelValueVectorType
Definition: mitkLabelSetImage.h:60
Ui
Definition: BlueBerryExampleLauncherDialog.h:21
mitk::Label
A data structure describing a label.
Definition: mitkLabel.h:29
mitk::Point< ScalarType, 3 >
mitk::MultiLabelSegmentation
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
QmitkMultiLabelInspector::m_Controls
Ui::QmitkMultiLabelInspector * m_Controls
Definition: QmitkMultiLabelInspector.h:253
QmitkMultiLabelInspector::LabelValueType
mitk::MultiLabelSegmentation::LabelValueType LabelValueType
Definition: QmitkMultiLabelInspector.h:55
mitkDataNode.h
mitkWeakPointer.h
QmitkMultiLabelInspector
Definition: QmitkMultiLabelInspector.h:38
MitkSegmentationUIExports.h
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
QmitkMultiLabelInspector::IndexLevelType
IndexLevelType
Definition: QmitkMultiLabelInspector.h:72
mitkLabelSetImage.h