Medical Imaging Interaction Toolkit  2026.06.00
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 
31 class MITKSEGMENTATIONUI_EXPORT QmitkMultiLabelTreeModel : public QAbstractItemModel
32 {
33  Q_OBJECT
34 
35 public:
38 
40  QmitkMultiLabelTreeModel(QObject *parent = nullptr);
42 
47 
48  Qt::ItemFlags flags(const QModelIndex &index) const override;
49  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
50  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
51 
52  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
53  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
54  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
55 
56  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
57  QModelIndex parent(const QModelIndex &child) const override;
58 
61  QModelIndex indexOfLabel(mitk::Label::PixelType labelValue) const;
66  QModelIndex FirstLabelInstanceIndex(const QModelIndex& currentIndex) const;
67 
69  //or instance node). If current index is at the end, an invalid index is returned.*/
70  //QModelIndex PrevLabelInstanceIndex(const QModelIndex& currentIndex) const;
71 
73  std::vector <LabelValueType> GetLabelsInSubTree(const QModelIndex& currentIndex) const;
74 
81  std::vector <LabelValueType> GetLabelInstancesOfSameLabelClass(const QModelIndex& currentIndex) const;
82 
84  {
85  NAME_COL = 0,
88  VISIBLE_COL
89  };
90 
92  {
97  LabelDataRole = 64,
100  LabelValueRole = 65,
105  LabelInstanceDataRole = 66,
111  LabelInstanceValueRole = 67,
113  GroupIDRole = 68
114  };
115 
118  bool GetModelUpdateOngoing() const;
122 
123 public Q_SLOTS:
125  void SetAllowLockModification(bool lmod);
126 
127 Q_SIGNALS:
130  void modelChanged();
131 
132 protected:
133  void ITKEventHandler(const itk::EventObject& e);
134 
135  void OnLabelAdded(LabelValueType labelValue);
136  void OnLabelModified(LabelValueType labelValue);
137  void OnLabelRemoved(LabelValueType labelValue);
138  void OnGroupAdded(GroupIndexType groupIndex);
139  void OnGroupModified(GroupIndexType groupIndex);
140  void OnGroupRemoved(GroupIndexType groupIndex);
141 
142 private:
143  void AddObserver();
144 
145  void UpdateInternalTree();
146  void GenerateInternalGroupTree(unsigned int layerID, QmitkMultiLabelSegTreeItem* layerItem);
147  QmitkMultiLabelSegTreeItem* GenerateInternalTree();
150  const QmitkMultiLabelSegTreeItem* ClosestLabelInstanceIndex(const QmitkMultiLabelSegTreeItem* currentItem) const;
151 
152  mitk::MultiLabelSegmentation::Pointer m_Segmentation;
153 
154  std::mutex m_Mutex;
155  std::unique_ptr<QmitkMultiLabelSegTreeItem> m_RootItem;
156 
157  bool m_ShowGroups = true;
158 
159  bool m_ShowVisibility = true;
160  bool m_ShowLock = true;
161  bool m_ShowOther = false;
162 
163  bool m_AllowVisibilityModification = true;
164  bool m_AllowLockModification = true;
165  bool m_ModelUpdateOngoing = false;
166 
167  mitk::MultiLabelSegmentation::LabelValueType m_NearestLabelValueToLastChange;
168 
169  mitk::ITKEventObserverGuard m_LabelAddedObserver;
170  mitk::ITKEventObserverGuard m_LabelModifiedObserver;
171  mitk::ITKEventObserverGuard m_LabelRemovedObserver;
172  mitk::ITKEventObserverGuard m_GroupAddedObserver;
173  mitk::ITKEventObserverGuard m_GroupModifiedObserver;
174  mitk::ITKEventObserverGuard m_GroupRemovedObserver;
175 };
176 
177 #endif
#define MITKSEGMENTATIONUI_EXPORT
Tree model representing the information of an MITK MultiLabel segmentation instance (labels,...
Qt::ItemFlags flags(const QModelIndex &index) const override
~QmitkMultiLabelTreeModel() override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
void OnGroupAdded(GroupIndexType groupIndex)
void ITKEventHandler(const itk::EventObject &e)
LabelValueType GetNearestLabelValueToLastChange() const
mitk::MultiLabelSegmentation::LabelValueType LabelValueType
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void SetSegmentation(mitk::MultiLabelSegmentation *segmentation)
Sets the segmentation whose labels and groups are represented by this model.
void OnLabelRemoved(LabelValueType labelValue)
mitk::MultiLabelSegmentation::GroupIndexType GroupIndexType
QModelIndex indexOfGroup(mitk::MultiLabelSegmentation::GroupIndexType groupIndex) const
std::vector< LabelValueType > GetLabelsInSubTree(const QModelIndex &currentIndex) const
‍** Returns the index to the next node in the tree that behaves like an instance (label node with onl...
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent(const QModelIndex &child) const override
QModelIndex indexOfLabel(mitk::Label::PixelType labelValue) const
bool GetAllowLockModification() const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void OnLabelAdded(LabelValueType labelValue)
QModelIndex FirstLabelInstanceIndex(const QModelIndex &currentIndex) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
std::vector< LabelValueType > GetLabelInstancesOfSameLabelClass(const QModelIndex &currentIndex) const
void OnLabelModified(LabelValueType labelValue)
void SetAllowVisibilityModification(bool vmod)
bool GetModelUpdateOngoing() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void OnGroupRemoved(GroupIndexType groupIndex)
void SetAllowLockModification(bool lmod)
bool GetAllowVisibilityModification() const
void OnGroupModified(GroupIndexType groupIndex)
const mitk::MultiLabelSegmentation * GetSegmentation() const
Returns the segmentation represented by this model.
QmitkMultiLabelTreeModel(QObject *parent=nullptr)
Constructs the tree model.
Convenience class that helps to manage the lifetime of itk event observers.
unsigned short PixelType
Pixel type used for label values (unsigned short).
Definition: mitkLabel.h:106
MultiLabelSegmentation class for handling labels and layers in a segmentation session.
mitk::Label::PixelType LabelValueType