Medical Imaging Interaction Toolkit  2024.06.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  }
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;
105  virtual SimpleHistogram *GetHistogram() = 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
mitk::SimpleImageHistogram::invLogHighest
double invLogHighest
Definition: mitkSimpleHistogram.h:79
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::valid
bool valid
Definition: mitkSimpleHistogram.h:77
mitk::SimpleImageHistogram::BinIteratorType
itk::ImageRegionIterator< BinImage > BinIteratorType
Definition: mitkSimpleHistogram.h:69
mitk::SimpleImageHistogram::CTIteratorIndexType
itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType
Definition: mitkSimpleHistogram.h:66
mitk::SimpleHistogramCache::cache
CacheContainer cache
Definition: mitkSimpleHistogram.h:110
mitk::SimpleImageHistogram::CTImage
itk::Image< short, 3 > CTImage
Definition: mitkSimpleHistogram.h:64
itk::SmartPointer< Self >
MitkAlgorithmsExtExports.h
mitk::SimpleHistogramCache::~SimpleHistogramCache
~SimpleHistogramCache()
Definition: mitkSimpleHistogram.h:113
mitk::SimpleImageHistogram::CountType
unsigned long CountType
Definition: mitkSimpleHistogram.h:72
MITKALGORITHMSEXT_EXPORT
#define MITKALGORITHMSEXT_EXPORT
Definition: MitkAlgorithmsExtExports.h:15
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::SimpleImageHistogram::SimpleImageHistogram
SimpleImageHistogram()
Definition: mitkSimpleHistogram.h:52
mitk::SimpleImageHistogram::histogram
HistogramType::ConstPointer histogram
Definition: mitkSimpleHistogram.h:75
mitk::SimpleHistogramCache
Definition: mitkSimpleHistogram.h:91
mitk::SimpleImageHistogram::BinIteratorIndexType
itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType
Definition: mitkSimpleHistogram.h:70
mitk::SimpleImageHistogram::HistogramType
itk::Statistics::Histogram< double > HistogramType
Definition: mitkSimpleHistogram.h:50
mitk::SimpleHistogramCache::SimpleHistogramCache
SimpleHistogramCache()
Definition: mitkSimpleHistogram.h:112
mitk::SimpleImageHistogram::BinImage
itk::Image< unsigned char, 3 > BinImage
Definition: mitkSimpleHistogram.h:68
mitk::SimpleHistogramCache::Element::baseData
mitk::WeakPointer< BaseData > baseData
Definition: mitkSimpleHistogram.h:99
mitk::BaseData
Base of all data objects.
Definition: mitkBaseData.h:42
mitk::SimpleHistogramCache::Element::m_LastUpdateTime
itk::TimeStamp m_LastUpdateTime
Definition: mitkSimpleHistogram.h:100
mitkWeakPointer.h
mitk::SimpleHistogramCache::Element
Definition: mitkSimpleHistogram.h:96
mitk::WeakPointer
Definition: mitkWeakPointer.h:22
mitk::SimpleImageHistogram::CTIteratorType
itk::ImageRegionIterator< CTImage > CTIteratorType
Definition: mitkSimpleHistogram.h:65
mitk::SimpleImageHistogram::~SimpleImageHistogram
~SimpleImageHistogram()
Definition: mitkSimpleHistogram.h:57
mitk::SimpleHistogramCache::CacheContainer
std::list< Element * > CacheContainer
Definition: mitkSimpleHistogram.h:108
mitk::SimpleHistogramCache::TrimCache
void TrimCache(bool full=false)
Definition: mitkSimpleHistogram.h:117