Medical Imaging Interaction Toolkit  2024.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 
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::LabelSetImage* segmentation);
44  const mitk::LabelSetImage* 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::LabelSetImage::GroupIndexType groupIndex) const;
63  QModelIndex ClosestLabelInstanceIndex(const QModelIndex& currentIndex) const;
67  QModelIndex FirstLabelInstanceIndex(const QModelIndex& currentIndex) const;
68 
70  //or instance node). If current index is at the end, an invalid index is returned.*/
71  //QModelIndex PrevLabelInstanceIndex(const QModelIndex& currentIndex) const;
72 
74  std::vector <LabelValueType> GetLabelsInSubTree(const QModelIndex& currentIndex) const;
75 
82  std::vector <LabelValueType> GetLabelInstancesOfSameLabelClass(const QModelIndex& currentIndex) const;
83 
85  {
86  NAME_COL = 0,
89  VISIBLE_COL
90  };
91 
93  {
98  LabelDataRole = 64,
101  LabelValueRole = 65,
106  LabelInstanceDataRole = 66,
112  LabelInstanceValueRole = 67,
114  GroupIDRole = 68
115  };
116 
117  bool GetAllowVisibilityModification() const;
118  bool GetAllowLockModification() const;
119 
120 public Q_SLOTS:
121  void SetAllowVisibilityModification(bool vmod);
122  void SetAllowLockModification(bool lmod);
123 
124 Q_SIGNALS:
125  void dataAvailable();
127  void modelChanged();
128 
129 protected:
130  void ITKEventHandler(const itk::EventObject& e);
131 
132  void OnLabelAdded(LabelValueType labelValue);
133  void OnLabelModified(LabelValueType labelValue);
134  void OnLabelRemoved(LabelValueType labelValue);
135  void OnGroupAdded(GroupIndexType groupIndex);
136  void OnGroupModified(GroupIndexType groupIndex);
137  void OnGroupRemoved(GroupIndexType groupIndex);
138 
139 private:
140  void AddObserver();
141 
142  void UpdateInternalTree();
143  void GenerateInternalGroupTree(unsigned int layerID, QmitkMultiLabelSegTreeItem* layerItem);
144  QmitkMultiLabelSegTreeItem* GenerateInternalTree();
145 
146  mitk::LabelSetImage::Pointer m_Segmentation;
147 
148  std::mutex m_Mutex;
149  std::unique_ptr<QmitkMultiLabelSegTreeItem> m_RootItem;
150 
151  bool m_ShowGroups = true;
152 
153  bool m_ShowVisibility = true;
154  bool m_ShowLock = true;
155  bool m_ShowOther = false;
156 
157  bool m_AllowVisibilityModification = true;
158  bool m_AllowLockModification = true;
159 
160  mitk::ITKEventObserverGuard m_LabelAddedObserver;
161  mitk::ITKEventObserverGuard m_LabelModifiedObserver;
162  mitk::ITKEventObserverGuard m_LabelRemovedObserver;
163  mitk::ITKEventObserverGuard m_GroupAddedObserver;
164  mitk::ITKEventObserverGuard m_GroupModifiedObserver;
165  mitk::ITKEventObserverGuard m_GroupRemovedObserver;
166 };
167 
168 #endif
QmitkMultiLabelTreeModel::LabelValueType
mitk::LabelSetImage::LabelValueType LabelValueType
Definition: QmitkMultiLabelTreeModel.h:37
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelTreeModel::TableColumns
TableColumns
Definition: QmitkMultiLabelTreeModel.h:84
QmitkMultiLabelTreeModel::GroupIndexType
mitk::LabelSetImage::GroupIndexType GroupIndexType
Definition: QmitkMultiLabelTreeModel.h:38
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:88
QmitkMultiLabelTreeModel
Definition: QmitkMultiLabelTreeModel.h:32
itk::SmartPointer< Self >
mitk::Label::PixelType
unsigned short PixelType
Definition: mitkLabel.h:34
MitkSegmentationUIExports.h
QmitkMultiLabelTreeModel::ItemModelRole
ItemModelRole
Definition: QmitkMultiLabelTreeModel.h:92
QmitkMultiLabelTreeModel::LOCKED_COL
@ LOCKED_COL
Definition: QmitkMultiLabelTreeModel.h:87
mitkITKEventObserverGuard.h
mitk::LabelSetImage::GroupIndexType
std::size_t GroupIndexType
Definition: mitkLabelSetImage.h:74
mitk::LabelSetImage
LabelSetImage class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:43
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:75
mitkLabelSetImage.h