00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkCacheableScalarFunction_h
00018 #define __itkCacheableScalarFunction_h
00019
00020 #include "itkArray.h"
00021 #include "itkExceptionObject.h"
00022
00023 namespace itk {
00055 class CacheableScalarFunction
00056 {
00057 public:
00059 CacheableScalarFunction() ;
00060
00062 virtual ~CacheableScalarFunction() {}
00063
00065 typedef double MeasureType ;
00066 typedef Array<MeasureType> MeasureArrayType;
00067
00070 long GetNumberOfSamples() { return m_NumberOfSamples ; }
00071
00073 bool IsCacheAvailable() { return m_CacheAvailable ; }
00074
00076 double GetCacheUpperBound() { return m_CacheUpperBound ; }
00077
00079 double GetCacheLowerBound() { return m_CacheLowerBound ; }
00080
00084 virtual MeasureType Evaluate(MeasureType x)
00085 { return x ; }
00086
00088 double GetInterval()
00089 { return m_TableInc ; }
00090
00096 inline MeasureType GetCachedValue(MeasureType x)
00097 {
00098 if (x > m_CacheUpperBound || x < m_CacheLowerBound)
00099 {
00100 throw ExceptionObject(__FILE__,__LINE__);
00101 }
00102
00103 int index = (int) ((x - m_CacheLowerBound) / m_TableInc) ;
00104 return m_CacheTable[index] ;
00105 }
00106
00107 protected:
00110 void CreateCache(double lowerBound, double upperBound, long sampleSize) ;
00111
00112 private:
00115 long m_NumberOfSamples ;
00116
00118 MeasureArrayType m_CacheTable;
00119
00121 double m_CacheUpperBound;
00122
00124 double m_CacheLowerBound ;
00125
00127 double m_TableInc ;
00128
00130 bool m_CacheAvailable ;
00131
00132 } ;
00133 }
00134 #endif