Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkCacheableScalarFunction.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkCacheableScalarFunction.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/02/26 00:40:57 $
00007   Version:   $Revision: 1.5 $
00008 
00009   Copyright (c) 2002 Insight 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 GetCacheHigherBound() { return m_CacheHigherBound ; } 
00077 
00079   double GetCacheLowerBound() { return m_CacheLowerBound ; } 
00080 
00084   virtual MeasureType Evaluate(MeasureType x) 
00085     { return x ; }
00086 
00092   inline MeasureType GetCachedValue(MeasureType x)
00093   {
00094     if (x > m_CacheHigherBound || x < m_CacheLowerBound)
00095       {
00096       throw ExceptionObject(__FILE__,__LINE__);
00097       }
00098     // access table
00099     int index = (int) ((x - m_CacheLowerBound) / m_TableInc + 0.5) ;
00100     return m_CacheTable[index] ;
00101   }
00102 
00103 protected:
00106   void CreateCache(double lowerBound, double higherBound, long sampleSize) ;
00107 
00108 private:
00111   long m_NumberOfSamples ;
00112 
00114   MeasureArrayType  m_CacheTable;
00115 
00117   double m_CacheHigherBound;
00118 
00120   double m_CacheLowerBound ;
00121 
00123   double m_TableInc ;
00124 
00126   bool m_CacheAvailable ;
00127   
00128 } ; // end of class
00129 } // end of namespace itk
00130 #endif

Generated at Fri May 21 01:14:30 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000