Medical Imaging Interaction Toolkit  2025.12.02
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>
22 
23 #include <QWidget>
24 #include <QItemSelectionModel>
25 
27 class QStyledItemDelegate;
28 class QWidgetAction;
29 class QCompleter;
30 
31 namespace Ui
32 {
34 }
35 
36 /*
37 * @brief This is an inspector that offers a tree view on the labels and groups of a MultiLabelSegmentation instance.
38 * It also allows some manipulation operations an the labels/groups according to the UI/selection state.
39 */
41 {
42  Q_OBJECT
43 
44 public:
45  QmitkMultiLabelInspector(QWidget* parent = nullptr);
46 
48 
49  bool GetMultiSelectionMode() const;
50 
57 
60 
65 
74 
75  enum class IndexLevelType
76  {
77  Group,
78  LabelClass,
79  LabelInstance
80  };
81 
87 
95 
101 
103 
104 Q_SIGNALS:
111 
119  void GoToLabel(LabelValueType label, const mitk::Point3D& point) const;
120 
129  void LabelRenameRequested(mitk::Label* label, bool rename, bool& canceled) const;
130 
132  void ModelUpdated() const;
133 
135  void SegmentationChanged() const;
136 
137 public Q_SLOTS:
138 
145  void SetSelectedLabels(const LabelValueVectorType& selectedLabels);
153 
163 
176 
177  void SetMultiSelectionMode(bool multiMode);
178 
179  void SetAllowVisibilityModification(bool visiblityMod);
180  void SetAllowLockModification(bool lockMod);
181  void SetAllowLabelModification(bool labelMod);
182 
183  void SetDefaultLabelNaming(bool defaultLabelNaming);
184 
186 
199 
207 
214 
220  void DeleteLabel();
221 
226 
231  void RemoveGroup();
232 
239 
240  void SetVisibilityOfAffectedLabels(bool visible) const;
241  void SetLockOfAffectedLabels(bool visible) const;
242 
243 protected Q_SLOTS:
244  void OnModelReset();
246  void OnDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
247  const QList<int>& roles = QList<int>());
248 
249 protected:
250  void Initialize();
251 
253  mitk::MultiLabelSegmentation::Pointer m_Segmentation;
254 
256  QStyledItemDelegate* m_LockItemDelegate;
257  QStyledItemDelegate* m_ColorItemDelegate;
258  QStyledItemDelegate* m_VisibilityItemDelegate;
259 
260  Ui::QmitkMultiLabelInspector* m_Controls;
261 
263  void UpdateSelectionModel(const LabelValueVectorType& selectedLabels);
264 
268 
270 
274 
276  void DeleteLabelInternal(const LabelValueVectorType& labelValues);
277 
278  void keyPressEvent(QKeyEvent* event) override;
279  void keyReleaseEvent(QKeyEvent* event) override;
280 
281 private Q_SLOTS:
291  void OnChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected);
292 
293  void OnContextMenuRequested(const QPoint&);
294 
295  void OnAddLabel();
296  void OnAddLabelInstance();
297  void OnDeleteGroup();
298  void OnDeleteAffectedLabel();
299  void OnDeleteLabels(bool);
300  void OnClearLabels(bool);
301  void OnMergeLabels(bool);
302 
303  void OnRenameGroup();
304  void OnRenameLabel(bool);
305  void OnClearLabel(bool);
306 
307  void OnUnlockAffectedLabels();
308  void OnLockAffectedLabels();
309 
310  void OnSetAffectedLabelsVisible();
311  void OnSetAffectedLabelsInvisible();
312  void OnSetOnlyActiveLabelVisible(bool);
313 
314  void OnItemDoubleClicked(const QModelIndex& index);
315 
316  void WaitCursorOn() const;
317  void WaitCursorOff() const;
318  void RestoreOverrideCursor() const;
319 
320  void PrepareGoToLabel(LabelValueType labelID) const;
321 
322  void OnEntered(const QModelIndex& index);
323  void OnMouseLeave();
324 
325  void OnSearchLabel();
326  void RefreshCompleter();
327 
328  QWidgetAction* CreateOpacityAction();
329 
330 private:
331  bool m_ShowVisibility = true;
332  bool m_ShowLock = true;
333  bool m_ShowOther = false;
334 
339  bool m_AllowVisibilityModification = true;
340 
343  bool m_AllowLockModification = true;
344 
347  bool m_AllowLabelModification = false;
348 
349  bool m_DefaultLabelNaming = true;
350 
351  bool m_ModelManipulationOngoing = false;
352 
353  bool m_AboutToShowContextMenu = false;
354 
355  bool m_CheckSelectionDueToExternalModelChange = true;
356 
357  mitk::DataNode::Pointer m_SegmentationNode;
358  unsigned long m_SegmentationNodeDataMTime;
359  mitk::ITKEventObserverGuard m_SegmentationObserver;
360  mitk::LabelHighlightGuard m_LabelHighlightGuard;
361  mitk::LabelSuggestionHelper::ConstPointer m_SuggestionHelper;
362  mitk::ITKEventObserverGuard m_SuggestionObserver;
363 
364  QCompleter* m_Completer;
365 };
366 
367 #endif
#define MITKSEGMENTATIONUI_EXPORT
bool GetAllowLabelModification() const
void SetLockOfAffectedLabels(bool visible) const
void SetMultiSelectionMode(bool multiMode)
void SetVisibilityOfAffectedLabels(bool visible) const
mitk::Label * AddNewLabelInstanceInternal(mitk::Label *templateLabel)
Adds an instance of the same label/class like the passed label value.
mitk::Label * AddNewLabelInternal(const mitk::MultiLabelSegmentation::GroupIndexType &containingGroup)
void RemoveGroup()
Removes the group of the first currently selected label of the segmentation. If no label is selected ...
void CurrentSelectionChanged(LabelValueVectorType labels) const
A signal that will be emitted if the selected labels change.
void OnCopyToGroup()
Copies a label to another group.
void keyPressEvent(QKeyEvent *event) override
bool GetAllowVisibilityModification() const
const mitk::LabelSuggestionHelper * GetLabelSuggestionHelper() const
QStyledItemDelegate * m_VisibilityItemDelegate
QmitkMultiLabelInspector(QWidget *parent=nullptr)
void DeleteLabel()
Delete the first currently selected label and all its instances of the segmentation....
IndexLevelType GetCurrentLevelType() const
Returns the level of the index that currently has the focus in the tree view.
void SetSelectedLabel(mitk::MultiLabelSegmentation::LabelValueType selectedLabel)
The passed label will be used as new selection in the widget.
QStyledItemDelegate * m_LockItemDelegate
LabelValueVectorType GetSelectedLabelsFromSelectionModel() const
QmitkMultiLabelTreeModel * m_Model
mitk::Label * AddNewGroup()
Adds a new group with a new label to segmentation.
void SegmentationChanged() const
Signal is emitted, if the segmentation is changed that is observed by the inspector.
LabelValueVectorType GetLabelInstancesOfSelectedFirstLabel() const
Returns the values of all label instances that are of the same label (class) like the first selected ...
void RemoveGroupInternal(const mitk::MultiLabelSegmentation::GroupIndexType &groupID)
void SetAllowLabelModification(bool labelMod)
void UpdateSelectionModel(const LabelValueVectorType &selectedLabels)
bool GetModelManipulationOngoing() const
void SetAllowVisibilityModification(bool visiblityMod)
void DeleteLabelInternal(const LabelValueVectorType &labelValues)
void SetLabelSuggestionHelper(const mitk::LabelSuggestionHelper *suggestionHelper)
mitk::Label * GetCurrentLabel() const
Returns the label that currently has the focus in the tree view.
Ui::QmitkMultiLabelInspector * m_Controls
void OnDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
LabelValueVectorType m_LastValidSelectedLabels
mitk::MultiLabelSegmentation::LabelValueVectorType LabelValueVectorType
LabelValueVectorType GetCurrentlyAffactedLabelInstances() const
Returns all label values that are currently affected.
mitk::MultiLabelSegmentation * GetMultiLabelSegmentation() const
void keyReleaseEvent(QKeyEvent *event) override
mitk::Label * GetFirstSelectedLabelObject() const
Helper that returns the label object (if multiple labels are selected the first).
LabelValueVectorType GetSelectedLabels() const
Retrieve the currently selected labels (equals the last CurrentSelectionChanged values).
void LabelRenameRequested(mitk::Label *label, bool rename, bool &canceled) const
Signal that is emitted, if a label should be (re)named and default label naming is deactivated.
bool GetMultiSelectionMode() const
mitk::MultiLabelSegmentation::LabelValueType LabelValueType
void SetMultiLabelNode(mitk::DataNode *node)
Sets the segmentation node that will be used /monitored by the widget.
void ModelUpdated() const
Signal that is emitted, if the model was updated (e.g. by a delete or add operation).
void SetSelectedLabels(const LabelValueVectorType &selectedLabels)
Transform a list of label values into the new selection of the inspector.
mitk::Label * AddNewLabelInstance()
Adds an instance of the same label/class like the first label instance indicated by GetSelectedLabels...
void GoToLabel(LabelValueType label, const mitk::Point3D &point) const
A signal that will be emitted if the user has requested to "go to" a certain label.
mitk::MultiLabelSegmentation::Pointer m_Segmentation
mitk::Label * AddNewLabel()
Adds a new label to the segmentation. Depending on the settings the name of the label will be either ...
void SetDefaultLabelNaming(bool defaultLabelNaming)
bool GetAllowLockModification() const
void SetAllowLockModification(bool lockMod)
void DeleteLabelInstance()
Removes the first currently selected label instance of the segmentation. If no label is selected noth...
void SetMultiLabelSegmentation(mitk::MultiLabelSegmentation *segmentation)
Sets the segmentation that will be used and monitored by the widget.
QStyledItemDelegate * m_ColorItemDelegate
mitk::DataNode * GetMultiLabelNode() const
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Convenience class that helps to manage the lifetime of itk event observers.
Helper class for handling label suggestions with constraint checking.
A data structure describing a label.
Definition: mitkLabel.h:90
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
std::vector< LabelValueType > LabelValueVectorType
mitk::Label::PixelType LabelValueType