ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkCacheableScalarFunction.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkCacheableScalarFunction_h
00019 #define __itkCacheableScalarFunction_h
00020 
00021 #include "itkArray.h"
00022 #include "itkIntTypes.h"
00023 
00024 namespace itk
00025 {
00058 class ITK_EXPORT CacheableScalarFunction
00059 {
00060 public:
00062   CacheableScalarFunction();
00063 
00065   virtual ~CacheableScalarFunction() {}
00066 
00068   typedef double               MeasureType;
00069   typedef Array< MeasureType > MeasureArrayType;
00070 
00073   SizeValueType GetNumberOfSamples() { return m_NumberOfSamples; }
00074 
00076   bool IsCacheAvailable() { return m_CacheAvailable; }
00077 
00079   double GetCacheUpperBound() { return m_CacheUpperBound; }
00080 
00082   double GetCacheLowerBound() { return m_CacheLowerBound; }
00083 
00087   virtual MeasureType Evaluate(MeasureType x)
00088   { return x; }
00089 
00091   double GetInterval()
00092   { return m_TableInc; }
00093 
00099   inline MeasureType GetCachedValue(MeasureType x)
00100   {
00101     if ( x > m_CacheUpperBound || x < m_CacheLowerBound )
00102       {
00103       throw ExceptionObject(__FILE__, __LINE__);
00104       }
00105     // access table
00106     int index = (int)( ( x - m_CacheLowerBound ) / m_TableInc );
00107     return m_CacheTable[index];
00108   }
00110 
00111 protected:
00114   void CreateCache(double lowerBound, double upperBound, SizeValueType sampleSize);
00115 
00116 private:
00119   SizeValueType m_NumberOfSamples;
00120 
00122   MeasureArrayType m_CacheTable;
00123 
00125   double m_CacheUpperBound;
00126 
00128   double m_CacheLowerBound;
00129 
00131   double m_TableInc;
00132 
00133