Medical Imaging Interaction Toolkit  2023.04.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_h
14 #define mitkImageStatisticsContainer_h
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
mitk::ImageStatisticsContainer::RealType
double RealType
Definition: mitkImageStatisticsContainer.h:41
mitk::GetAllStatisticNames
MITKIMAGESTATISTICS_EXPORT ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector GetAllStatisticNames(const ImageStatisticsContainer *container)
mitk::ImageStatisticsContainer::VerifyRequestedRegion
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
Definition: mitkImageStatisticsContainer.h:53
mitk::ImageStatisticsContainer::StatisticsMapType
std::map< std::string, StatisticsVariantType > StatisticsMapType
Definition: mitkImageStatisticsContainer.h:46
mitk::ImageStatisticsContainer::ImageStatisticsObject::GetValueConverted
TType GetValueConverted(const std::string &name) const
Converts the requested value to the defined type.
Definition: mitkImageStatisticsContainer.h:100
mitk::ImageStatisticsContainer::IndexType
vnl_vector< int > IndexType
Definition: mitkImageStatisticsContainer.h:43
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::ImageStatisticsContainer::SetRequestedRegionToLargestPossibleRegion
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
Definition: mitkImageStatisticsContainer.h:49
mitk::ImageStatisticsContainer
Container class for storing a StatisticsObject for each timestep.
Definition: mitkImageStatisticsContainer.h:33
mitk::ImageStatisticsContainer::LabelIndex
unsigned int LabelIndex
Definition: mitkImageStatisticsContainer.h:42
MITKIMAGESTATISTICS_EXPORT
#define MITKIMAGESTATISTICS_EXPORT
Definition: MitkImageStatisticsExports.h:15
mitk::ImageStatisticsContainer::SetRequestedRegion
void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
Definition: mitkImageStatisticsContainer.h:55
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::ImageStatisticsContainer::StatisticsKeyType
std::string StatisticsKeyType
Definition: mitkImageStatisticsContainer.h:47
mitk::ImageStatisticsContainer::ImageStatisticsObject
Container class for storing the computed image statistics.
Definition: mitkImageStatisticsContainer.h:62
mitk::ImageStatisticsContainer::TimeStepMapType
std::map< TimeStepType, ImageStatisticsObject > TimeStepMapType
Definition: mitkImageStatisticsContainer.h:121
mitk::ImageStatisticsContainer::HistogramType
itk::Statistics::Histogram< double > HistogramType
Definition: mitkImageStatisticsContainer.h:40
map
Definition: mitkFastSymmetricForcesDemonsMultiResDefaultRegistrationAlgorithm_ProfileResource.h:26
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitkBaseData.h
mitkImageStatisticsConstants.h
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::ImageStatisticsContainer::RequestedRegionIsOutsideOfTheBufferedRegion
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
Definition: mitkImageStatisticsContainer.h:51
MitkImageStatisticsExports.h
mitk::ImageStatisticsContainer::StatisticsVariantType
boost::variant< RealType, VoxelCountType, IndexType > StatisticsVariantType
Definition: mitkImageStatisticsContainer.h:45
mitk::ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector
std::vector< std::string > StatisticNameVector
Definition: mitkImageStatisticsContainer.h:71
mitk::ImageStatisticsContainer::VoxelCountType
unsigned long VoxelCountType
Definition: mitkImageStatisticsContainer.h:44