Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
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>
19 #include <mitkLabelSetImage.h>
21 
22 #include <boost/variant.hpp>
23 
24 namespace mitk
25 {
26 
35  {
36  public:
38  itkFactorylessNewMacro(Self);
39  itkCloneMacro(Self);
40 
41  using HistogramType = itk::Statistics::Histogram<double>;
43 
45 
46  bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
47 
48  bool VerifyRequestedRegion() override { return true; }
49 
50  void SetRequestedRegion(const itk::DataObject*) override {}
51 
58  public:
60 
61  using RealType = double;
62  using IndexType = vnl_vector<int>;
63  using VoxelCountType = unsigned long;
64 
65  using StatisticsVariantType = boost::variant<RealType, VoxelCountType, IndexType >;
66 
71  void AddStatistic(const std::string_view key, StatisticsVariantType value);
72 
73  using StatisticNameVector = std::vector<std::string>;
74 
79  static const StatisticNameVector& GetDefaultStatisticNames();
80 
84  const StatisticNameVector& GetCustomStatisticNames() const;
85 
91 
92  StatisticNameVector GetExistingStatisticNames() const;
93 
94  bool HasStatistic(const std::string_view name) const;
95 
101  template <typename TType>
102  TType GetValueConverted(const std::string_view name) const
103  {
104  auto value = GetValueNonConverted(name);
105  return boost::get<TType>(value);
106  }
107 
112  StatisticsVariantType GetValueNonConverted(const std::string_view name) const;
113 
114  void Reset();
115 
116  HistogramType::ConstPointer m_Histogram=nullptr;
117  private:
118 
119  using StatisticsMapType = std::map < std::string, StatisticsVariantType, std::less<>>;
120 
121  StatisticsMapType m_Statistics;
122  StatisticNameVector m_CustomNames;
123  static const StatisticNameVector m_DefaultNames;
124  };
125 
130 
131  using TimeStepVectorType = std::vector<TimeStepType>;
132  TimeStepVectorType GetExistingTimeSteps(LabelValueType labelValue) const;
133 
135  static constexpr LabelValueType NO_MASK_LABEL_VALUE = Label::UNLABELED_VALUE;
137  LabelValueVectorType GetExistingLabelValues() const;
138 
141  void Reset();
142 
143  const ImageStatisticsObject& GetStatistics(LabelValueType labelValue, TimeStepType timeStep) const;
144 
149  void SetStatistics(LabelValueType labelValue, TimeStepType timeStep, const ImageStatisticsObject& statistics);
150 
155  bool StatisticsExist(LabelValueType labelValue, TimeStepType timeStep) const;
156 
160  const HistogramType* GetHistogram(LabelValueType labelValue, TimeStepType timeStep) const;
161 
162  bool IgnoresZeroVoxel() const;
163 
164  bool IsWIP() const;
165 
166  protected:
168  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
169 
170  private:
171  itk::LightObject::Pointer InternalClone() const override;
172 
173  using TimeStepMapType = std::map<TimeStepType, ImageStatisticsObject>;
174  using LabelMapType = std::map<LabelValueType, TimeStepMapType>;
175 
176  LabelMapType m_LabelTimeStep2StatisticsMap;
177  };
178 
181 }
182 #endif
mitk::ImageStatisticsContainer::TimeStepVectorType
std::vector< TimeStepType > TimeStepVectorType
Definition: mitkImageStatisticsContainer.h:131
mitk::ImageStatisticsContainer::ImageStatisticsObject::IndexType
vnl_vector< int > IndexType
Definition: mitkImageStatisticsContainer.h:62
mitk::ImageStatisticsContainer::ImageStatisticsObject::RealType
double RealType
Definition: mitkImageStatisticsContainer.h:61
mitk::ImageStatisticsContainer::IndexType
ImageStatisticsObject::IndexType IndexType
Definition: mitkImageStatisticsContainer.h:128
mitk::GetAllStatisticNames
MITKIMAGESTATISTICS_EXPORT ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector GetAllStatisticNames(const ImageStatisticsContainer *container)
mitk::ImageStatisticsContainer::ImageStatisticsObject::VoxelCountType
unsigned long VoxelCountType
Definition: mitkImageStatisticsContainer.h:63
mitk::ImageStatisticsContainer::VerifyRequestedRegion
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
Definition: mitkImageStatisticsContainer.h:48
mitk::ImageStatisticsContainer::VoxelCountType
ImageStatisticsObject::VoxelCountType VoxelCountType
Definition: mitkImageStatisticsContainer.h:129
mitk::ImageStatisticsContainer::RealType
ImageStatisticsObject::RealType RealType
Definition: mitkImageStatisticsContainer.h:127
mitk::ImageStatisticsContainer::LabelValueType
LabelSetImage::LabelValueType LabelValueType
Definition: mitkImageStatisticsContainer.h:42
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::ImageStatisticsContainer::SetRequestedRegionToLargestPossibleRegion
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
Definition: mitkImageStatisticsContainer.h:44
mitk::ImageStatisticsContainer
Container class for storing a StatisticsObject for each time step.
Definition: mitkImageStatisticsContainer.h:34
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:50
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::ImageStatisticsContainer::ImageStatisticsObject::GetValueConverted
TType GetValueConverted(const std::string_view name) const
Converts the requested value to the defined type.
Definition: mitkImageStatisticsContainer.h:102
mitk::ImageStatisticsContainer::ImageStatisticsObject
Container class for storing the computed image statistics.
Definition: mitkImageStatisticsContainer.h:57
mitk::Label::UNLABELED_VALUE
static constexpr PixelType UNLABELED_VALUE
Definition: mitkLabel.h:43
mitk::ImageStatisticsContainer::HistogramType
itk::Statistics::Histogram< double > HistogramType
Definition: mitkImageStatisticsContainer.h:41
mitk::TimeStepType
std::size_t TimeStepType
Definition: mitkTimeGeometry.h:27
mitk::ImageStatisticsContainer::StatisticsVariantType
ImageStatisticsObject::StatisticsVariantType StatisticsVariantType
Definition: mitkImageStatisticsContainer.h:126
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:46
mitk::ImageStatisticsContainer::LabelValueVectorType
LabelSetImage::LabelValueVectorType LabelValueVectorType
Definition: mitkImageStatisticsContainer.h:136
MitkImageStatisticsExports.h
mitk::ImageStatisticsContainer::ImageStatisticsObject::StatisticsVariantType
boost::variant< RealType, VoxelCountType, IndexType > StatisticsVariantType
Definition: mitkImageStatisticsContainer.h:65
mitk::ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector
std::vector< std::string > StatisticNameVector
Definition: mitkImageStatisticsContainer.h:73
mitk::LabelSetImage::LabelValueVectorType
std::vector< LabelValueType > LabelValueVectorType
Definition: mitkLabelSetImage.h:78
mitk::LabelSetImage::LabelValueType
mitk::Label::PixelType LabelValueType
Definition: mitkLabelSetImage.h:75
mitkLabelSetImage.h