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 ITK_EXPORT 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 }
00107
00108 protected:
00111 void CreateCache(double lowerBound, double upperBound, long sampleSize);
00112
00113 private:
00116 long m_NumberOfSamples;
00117
00119 MeasureArrayType m_CacheTable;
00120
00122 double m_CacheUpperBound;
00123
00125 double m_CacheLowerBound;
00126
00128 double m_TableInc;
00129
00131 bool m_CacheAvailable;
00132
00133 };
00134 }
00135 #endif
00136