Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkSimpleHistogram.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 mitkSimpleHistogram_h
14 #define mitkSimpleHistogram_h
15 
16 #ifndef __itkHistogram_h
17 #include <itkHistogram.h>
18 #endif
19 
21 
22 #include <mitkImage.h>
23 #include <mitkWeakPointer.h>
24 
25 #include <itkImageRegionIterator.h>
26 #include <itkImageRegionIteratorWithIndex.h>
27 
28 namespace mitk
29 {
30  //##Documentation
31  //## @brief Abstract superclass for histograms with double values.
32  //## Classes which are deriving from this class can be cached
33  //## in the same way.
35  {
36  public:
38  virtual double GetMin() const = 0;
40  virtual double GetMax() const = 0;
42  virtual void ComputeFromBaseData(BaseData *source) = 0;
44  virtual float GetRelativeBin(double start, double end) const = 0;
45  };
46 
48  {
49  public:
50  typedef itk::Statistics::Histogram<double> HistogramType;
51 
53  {
54  valid = false;
55  }
56 
58  {
59  }
60 
62  bool GetValid();
63 
64  typedef itk::Image<short, 3> CTImage;
65  typedef itk::ImageRegionIterator<CTImage> CTIteratorType;
66  typedef itk::ImageRegionIteratorWithIndex<CTImage> CTIteratorIndexType;
67 
68  typedef itk::Image<unsigned char, 3> BinImage;
69  typedef itk::ImageRegionIterator<BinImage> BinIteratorType;
70  typedef itk::ImageRegionIteratorWithIndex<BinImage> BinIteratorIndexType;
71 
72  typedef unsigned long CountType;
73 
74  protected:
75  HistogramType::ConstPointer histogram;
76 
77  bool valid;
78  unsigned int nBins = 256;
79  double invLogHighest;
80 
81  public:
82  double GetMin() const override;
83  double GetMax() const override;
84 
87  void ComputeFromBaseData(BaseData *source) override;
88  float GetRelativeBin(double start, double end) const override;
89  };
90 
92  {
93  public:
94  static const unsigned int maxCacheSize = 64;
95 
97  {
98  public:
100  itk::TimeStamp m_LastUpdateTime;
101 
102  virtual ~Element();
103 
104  virtual void ComputeFromBaseData(BaseData *baseData) = 0;
106  };
107 
108  typedef std::list<Element *> CacheContainer;
109 
111 
113  ~SimpleHistogramCache() { TrimCache(true); }
114  SimpleHistogram *operator[](BaseData::Pointer sp_BaseData);
115 
116  protected:
117  void TrimCache(bool full = false)
118  {
119  unsigned int targetSize = full ? 0 : maxCacheSize;
120 
121  while (cache.size() > targetSize)
122  {
123  delete cache.back();
124  cache.pop_back();
125  }
126  }
127  };
128 }
129 
130 #endif
#define MITKALGORITHMSEXT_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
mitk::WeakPointer< BaseData > baseData
virtual SimpleHistogram * GetHistogram()=0
virtual void ComputeFromBaseData(BaseData *baseData)=0
std::list< Element * > CacheContainer
SimpleHistogram * operator[](BaseData::Pointer sp_BaseData)
void TrimCache(bool full=false)
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
virtual void ComputeFromBaseData(BaseData *source)=0
Creates a new histogram out the source.
virtual double GetMin() const =0
Returns the minimal value of the histogram.
virtual double GetMax() const =0
Returns the maximum value of the histogram.
virtual float GetRelativeBin(double start, double end) const =0
TODO: (What should this method do?)
void ComputeFromBaseData(BaseData *source) override
Creates a new histogram out the source which must be an image. Method does nothing if the image is in...
HistogramType::ConstPointer histogram
double GetMax() const override
Returns the maximum value of the histogram.
itk::Image< unsigned char, 3 > BinImage
itk::ImageRegionIterator< CTImage > CTIteratorType
float GetRelativeBin(double start, double end) const override
TODO: (What should this method do?)
itk::Statistics::Histogram< double > HistogramType
itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType
itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType
double GetMin() const override
Returns the minimal value of the histogram.
itk::Image< short, 3 > CTImage
itk::ImageRegionIterator< BinImage > BinIteratorType
Find image slices visible on a given plane.