Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 {
33  {
34  public:
36  itkFactorylessNewMacro(Self);
37  itkCloneMacro(Self);
38 
39  using HistogramType = itk::Statistics::Histogram<double>;
40  using RealType = double;
41  using LabelIndex = unsigned int;
42  using IndexType = vnl_vector<int>;
43  using VoxelCountType = unsigned long;
44  using StatisticsVariantType = boost::variant<RealType, VoxelCountType, IndexType >;
45  using StatisticsMapType = std::map < std::string, StatisticsVariantType>;
46  using StatisticsKeyType = std::string;
47 
49 
50  bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
51 
52  bool VerifyRequestedRegion() override { return true; }
53 
54  void SetRequestedRegion(const itk::DataObject*) override {}
55 
62  public:
68  void AddStatistic(const std::string& key, StatisticsVariantType value);
69 
70  using StatisticNameVector = std::vector<std::string>;
71 
76  static const StatisticNameVector& GetDefaultStatisticNames();
77 
81  const StatisticNameVector& GetCustomStatisticNames() const;
82 
88 
89  StatisticNameVector GetExistingStatisticNames() const;
90 
91  bool HasStatistic(const std::string& name) const;
92 
98  template <typename TType>
99  TType GetValueConverted(const std::string& name) const
100  {
101  auto value = GetValueNonConverted(name);
102  return boost::get<TType>(value);
103  }
104 
109  StatisticsVariantType GetValueNonConverted(const std::string& name) const;
110 
111  void Reset();
112 
113  HistogramType::ConstPointer m_Histogram=nullptr;
114  private:
115  StatisticsMapType m_Statistics;
116  StatisticNameVector m_CustomNames;
117  static const StatisticNameVector m_DefaultNames;
118  };
119 
120  using TimeStepMapType = std::map<TimeStepType, ImageStatisticsObject>;
121 
122  unsigned int GetNumberOfTimeSteps() const;
123 
126  void Reset();
127 
132  const ImageStatisticsObject& GetStatisticsForTimeStep(TimeStepType timeStep) const;
133 
138  void SetStatisticsForTimeStep(TimeStepType timeStep, ImageStatisticsObject statistics);
139 
144  bool TimeStepExists(TimeStepType timeStep) const;
145 
146  protected:
148  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
149 
150  private:
151  itk::LightObject::Pointer InternalClone() const override;
152 
153  void SetTimeStepMap(TimeStepMapType map);
154 
155  TimeStepMapType m_TimeStepMap;
156  };
157 
160 
161 }
162 #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:37
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:40
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