Medical Imaging Interaction Toolkit  2023.12.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"
18 
19 // qt
20 #include <QAbstractItemModel>
21 
23 
24 
25 class QmitkMultiLabelSegTreeItem;
26 
31 class MITKSEGMENTATIONUI_EXPORT QmitkMultiLabelTreeModel : public QAbstractItemModel
32 {
33  Q_OBJECT
34 
35 public:
38 
39  QmitkMultiLabelTreeModel(QObject *parent = nullptr);
40  ~QmitkMultiLabelTreeModel() override;
41 
42  void SetSegmentation(mitk::LabelSetImage* segmentation);
43  const mitk::LabelSetImage* GetSegmentation() const;
44 
45  Qt::ItemFlags flags(const QModelIndex &index) const override;
46  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
47  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
48 
49  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
50  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
51  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
52 
53  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
54  QModelIndex parent(const QModelIndex &child) const override;
55 
58  QModelIndex indexOfLabel(mitk::Label::PixelType labelValue) const;
59  QModelIndex indexOfGroup(mitk::LabelSetImage::GroupIndexType groupIndex) const;
62  QModelIndex ClosestLabelInstanceIndex(const QModelIndex& currentIndex) 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 
116  bool GetAllowVisibilityModification() const;
117  bool GetAllowLockModification() const;
118 
119 public Q_SLOTS:
120  void SetAllowVisibilityModification(bool vmod);
121  void SetAllowLockModification(bool lmod);
122 
123 Q_SIGNALS:
124  void dataAvailable();
126  void modelChanged();
127 
128 protected:
129  void OnLabelAdded(LabelValueType labelValue);
130  void OnLabelModified(LabelValueType labelValue);
131  void OnLabelRemoved(LabelValueType labelValue);
132  void OnGroupAdded(GroupIndexType groupIndex);
133  void OnGroupModified(GroupIndexType groupIndex);
134  void OnGroupRemoved(GroupIndexType groupIndex);
135 
136 private:
137  void AddObserver();
138  void RemoveObserver();
139 
140  void UpdateInternalTree();
141  void GenerateInternalGroupTree(unsigned int layerID, QmitkMultiLabelSegTreeItem* layerItem);
142  QmitkMultiLabelSegTreeItem* GenerateInternalTree();
143 
144  /* builds a hierarchical tree model for the image statistics
145  1. Level: Image
146  --> 2. Level: Mask [if exist]
147  --> 3. Level: Timestep [if >1 exist] */
148  void BuildHierarchicalModel();
149 
150  mitk::LabelSetImage::Pointer m_Segmentation;
151 
152  std::mutex m_Mutex;
153  std::unique_ptr<QmitkMultiLabelSegTreeItem> m_RootItem;
154 
155  bool m_Observed;
156  bool m_ShowGroups = true;
157 
158  bool m_ShowVisibility = true;
159  bool m_ShowLock = true;
160  bool m_ShowOther = false;
161 
162  bool m_AllowVisibilityModification = true;
163  bool m_AllowLockModification = true;
164 };
165 
166 #endif
QmitkMultiLabelTreeModel::LabelValueType
mitk::LabelSetImage::LabelValueType LabelValueType
Definition: QmitkMultiLabelTreeModel.h:36
MITKSEGMENTATIONUI_EXPORT
#define MITKSEGMENTATIONUI_EXPORT
Definition: MitkSegmentationUIExports.h:15
QmitkMultiLabelTreeModel::TableColumns
TableColumns
Definition: QmitkMultiLabelTreeModel.h:83
QmitkMultiLabelTreeModel::GroupIndexType
mitk::LabelSetImage::GroupIndexType GroupIndexType
Definition: QmitkMultiLabelTreeModel.h:37
QmitkMultiLabelTreeModel::COLOR_COL
@ COLOR_COL
Definition: QmitkMultiLabelTreeModel.h:87
QmitkMultiLabelTreeModel
Definition: QmitkMultiLabelTreeModel.h:31
itk::SmartPointer< Self >
mitk::Label::PixelType
unsigned short PixelType
Definition: mitkLabel.h:34
MitkSegmentationUIExports.h
QmitkMultiLabelTreeModel::ItemModelRole
ItemModelRole
Definition: QmitkMultiLabelTreeModel.h:91
QmitkMultiLabelTreeModel::LOCKED_COL
@ LOCKED_COL
Definition: QmitkMultiLabelTreeModel.h:86
mitk::LabelSetImage::GroupIndexType
std::size_t GroupIndexType
Definition: mitkLabelSetImage.h:61
mitk::LabelSetImage
LabelSetImage class for handling labels and layers in a segmentation session.
Definition: mitkLabelSetImage.h:29
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:62
mitkLabelSetImage.h