Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkImageStatisticsTreeModel.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 QmitkImageStatisticsTreeModel_h
15 #define QmitkImageStatisticsTreeModel_h
16 
18 
19 //MITK
22 
23 #include <mutex>
24 
26 
43 {
44  Q_OBJECT
45 
46 public:
47 
52  QmitkImageStatisticsTreeModel(QObject *parent = nullptr);
53 
56 
65  void SetImageNodes(const std::vector<mitk::DataNode::ConstPointer>& nodes);
66 
75  void SetMaskNodes(const std::vector<mitk::DataNode::ConstPointer>& nodes);
76 
80  void Clear();
81 
89  void SetIgnoreZeroValueVoxel(bool _arg);
90 
96 
104  void SetHistogramNBins(unsigned int nbins);
105 
110  unsigned int GetHistogramNBins() const;
111 
117  Qt::ItemFlags flags(const QModelIndex &index) const override;
118 
129  QVariant data(const QModelIndex &index, int role) const override;
130 
142  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
143 
149  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
150 
156  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
157 
165  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
166 
172  QModelIndex parent(const QModelIndex &child) const override;
173 
174 signals:
179 
183  void modelChanged();
184 
185 protected:
186  /*
187  * @brief See 'QmitkAbstractDataStorageModel'
188  */
189  void DataStorageChanged() override;
190  /*
191  * @brief See 'QmitkAbstractDataStorageModel'
192  */
193  void NodePredicateChanged() override;
194  /*
195  * @brief See 'QmitkAbstractDataStorageModel'
196  */
197  void NodeAdded(const mitk::DataNode *node) override;
198  /*
199  * @brief See 'QmitkAbstractDataStorageModel'
200  */
201  void NodeChanged(const mitk::DataNode *node) override;
202  /*
203  * @brief See 'QmitkAbstractDataStorageModel'
204  */
205  void NodeRemoved(const mitk::DataNode *node) override;
206 
207 private:
208  void UpdateByDataStorage();
209 
210  using StatisticsContainerVector = std::vector<mitk::ImageStatisticsContainer::ConstPointer>;
211  /* builds a hierarchical tree model for the image statistics
212  1. Level: Image
213  --> 2. Level: Mask [if exist]
214  --> 3. Level: Label instances [if Mask has more then one label]
215  --> 4. Level: Timestep [if >1 exist] */
216  void BuildHierarchicalModel();
217 
218  StatisticsContainerVector m_Statistics;
219 
221  std::vector<mitk::DataNode::ConstPointer> m_ImageNodes;
227  std::vector<std::pair<mitk::DataNode::ConstPointer, unsigned int> > m_TimeStepResolvedImageNodes;
229  std::vector<mitk::DataNode::ConstPointer> m_MaskNodes;
231  std::vector<std::pair<mitk::DataNode::ConstPointer, unsigned int>> m_TimeStepResolvedMaskNodes;
232  std::vector<std::string> m_StatisticNames;
233 
234  std::mutex m_Mutex;
235  std::unique_ptr<QmitkImageStatisticsTreeItem> m_RootItem;
236  QVariant m_HeaderFirstColumn;
237  itk::TimeStamp m_BuildTime;
238 
239  bool m_IgnoreZeroValueVoxel = false;
240  unsigned int m_HistogramNBins = 100;
241 };
242 
243 #endif
#define MITKIMAGESTATISTICSUI_EXPORT
Abstract base class extending QAbstractItemModel for DataStorage-backed models.
An item that represents an entry (usually an ImageStatisticsObject) for the QmitkImageStatisticsTreeM...
Tree model that represents mitk::ImageStatisticsContainer data in the Qt model/view framework.
~QmitkImageStatisticsTreeModel() override
Destructor. Disconnects from the data storage.
void Clear()
Clears all image nodes, mask nodes, statistics, and resets the model.
Qt::ItemFlags flags(const QModelIndex &index) const override
Returns the item flags for the given model index.
void dataAvailable()
Emitted when new statistics data becomes available in the model.
QVariant data(const QModelIndex &index, int role) const override
Returns the data for the given index and role.
void NodeRemoved(const mitk::DataNode *node) override
void NodeAdded(const mitk::DataNode *node) override
void SetIgnoreZeroValueVoxel(bool _arg)
Sets whether zero-valued voxels should be ignored when selecting statistics.
QModelIndex parent(const QModelIndex &child) const override
Returns the parent model index of the given child.
unsigned int GetHistogramNBins() const
Returns the current number of histogram bins.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of columns (statistic names count + 1).
QmitkImageStatisticsTreeModel(QObject *parent=nullptr)
Constructs the tree model.
void SetMaskNodes(const std::vector< mitk::DataNode::ConstPointer > &nodes)
Sets the mask nodes whose statistics should be displayed.
bool GetIgnoreZeroValueVoxel() const
Returns whether zero-valued voxels are currently being ignored.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the header data for the given section and orientation.
void NodeChanged(const mitk::DataNode *node) override
void NodePredicateChanged() override
void SetImageNodes(const std::vector< mitk::DataNode::ConstPointer > &nodes)
Sets the image nodes whose statistics should be displayed.
void DataStorageChanged() override
void SetHistogramNBins(unsigned int nbins)
Sets the number of histogram bins used to select matching statistics.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of child rows under the given parent.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the model index for the specified row, column, and parent.
void modelChanged()
Emitted when the model rebuild is finished (usually shortly after dataAvailable()).
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72