Medical Imaging Interaction Toolkit  2021.10.99-9c07a326
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  histogram = nullptr;
56  }
57 
59  {
60  if (histogram)
61  delete histogram;
62  }
63 
65  bool GetValid();
66 
67  typedef itk::Image<short, 3> CTImage;
68  typedef itk::ImageRegionIterator<CTImage> CTIteratorType;
69  typedef itk::ImageRegionIteratorWithIndex<CTImage> CTIteratorIndexType;
70 
71  typedef itk::Image<unsigned char, 3> BinImage;
72  typedef itk::ImageRegionIterator<BinImage> BinIteratorType;
73  typedef itk::ImageRegionIteratorWithIndex<BinImage> BinIteratorIndexType;
74 
75  typedef unsigned long CountType;
76 
77  protected:
78  CountType *histogram;
79 
80  bool valid;
81 
82  int first;
83  int last;
84  int min;
85  int max;
86  CountType highest;
87  double invLogHighest;
88 
89  public:
90  double GetMin() const override
91  {
92  if (!valid)
93  return 0;
94 
95  return min;
96  }
97 
98  double GetMax() const override
99  {
100  if (!valid)
101  return 1;
102 
103  return max;
104  }
105 
108  void ComputeFromBaseData(BaseData *source) override;
109  float GetRelativeBin(double start, double end) const override;
110  };
111 
113  {
114  public:
115  static const unsigned int maxCacheSize = 64;
116 
118  {
119  public:
121  itk::TimeStamp m_LastUpdateTime;
122 
123  virtual ~Element();
124 
125  virtual void ComputeFromBaseData(BaseData *baseData) = 0;
126  virtual SimpleHistogram *GetHistogram() = 0;
127  };
128 
129  typedef std::list<Element *> CacheContainer;
130 
131  CacheContainer cache;
132 
134  ~SimpleHistogramCache() { TrimCache(true); }
135  SimpleHistogram *operator[](BaseData::Pointer sp_BaseData);
136 
137  protected:
138  void TrimCache(bool full = false)
139  {
140  unsigned int targetSize = full ? 0 : maxCacheSize;
141 
142  while (cache.size() > targetSize)
143  {
144  delete cache.back();
145  cache.pop_back();
146  }
147  }
148  };
149 }
150 
151 #endif // MITKSIMPLEHISTOGRAM_H
itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType
itk::Image< short, 3 > CTImage
mitk::WeakPointer< BaseData > baseData
Base of all data objects.
Definition: mitkBaseData.h:42
double GetMax() const override
Returns the maximum value of the histogram.
itk::ImageRegionIterator< CTImage > CTIteratorType
DataCollection - Class to facilitate loading/accessing structured data.
itk::Statistics::Histogram< double > HistogramType
#define MITKALGORITHMSEXT_EXPORT
double GetMin() const override
Returns the minimal value of the histogram.
std::list< Element * > CacheContainer
void TrimCache(bool full=false)
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
itk::Image< unsigned char, 3 > BinImage
itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType
itk::ImageRegionIterator< BinImage > BinIteratorType