Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
Medical Imaging Interaction Toolkit
QmitkMultiLabelTreeModel.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 
14 #ifndef QmitkMultiLabelTreeModel_h
15 #define QmitkMultiLabelTreeModel_h
16 
17 #include "mitkLabelSetImage.h"
19 
20 // qt
21 #include <QAbstractItemModel>
22 
24 
25 
26 class QmitkMultiLabelSegTreeItem;
27 
32 class MITKSEGMENTATIONUI_EXPORT QmitkMultiLabelTreeModel : public QAbstractItemModel
33 {
34  Q_OBJECT
35 
36 public:
39 
40  QmitkMultiLabelTreeModel(QObject *parent = nullptr);
41  ~QmitkMultiLabelTreeModel() override;
42 
43  void SetSegmentation(mitk::MultiLabelSegmentation* segmentation);
44  const mitk::MultiLabelSegmentation* GetSegmentation() const;
45 
46  Qt::ItemFlags flags(const QModelIndex &index) const override;
47  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
48  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
49 
50  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
51  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
52  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
53 
54  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
55  QModelIndex parent(const QModelIndex &child) const override;
56 
59  QModelIndex indexOfLabel(mitk::Label::PixelType labelValue) const;
60  QModelIndex indexOfGroup(mitk::MultiLabelSegmentation::GroupIndexType groupIndex) const;
64  QModelIndex FirstLabelInstanceIndex(const QModelIndex& currentIndex) const;
65 
67  //or instance node). If current index is at the end, an invalid index is returned.*/
68  //QModelIndex PrevLabelInstanceIndex(const QModelIndex& currentIndex) const;
69 
71  std::vector <LabelValueType> GetLabelsInSubTree(const QModelIndex& currentIndex) const;
72 
79  std::vector <LabelValueType> GetLabelInstancesOfSameLabelClass(const QModelIndex& currentIndex) const;
80 
82  {
83  NAME_COL = 0,
86  VISIBLE_COL
87  };
88 
90  {
95  LabelDataRole = 64,
98  LabelValueRole = 65,
103  LabelInstanceDataRole = 66,
109  LabelInstanceValueRole = 67,
111  GroupIDRole = 68
112  };
113 
114  bool GetAllowVisibilityModification() const;
115  bool GetAllowLockModification() const;
116  bool GetModelUpdateOngoing() const;
119  LabelValueType GetNearestLabelValueToLastChange() const;
120 
121 public Q_SLOTS:
122  void SetAllowVisibilityModification(bool vmod);
123  void SetAllowLockModification(bool lmod);
124 
125 Q_SIGNALS:
126  void dataAvailable();
128  void modelChanged();
129 
130 protected:
131  void ITKEventHandler(const itk::EventObject& e);
132 
133  void OnLabelAdded(LabelValueType labelValue);
134  void OnLabelModified(LabelValueType labelValue);
135  void OnLabelRemoved(LabelValueType labelValue);
136  void OnGroupAdded(GroupIndexType groupIndex);
137  void OnGroupModified(GroupIndexType groupIndex);
138  void OnGroupRemoved(GroupIndexType groupIndex);
139 
140 private:
141  void AddObserver();
142 
143  void UpdateInternalTree();
144  void GenerateInternalGroupTree(unsigned int layerID, QmitkMultiLabelSegTreeItem* layerItem);
145  QmitkMultiLabelSegTreeItem* GenerateInternalTree();
148  const QmitkMultiLabelSegTreeItem* ClosestLabelInstanceIndex(const QmitkMultiLabelSegTreeItem* currentItem) const;
149 
151 
152  std::mutex m_Mutex;
153  std::unique_ptr<QmitkMultiLabelSegTreeItem> m_RootItem;
154 
155  bool m_ShowGroups = true;
156 
157  bool m_ShowVisibility = true;
158  bool m_ShowLock = true;
159  bool m_ShowOther = false;
160 
161  bool m_AllowVisibilityModification = true;
162  bool m_AllowLockModification = true;
163  bool m_ModelUpdateOngoing = false;
164 
165  mitk::MultiLabelSegmentation::LabelValueType m_NearestLabelValueToLastChange;
166 
167  mitk::ITKEventObserverGuard m_LabelAddedObserver;
168  mitk::ITKEventObserverGuard m_LabelModifiedObserver;
169  mitk::ITKEventObserverGuard m_LabelRemovedObserver;
170  mitk::ITKEventObserverGuard m_GroupAddedObserver;
171  mitk::ITKEventObserverGuard m_GroupModifiedObserver;
172  mitk::ITKEventObserverGuard m_GroupRemovedObserver;
173 };
174 
175 #endif
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelTreeModel::TableColumns
TableColumns
Definition: QmitkMultiLabelTreeModel.h:81
mitk::ITKEventObserverGuard
Convenience class that helps to manage the lifetime of itk event observers.
Definition: mitkITKEventObserverGuard.h:55
QmitkMultiLabelTreeModel::COLOR_COL
@ COLOR_COL
Definition: QmitkMultiLabelTreeModel.h:85
QmitkMultiLabelTreeModel
Definition: QmitkMultiLabelTreeModel.h:32
itk::SmartPointer< Self >
mitk::MultiLabelSegmentation::GroupIndexType
std::size_t GroupIndexType
Definition: mitkLabelSetImage.h:56
mitk::Label::PixelType
unsigned short PixelType
Definition: mitkLabel.h:34
mitk::MultiLabelSegmentation::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:57
QmitkMultiLabelTreeModel::GroupIndexType
mitk::MultiLabelSegmentation::GroupIndexType GroupIndexType
Definition: QmitkMultiLabelTreeModel.h:38
mitk::MultiLabelSegmentation
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
QmitkMultiLabelTreeModel::LabelValueType
mitk::MultiLabelSegmentation::LabelValueType LabelValueType
Definition: QmitkMultiLabelTreeModel.h:37
MitkSegmentationUIExports.h
QmitkMultiLabelTreeModel::ItemModelRole
ItemModelRole
Definition: QmitkMultiLabelTreeModel.h:89
QmitkMultiLabelTreeModel::LOCKED_COL
@ LOCKED_COL
Definition: QmitkMultiLabelTreeModel.h:84
mitkITKEventObserverGuard.h
mitkLabelSetImage.h