Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKSIMPLEHISTOGRAM_H
18 #define MITKSIMPLEHISTOGRAM_H
19 
20 #ifndef __itkHistogram_h
21 #include <itkHistogram.h>
22 #endif
23 
25 
26 #include <mitkImage.h>
27 #include <mitkWeakPointer.h>
28 
29 #include <itkImageRegionIterator.h>
30 #include <itkImageRegionIteratorWithIndex.h>
31 
32 namespace mitk
33 {
34  //##Documentation
35  //## @brief Abstract superclass for histograms with double values.
36  //## Classes which are deriving from this class can be cached
37  //## in the same way.
39  {
40  public:
42  virtual double GetMin() const = 0;
44  virtual double GetMax() const = 0;
46  virtual void ComputeFromBaseData(BaseData *source) = 0;
48  virtual float GetRelativeBin(double start, double end) const = 0;
49  };
50 
52  {
53  public:
54  typedef itk::Statistics::Histogram<double> HistogramType;
55 
57  {
58  valid = false;
59  histogram = nullptr;
60  }
61 
63  {
64  if (histogram)
65  delete histogram;
66  }
67 
69  bool GetValid();
70 
71  typedef itk::Image<short, 3> CTImage;
72  typedef itk::ImageRegionIterator<CTImage> CTIteratorType;
73  typedef itk::ImageRegionIteratorWithIndex<CTImage> CTIteratorIndexType;
74 
75  typedef itk::Image<unsigned char, 3> BinImage;
76  typedef itk::ImageRegionIterator<BinImage> BinIteratorType;
77  typedef itk::ImageRegionIteratorWithIndex<BinImage> BinIteratorIndexType;
78 
79  typedef unsigned long CountType;
80 
81  protected:
82  CountType *histogram;
83 
84  bool valid;
85 
86  int first;
87  int last;
88  int min;
89  int max;
90  CountType highest;
91  double invLogHighest;
92 
93  public:
94  double GetMin() const override
95  {
96  if (!valid)
97  return 0;
98 
99  return min;
100  }
101 
102  double GetMax() const override
103  {
104  if (!valid)
105  return 1;
106 
107  return max;
108  }
109 
112  void ComputeFromBaseData(BaseData *source) override;
113  float GetRelativeBin(double start, double end) const override;
114  };
115 
117  {
118  public:
119  static const unsigned int maxCacheSize = 64;
120 
122  {
123  public:
125  itk::TimeStamp m_LastUpdateTime;
126 
127  virtual ~Element();
128 
129  virtual void ComputeFromBaseData(BaseData *baseData) = 0;
130  virtual SimpleHistogram *GetHistogram() = 0;
131  };
132 
133  typedef std::list<Element *> CacheContainer;
134 
135  CacheContainer cache;
136 
138  ~SimpleHistogramCache() { TrimCache(true); }
139  SimpleHistogram *operator[](BaseData::Pointer sp_BaseData);
140 
141  protected:
142  void TrimCache(bool full = false)
143  {
144  unsigned int targetSize = full ? 0 : maxCacheSize;
145 
146  while (cache.size() > targetSize)
147  {
148  delete cache.back();
149  cache.pop_back();
150  }
151  }
152  };
153 }
154 
155 #endif // MITKSIMPLEHISTOGRAM_H
itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType
itk::Image< short, 3 > CTImage
mitk::WeakPointer< BaseData > baseData
Base of all data objects.
Definition: mitkBaseData.h:39
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...
Implements a weak reference to an object.
static T max(T x, T y)
Definition: svm.cpp:70
static T min(T x, T y)
Definition: svm.cpp:67
itk::Image< unsigned char, 3 > BinImage
itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType
itk::ImageRegionIterator< BinImage > BinIteratorType