Medical Imaging Interaction Toolkit  2026.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>
22 
23 #include <QWidget>
24 #include <QItemSelectionModel>
25 #include <memory>
26 
28 class QStyledItemDelegate;
29 class QWidgetAction;
30 class QCompleter;
31 
32 namespace Ui
33 {
35 }
36 
43 {
44  Q_OBJECT
45 
46 public:
48  QmitkMultiLabelInspector(QWidget* parent = nullptr);
49 
51 
53  bool GetMultiSelectionMode() const;
54 
64 
67 
72 
81 
82  enum class IndexLevelType
83  {
84  Group,
85  LabelClass,
86  LabelInstance
87  };
88 
94 
102 
108 
110 
111 Q_SIGNALS:
118 
126  void GoToLabel(LabelValueType label, const mitk::Point3D& point) const;
127 
136  void LabelRenameRequested(mitk::Label* label, bool rename, bool& canceled) const;
137 
139  void ModelUpdated() const;
140 
142  void SegmentationChanged() const;
143 
144 public Q_SLOTS:
145 
152  void SetSelectedLabels(const LabelValueVectorType& selectedLabels);
160 
170 
183 
184  void SetMultiSelectionMode(bool multiMode);
185 
186  void SetAllowVisibilityModification(bool visiblityMod);
187  void SetAllowLockModification(bool lockMod);
188  void SetAllowLabelModification(bool labelMod);
189 
190  void SetDefaultLabelNaming(bool defaultLabelNaming);
191 
193 
206 
219  mitk::Label* AddNewLabel(bool skipNamingPrompt = false);
220 
227 
233  void DeleteLabel();
234 
239 
244  void RemoveGroup();
245 
252 
253  void SetVisibilityOfAffectedLabels(bool visible) const;
254  void SetLockOfAffectedLabels(bool visible) const;
255 
256 protected Q_SLOTS:
257  void OnModelReset();
259  void OnDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight,
260  const QList<int>& roles = QList<int>());
261 
262 protected:
263  void Initialize();
264 
266  mitk::MultiLabelSegmentation::Pointer m_Segmentation;
267 
269  QStyledItemDelegate* m_LockItemDelegate;
270  QStyledItemDelegate* m_ColorItemDelegate;
271  QStyledItemDelegate* m_VisibilityItemDelegate;
272 
273  std::unique_ptr<Ui::QmitkMultiLabelInspector> m_Controls;
274 
276  void UpdateSelectionModel(const LabelValueVectorType& selectedLabels);
277 
281 
283  bool skipNamingPrompt = false);
284 
288 
290  void DeleteLabelInternal(const LabelValueVectorType& labelValues);
291 
292  void keyPressEvent(QKeyEvent* event) override;
293  void keyReleaseEvent(QKeyEvent* event) override;
294 
295 private Q_SLOTS:
305  void OnChangeModelSelection(const QItemSelection& selected, const QItemSelection& deselected);
306 
307  void OnContextMenuRequested(const QPoint&);
308 
309  void OnAddLabel();
310  void OnAddLabelInstance();
311  void OnDeleteGroup();
312  void OnDeleteAffectedLabel();
313  void OnDeleteLabels(bool);
314  void OnClearLabels(bool);
315  void OnMergeLabels(bool);
316 
317  void OnRenameGroup();
318  void OnRenameLabel(bool);
319  void OnClearLabel(bool);
320 
321  void OnUnlockAffectedLabels();
322  void OnLockAffectedLabels();
323 
324  void OnSetAffectedLabelsVisible();
325  void OnSetAffectedLabelsInvisible();
326  void OnSetOnlyActiveLabelVisible(bool);
327 
328  void OnItemDoubleClicked(const QModelIndex& index);
329 
330  void WaitCursorOn() const;
331  void WaitCursorOff() const;
332  void RestoreOverrideCursor() const;
333 
334  void PrepareGoToLabel(LabelValueType labelID) const;
335 
336  void OnEntered(const QModelIndex& index);
337  void OnMouseLeave();
338 
339  void OnSearchLabel();
340  void RefreshCompleter();
341 
342  QWidgetAction* CreateOpacityAction();
343 
344 private:
345  bool m_ShowVisibility = true;
346  bool m_ShowLock = true;
347  bool m_ShowOther = false;
348 
353  bool m_AllowVisibilityModification = true;
354 
357  bool m_AllowLockModification = true;
358 
361  bool m_AllowLabelModification = false;
362 
363  bool m_DefaultLabelNaming = true;
364 
365  bool m_ModelManipulationOngoing = false;
366 
367  bool m_AboutToShowContextMenu = false;
368 
369  bool m_CheckSelectionDueToExternalModelChange = true;
370 
371  mitk::DataNode::Pointer m_SegmentationNode;
372  unsigned long m_SegmentationNodeDataMTime;
373  mitk::ITKEventObserverGuard m_SegmentationObserver;
374  mitk::LabelHighlightGuard m_LabelHighlightGuard;
375  mitk::LabelSuggestionHelper::ConstPointer m_SuggestionHelper;
376  mitk::ITKEventObserverGuard m_SuggestionObserver;
377 
378  QCompleter* m_Completer;
379 };
380 
381 #endif
#define MITKSEGMENTATIONUI_EXPORT
Inspector widget providing a tree view on labels and groups of a MultiLabelSegmentation instance.
mitk::Label * AddNewLabel(bool skipNamingPrompt=false)
Adds a new label to the segmentation. Depending on the settings the name of the label will be either ...
bool GetAllowLabelModification() const
Returns whether label modification (add/remove/rename) is allowed.
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.
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
Returns whether visibility modification is allowed.
const mitk::LabelSuggestionHelper * GetLabelSuggestionHelper() const
std::unique_ptr< Ui::QmitkMultiLabelInspector > m_Controls
QStyledItemDelegate * m_VisibilityItemDelegate
QmitkMultiLabelInspector(QWidget *parent=nullptr)
Constructs the multi-label inspector widget.
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 ...
mitk::Label * AddNewLabelInternal(const mitk::MultiLabelSegmentation::GroupIndexType &containingGroup, bool skipNamingPrompt=false)
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.
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
Returns whether multi-selection mode is enabled.
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
void SetDefaultLabelNaming(bool defaultLabelNaming)
bool GetAllowLockModification() const
Returns whether lock modification is allowed.
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
Tree model representing the information of an MITK MultiLabel segmentation instance (labels,...
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Convenience class that helps to manage the lifetime of itk event observers.
RAII guard for managing label highlighting on data nodes.
Helper class for handling label suggestions with constraint checking.
A data structure describing a label in a multi-label segmentation.
Definition: mitkLabel.h:101
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
std::vector< LabelValueType > LabelValueVectorType
mitk::Label::PixelType LabelValueType