Medical Imaging Interaction Toolkit  2024.06.00
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::LabelSetImage::LabelValueType selectedLabel);
148 
156  void SetMultiLabelSegmentation(mitk::LabelSetImage* segmentation);
157  mitk::LabelSetImage* 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 
226  void SetVisibilityOfAffectedLabels(bool visible) const;
227  void SetLockOfAffectedLabels(bool visible) const;
228 
229 protected:
230  void Initialize();
231  void OnModelReset();
232  void OnDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
233  const QList<int>& roles = QList<int>());
234 
237 
239  QStyledItemDelegate* m_LockItemDelegate;
240  QStyledItemDelegate* m_ColorItemDelegate;
241  QStyledItemDelegate* m_VisibilityItemDelegate;
242 
243  Ui::QmitkMultiLabelInspector* m_Controls;
244 
245  LabelValueVectorType GetSelectedLabelsFromSelectionModel() const;
246  void UpdateSelectionModel(const LabelValueVectorType& selectedLabels);
247 
250  mitk::Label* GetFirstSelectedLabelObject() const;
251 
252  mitk::Label* AddNewLabelInternal(const mitk::LabelSetImage::GroupIndexType& containingGroup);
253 
256  mitk::Label* AddNewLabelInstanceInternal(mitk::Label* templateLabel);
257 
258  void RemoveGroupInternal(const mitk::LabelSetImage::GroupIndexType& groupID);
259  void DeleteLabelInternal(const LabelValueVectorType& labelValues);
260 
261  void keyPressEvent(QKeyEvent* event) override;
262  void keyReleaseEvent(QKeyEvent* event) override;
263 
264 private Q_SLOTS:
274  void OnChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected);
275 
276  void OnContextMenuRequested(const QPoint&);
277 
278  void OnAddLabel();
279  void OnAddLabelInstance();
280  void OnDeleteGroup();
281  void OnDeleteAffectedLabel();
282  void OnDeleteLabels(bool);
283  void OnClearLabels(bool);
284  void OnMergeLabels(bool);
285 
286  void OnRenameLabel(bool);
287  void OnClearLabel(bool);
288 
289  void OnUnlockAffectedLabels();
290  void OnLockAffectedLabels();
291 
292  void OnSetAffectedLabelsVisible();
293  void OnSetAffectedLabelsInvisible();
294  void OnSetOnlyActiveLabelVisible(bool);
295 
296  void OnItemDoubleClicked(const QModelIndex& index);
297 
298  void WaitCursorOn() const;
299  void WaitCursorOff() const;
300  void RestoreOverrideCursor() const;
301 
302  void PrepareGoToLabel(LabelValueType labelID) const;
303 
304  void OnEntered(const QModelIndex& index);
305  void OnMouseLeave();
306 
307  QWidgetAction* CreateOpacityAction();
308 
309 private:
310  bool m_ShowVisibility = true;
311  bool m_ShowLock = true;
312  bool m_ShowOther = false;
313 
318  bool m_AllowVisibilityModification = true;
319 
322  bool m_AllowLockModification = true;
323 
326  bool m_AllowLabelModification = false;
327 
328  bool m_DefaultLabelNaming = true;
329 
330  bool m_ModelManipulationOngoing = false;
331 
332  bool m_AboutToShowContextMenu = false;
333  mitk::DataNode::Pointer m_SegmentationNode;
334  unsigned long m_SegmentationNodeDataMTime;
335  mitk::ITKEventObserverGuard m_SegmentationObserver;
336  mitk::LabelHighlightGuard m_LabelHighlightGuard;
337 };
338 
339 #endif
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelInspector::m_LastValidSelectedLabels
LabelValueVectorType m_LastValidSelectedLabels
Definition: QmitkMultiLabelInspector.h:238
mitk::LabelHighlightGuard
Definition: mitkLabelHighlightGuard.h:29
QmitkMultiLabelInspector::m_ColorItemDelegate
QStyledItemDelegate * m_ColorItemDelegate
Definition: QmitkMultiLabelInspector.h:240
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:55
QmitkMultiLabelInspector::LabelValueVectorType
mitk::LabelSetImage::LabelValueVectorType LabelValueVectorType
Definition: QmitkMultiLabelInspector.h:56
QmitkMultiLabelTreeModel
Definition: QmitkMultiLabelTreeModel.h:32
itk::SmartPointer< Self >
QmitkMultiLabelInspector::m_LockItemDelegate
QStyledItemDelegate * m_LockItemDelegate
Definition: QmitkMultiLabelInspector.h:239
QmitkMultiLabelInspector::m_Model
QmitkMultiLabelTreeModel * m_Model
Definition: QmitkMultiLabelInspector.h:235
QmitkMultiLabelInspector::m_VisibilityItemDelegate
QStyledItemDelegate * m_VisibilityItemDelegate
Definition: QmitkMultiLabelInspector.h:241
mitkLabelHighlightGuard.h
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:243
mitk::Image::Pointer
itk::SmartPointer< Self > Pointer
Definition: mitkImage.h:81
mitkDataNode.h
mitkWeakPointer.h
QmitkMultiLabelInspector
Definition: QmitkMultiLabelInspector.h:38
MitkSegmentationUIExports.h
QmitkMultiLabelInspector::m_Segmentation
mitk::LabelSetImage::Pointer m_Segmentation
Definition: QmitkMultiLabelInspector.h:236
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:72
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:75
mitkLabelSetImage.h