00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkCacheableScalarFunction.h,v $ 00005 Language: C++ 00006 Date: $Date: 2007/03/29 19:37:00 $ 00007 Version: $Revision: 1.10 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 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 // access table 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 }; // end of class 00134 } // end of namespace itk 00135 #endif 00136