Medical Imaging Interaction Toolkit  2021.10.00
Medical Imaging Interaction Toolkit
mitkImageStatisticsContainer.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 #ifndef MITKIMAGESTATISTICSCONTAINER
14 #define MITKIMAGESTATISTICSCONTAINER
15 
17 #include <mitkBaseData.h>
18 #include <itkHistogram.h>
20 
21 #include <boost/variant.hpp>
22 
23 namespace mitk
24 {
25 
34  {
35  public:
37  itkFactorylessNewMacro(Self);
38  itkCloneMacro(Self);
39 
40  using HistogramType = itk::Statistics::Histogram<double>;
41  using RealType = double;
42  using LabelIndex = unsigned int;
43  using IndexType = vnl_vector<int>;
44  using VoxelCountType = unsigned long;
45  using StatisticsVariantType = boost::variant<RealType, VoxelCountType, IndexType >;
46  using StatisticsMapType = std::map < std::string, StatisticsVariantType>;
47  using StatisticsKeyType = std::string;
48 
50 
51  bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
52 
53  bool VerifyRequestedRegion() override { return true; }
54 
55  void SetRequestedRegion(const itk::DataObject*) override {}
56 
63  public:
69  void AddStatistic(const std::string& key, StatisticsVariantType value);
70 
71  using StatisticNameVector = std::vector<std::string>;
72 
77  static const StatisticNameVector& GetDefaultStatisticNames();
78 
82  const StatisticNameVector& GetCustomStatisticNames() const;
83 
89 
90  StatisticNameVector GetExistingStatisticNames() const;
91 
92  bool HasStatistic(const std::string& name) const;
93 
99  template <typename TType>
100  TType GetValueConverted(const std::string& name) const
101  {
102  auto value = GetValueNonConverted(name);
103  return boost::get<TType>(value);
104  }
105 
110  StatisticsVariantType GetValueNonConverted(const std::string& name) const;
111 
112  void Reset();
113 
114  HistogramType::ConstPointer m_Histogram=nullptr;
115  private:
116  StatisticsMapType m_Statistics;
117  StatisticNameVector m_CustomNames;
118  static const StatisticNameVector m_DefaultNames;
119  };
120 
121  using TimeStepMapType = std::map<TimeStepType, ImageStatisticsObject>;
122 
123  unsigned int GetNumberOfTimeSteps() const;
124 
127  void Reset();
128 
133  const ImageStatisticsObject& GetStatisticsForTimeStep(TimeStepType timeStep) const;
134 
139  void SetStatisticsForTimeStep(TimeStepType timeStep, ImageStatisticsObject statistics);
140 
145  bool TimeStepExists(TimeStepType timeStep) const;
146 
150  const HistogramType* GetHistogramForTimeStep(TimeStepType timeStep) const;
151 
152  protected:
154  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
155 
156  private:
157  itk::LightObject::Pointer InternalClone() const override;
158 
159  void SetTimeStepMap(TimeStepMapType map);
160 
161  TimeStepMapType m_TimeStepMap;
162  };
163 
166 }
167 #endif // MITKIMAGESTATISTICSCONTAINER
std::map< std::string, StatisticsVariantType > StatisticsMapType
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
Base of all data objects.
Definition: mitkBaseData.h:42
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
DataCollection - Class to facilitate loading/accessing structured data.
TType GetValueConverted(const std::string &name) const
Converts the requested value to the defined type.
#define MITKIMAGESTATISTICS_EXPORT
itk::Statistics::Histogram< double > HistogramType
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
MITKIMAGESTATISTICS_EXPORT ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector GetAllStatisticNames(const ImageStatisticsContainer *container)
std::vcl_size_t TimeStepType
void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
boost::variant< RealType, VoxelCountType, IndexType > StatisticsVariantType
Container class for storing the computed image statistics.
Container class for storing a StatisticsObject for each timestep.
std::map< TimeStepType, ImageStatisticsObject > TimeStepMapType