Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cmtkHistogramBase_h_included_
00034 #define __cmtkHistogramBase_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Base/cmtkTypes.h>
00039 #include <Base/cmtkMathUtil.h>
00040
00041 #include <System/cmtkSmartPtr.h>
00042
00043 #include <algorithm>
00044
00045 #ifndef CMTK_HISTOGRAM_AUTOBINS
00046
00047 #define CMTK_HISTOGRAM_AUTOBINS 0
00048 #endif
00049
00051 #define CMTK_HISTOGRAM_FRACTIONAL true
00052
00054 #define CMTK_HISTOGRAM_DISCRETE false
00055
00057 #define CMTK_HISTOGRAM_RESET true
00058
00060 #define CMTK_HISTOGRAM_NORESET false
00061
00063 #define CMTK_HISTOGRAM_COPY true
00064
00066 #define CMTK_HISTOGRAM_NOCOPY false
00067
00068 namespace
00069 cmtk
00070 {
00071
00074
00077 class HistogramBase
00078 {
00079 protected:
00081 Types::DataItem m_BinWidth;
00082
00084 Types::DataItem m_BinsLowerBound;
00085
00087 Types::DataItem m_BinsUpperBound;
00088
00089 public:
00091 typedef HistogramBase Self;
00092
00094 HistogramBase()
00095 {
00096 this->m_BinWidth = 1.0;
00097 this->m_BinsLowerBound = this->m_BinsUpperBound = 0.0;
00098 }
00099
00101 virtual ~HistogramBase() {}
00102
00104 virtual size_t GetNumBins() const = 0;
00105
00108 void SetRange ( const Types::DataItemRange& range )
00109 {
00110 this->m_BinsLowerBound = range.m_LowerBound;
00111 this->m_BinsUpperBound = range.m_UpperBound;
00112 this->m_BinWidth = range.Width() / (this->GetNumBins() - 1);
00113 }
00114
00117 void SetRangeCentered( const Types::DataItemRange& range )
00118 {
00119 this->m_BinWidth = range.Width() / (this->GetNumBins() - 1);
00120 this->m_BinsLowerBound = static_cast<Types::DataItem>( range.m_LowerBound - 0.5 * this->m_BinWidth );
00121 this->m_BinsUpperBound = static_cast<Types::DataItem>( range.m_UpperBound + 0.5 * this->m_BinWidth );
00122 }
00123
00126 const Types::DataItemRange GetRange() const
00127 {
00128 return Types::DataItemRange( this->m_BinsLowerBound, this->m_BinsUpperBound );
00129 }
00130
00133 virtual const Types::DataItemRange GetRangeBin( const size_t bin ) const
00134 {
00135 const Types::DataItem from = this->m_BinsLowerBound + this->m_BinWidth * bin;
00136 return Types::DataItemRange( from, from + this->m_BinWidth );
00137 }
00138
00140 Types::DataItem GetBinWidth() const
00141 {
00142 return this->m_BinWidth;
00143 }
00144
00149 virtual size_t ValueToBin ( const Types::DataItem value ) const
00150 {
00151 const size_t binIndex = static_cast<size_t>( (value - this->m_BinsLowerBound) / this->m_BinWidth );
00152 return std::max<size_t>( 0, std::min( this->GetNumBins()-1, binIndex ) );
00153 }
00154
00161 virtual Types::DataItem ValueToBinFractional ( const Types::DataItem value ) const
00162 {
00163 const Types::DataItem binIndex = (value - this->m_BinsLowerBound) / this->m_BinWidth;
00164 return std::max<Types::DataItem>( 0, std::min<Types::DataItem>( static_cast<Types::DataItem>( this->GetNumBins()-1 ), binIndex));
00165 }
00166
00171 virtual Types::DataItem BinToValue ( const size_t bin ) const
00172 {
00173 return static_cast<Types::DataItem>( this->m_BinsLowerBound + (bin+0.5) * this->m_BinWidth );
00174 }
00175 };
00176
00178
00179 }
00180
00181 #endif // #ifndef __cmtkHistogramBase_h_included_