Medical Imaging Interaction Toolkit  2023.04.00
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:
79 
80  bool valid;
81 
82  int first;
83  int last;
84  int min;
85  int max;
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 
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
mitk::SimpleImageHistogram::invLogHighest
double invLogHighest
Definition: mitkSimpleHistogram.h:87
mitk::SimpleHistogram
Abstract superclass for histograms with double values. Classes which are deriving from this class can...
Definition: mitkSimpleHistogram.h:34
mitk::SimpleImageHistogram
Definition: mitkSimpleHistogram.h:47
mitkImage.h
mitk::SimpleImageHistogram::max
int max
Definition: mitkSimpleHistogram.h:85
mitk::SimpleImageHistogram::valid
bool valid
Definition: mitkSimpleHistogram.h:80
mitk::SimpleImageHistogram::BinIteratorType
itk::ImageRegionIterator< BinImage > BinIteratorType
Definition: mitkSimpleHistogram.h:72
mitk::SimpleImageHistogram::CTIteratorIndexType
itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType
Definition: mitkSimpleHistogram.h:69
mitk::SimpleHistogramCache::cache
CacheContainer cache
Definition: mitkSimpleHistogram.h:131
mitk::SimpleImageHistogram::first
int first
Definition: mitkSimpleHistogram.h:82
mitk::SimpleImageHistogram::CTImage
itk::Image< short, 3 > CTImage
Definition: mitkSimpleHistogram.h:67
itk::SmartPointer< Self >
MitkAlgorithmsExtExports.h
mitk::SimpleHistogramCache::~SimpleHistogramCache
~SimpleHistogramCache()
Definition: mitkSimpleHistogram.h:134
mitk::SimpleImageHistogram::CountType
unsigned long CountType
Definition: mitkSimpleHistogram.h:75
MITKALGORITHMSEXT_EXPORT
#define MITKALGORITHMSEXT_EXPORT
Definition: MitkAlgorithmsExtExports.h:15
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::SimpleImageHistogram::SimpleImageHistogram
SimpleImageHistogram()
Definition: mitkSimpleHistogram.h:52
mitk::SimpleHistogramCache
Definition: mitkSimpleHistogram.h:112
mitk::SimpleImageHistogram::highest
CountType highest
Definition: mitkSimpleHistogram.h:86
mitk::SimpleImageHistogram::BinIteratorIndexType
itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType
Definition: mitkSimpleHistogram.h:73
mitk::SimpleImageHistogram::HistogramType
itk::Statistics::Histogram< double > HistogramType
Definition: mitkSimpleHistogram.h:50
mitk::SimpleHistogramCache::SimpleHistogramCache
SimpleHistogramCache()
Definition: mitkSimpleHistogram.h:133
mitk::SimpleImageHistogram::BinImage
itk::Image< unsigned char, 3 > BinImage
Definition: mitkSimpleHistogram.h:71
mitk::SimpleImageHistogram::GetMax
double GetMax() const override
Returns the maximum value of the histogram.
Definition: mitkSimpleHistogram.h:98
mitk::SimpleImageHistogram::last
int last
Definition: mitkSimpleHistogram.h:83
mitk::SimpleHistogramCache::Element::baseData
mitk::WeakPointer< BaseData > baseData
Definition: mitkSimpleHistogram.h:120
mitk::SimpleImageHistogram::GetMin
double GetMin() const override
Returns the minimal value of the histogram.
Definition: mitkSimpleHistogram.h:90
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::SimpleHistogramCache::Element::m_LastUpdateTime
itk::TimeStamp m_LastUpdateTime
Definition: mitkSimpleHistogram.h:121
mitk::SimpleImageHistogram::histogram
CountType * histogram
Definition: mitkSimpleHistogram.h:78
mitkWeakPointer.h
mitk::SimpleHistogramCache::Element
Definition: mitkSimpleHistogram.h:117
mitk::SimpleImageHistogram::min
int min
Definition: mitkSimpleHistogram.h:84
mitk::WeakPointer
Definition: mitkWeakPointer.h:22
mitk::SimpleImageHistogram::CTIteratorType
itk::ImageRegionIterator< CTImage > CTIteratorType
Definition: mitkSimpleHistogram.h:68
mitk::SimpleImageHistogram::~SimpleImageHistogram
~SimpleImageHistogram()
Definition: mitkSimpleHistogram.h:58
mitk::SimpleHistogramCache::CacheContainer
std::list< Element * > CacheContainer
Definition: mitkSimpleHistogram.h:129
mitk::SimpleHistogramCache::TrimCache
void TrimCache(bool full=false)
Definition: mitkSimpleHistogram.h:138