Medical Imaging Interaction Toolkit  2024.12.99-d991a09f
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
231  void OnCopyToGroup();
232 
233  void SetVisibilityOfAffectedLabels(bool visible) const;
234  void SetLockOfAffectedLabels(bool visible) const;
235 
236 protected:
237  void Initialize();
238  void OnModelReset();
239  void OnDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
240  const QList<int>& roles = QList<int>());
241 
244 
246  QStyledItemDelegate* m_LockItemDelegate;
247  QStyledItemDelegate* m_ColorItemDelegate;
248  QStyledItemDelegate* m_VisibilityItemDelegate;
249 
250  Ui::QmitkMultiLabelInspector* m_Controls;
251 
252  LabelValueVectorType GetSelectedLabelsFromSelectionModel() const;
253  void UpdateSelectionModel(const LabelValueVectorType& selectedLabels);
254 
257  mitk::Label* GetFirstSelectedLabelObject() const;
258 
259  mitk::Label* AddNewLabelInternal(const mitk::LabelSetImage::GroupIndexType& containingGroup);
260 
263  mitk::Label* AddNewLabelInstanceInternal(mitk::Label* templateLabel);
264 
265  void RemoveGroupInternal(const mitk::LabelSetImage::GroupIndexType& groupID);
266  void DeleteLabelInternal(const LabelValueVectorType& labelValues);
267 
268  void keyPressEvent(QKeyEvent* event) override;
269  void keyReleaseEvent(QKeyEvent* event) override;
270 
271 private Q_SLOTS:
281  void OnChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected);
282 
283  void OnContextMenuRequested(const QPoint&);
284 
285  void OnAddLabel();
286  void OnAddLabelInstance();
287  void OnDeleteGroup();
288  void OnDeleteAffectedLabel();
289  void OnDeleteLabels(bool);
290  void OnClearLabels(bool);
291  void OnMergeLabels(bool);
292 
293  void OnRenameGroup();
294  void OnRenameLabel(bool);
295  void OnClearLabel(bool);
296 
297  void OnUnlockAffectedLabels();
298  void OnLockAffectedLabels();
299 
300  void OnSetAffectedLabelsVisible();
301  void OnSetAffectedLabelsInvisible();
302  void OnSetOnlyActiveLabelVisible(bool);
303 
304  void OnItemDoubleClicked(const QModelIndex& index);
305 
306  void WaitCursorOn() const;
307  void WaitCursorOff() const;
308  void RestoreOverrideCursor() const;
309 
310  void PrepareGoToLabel(LabelValueType labelID) const;
311 
312  void OnEntered(const QModelIndex& index);
313  void OnMouseLeave();
314 
315  QWidgetAction* CreateOpacityAction();
316 
317 private:
318  bool m_ShowVisibility = true;
319  bool m_ShowLock = true;
320  bool m_ShowOther = false;
321 
326  bool m_AllowVisibilityModification = true;
327 
330  bool m_AllowLockModification = true;
331 
334  bool m_AllowLabelModification = false;
335 
336  bool m_DefaultLabelNaming = true;
337 
338  bool m_ModelManipulationOngoing = false;
339 
340  bool m_AboutToShowContextMenu = false;
341  mitk::DataNode::Pointer m_SegmentationNode;
342  unsigned long m_SegmentationNodeDataMTime;
343  mitk::ITKEventObserverGuard m_SegmentationObserver;
344  mitk::LabelHighlightGuard m_LabelHighlightGuard;
345 };
346 
347 #endif
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelInspector::m_LastValidSelectedLabels
LabelValueVectorType m_LastValidSelectedLabels
Definition: QmitkMultiLabelInspector.h:245
mitk::LabelHighlightGuard
Definition: mitkLabelHighlightGuard.h:29
QmitkMultiLabelInspector::m_ColorItemDelegate
QStyledItemDelegate * m_ColorItemDelegate
Definition: QmitkMultiLabelInspector.h:247
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:246
QmitkMultiLabelInspector::m_Model
QmitkMultiLabelTreeModel * m_Model
Definition: QmitkMultiLabelInspector.h:242
QmitkMultiLabelInspector::m_VisibilityItemDelegate
QStyledItemDelegate * m_VisibilityItemDelegate
Definition: QmitkMultiLabelInspector.h:248
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:250
mitk::Image::Pointer
itk::SmartPointer< Self > Pointer
Definition: mitkImage.h:80
mitkDataNode.h
mitkWeakPointer.h
QmitkMultiLabelInspector
Definition: QmitkMultiLabelInspector.h:38
MitkSegmentationUIExports.h
QmitkMultiLabelInspector::m_Segmentation
mitk::LabelSetImage::Pointer m_Segmentation
Definition: QmitkMultiLabelInspector.h:243
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