Medical Imaging Interaction Toolkit  2018.4.99-1640525a
Medical Imaging Interaction Toolkit
QmitkImageStatisticsTreeItem.cpp
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 
14 
16  ImageStatisticsObject statisticsData,
17  StatisticNameVector statisticNames,
18  QVariant label, bool isWIP,
20  : m_statistics(statisticsData) , m_statisticNames(statisticNames), m_label(label), m_parentItem(parent), m_IsWIP(isWIP)
21 {
22 }
23 
25  QVariant label,
26  bool isWIP,
28  : QmitkImageStatisticsTreeItem(ImageStatisticsObject(), statisticNames, label, isWIP, parentItem )
29 {
30 }
31 
33 
35 {
36  qDeleteAll(m_childItems);
37 }
38 
40 {
41  m_childItems.append(item);
42 }
43 
45 {
46  return m_childItems.value(row);
47 }
48 
50 {
51  return m_childItems.count();
52 }
53 
55 {
56  return m_statisticNames.size() + 1;
57 }
58 
59 struct StatValueVisitor : boost::static_visitor<QVariant>
60 {
61  QVariant operator()(const mitk::ImageStatisticsContainer::RealType& val) const
62  {
63  return QVariant(val);
64  }
65 
66  QVariant operator()(const mitk::ImageStatisticsContainer::VoxelCountType& val) const
67  {
68  return QVariant::fromValue<mitk::ImageStatisticsContainer::VoxelCountType>(val);
69  }
70 
71  QVariant operator()(const mitk::ImageStatisticsContainer::IndexType& val) const
72  {
73  std::stringstream ss;
74  ss << val;
75  return QVariant(QString::fromStdString(ss.str()));
76  }
77 
78 };
79 
80 QVariant QmitkImageStatisticsTreeItem::data(int column) const
81 {
82  QVariant result;
83  if (column > 0 && !m_statisticNames.empty())
84  {
85  if (column - 1 < static_cast<int>(m_statisticNames.size()))
86  {
87  if (m_IsWIP)
88  {
89  result = QVariant(QString("..."));
90  }
91  else
92  {
93  auto statisticKey = m_statisticNames.at(column - 1);
94  if (m_statistics.HasStatistic(statisticKey))
95  {
96  return boost::apply_visitor(StatValueVisitor(), m_statistics.GetValueNonConverted(statisticKey));
97  }
98  else
99  {
100  return QVariant();
101  }
102  }
103  }
104  else
105  {
106  return QVariant();
107  }
108  }
109  else if (column == 0)
110  {
111  result = m_label;
112  }
113  return result;
114 }
115 
117 {
118  return m_parentItem;
119 }
120 
122 {
123  if (m_parentItem)
124  return m_parentItem->m_childItems.indexOf(const_cast<QmitkImageStatisticsTreeItem *>(this));
125 
126  return 0;
127 }
128 
130 {
131  return m_IsWIP;
132 }
QmitkImageStatisticsTreeItem * parentItem()
QmitkImageStatisticsTreeItem * child(int row)
void appendChild(QmitkImageStatisticsTreeItem *child)
mitk::ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector StatisticNameVector
Container class for storing the computed image statistics.