ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkCacheableScalarFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkCacheableScalarFunction_h
19 #define itkCacheableScalarFunction_h
20 
21 #include "itkArray.h"
22 #include "itkIntTypes.h"
23 #include "ITKBiasCorrectionExport.h"
24 
25 namespace itk
26 {
59 class ITKBiasCorrection_EXPORT CacheableScalarFunction
60 {
61 public:
63  CacheableScalarFunction();
64 
66  virtual ~CacheableScalarFunction();
67 
69  typedef double MeasureType;
70  typedef Array< MeasureType > MeasureArrayType;
71 
74  SizeValueType GetNumberOfSamples() { return m_NumberOfSamples; }
75 
77  bool IsCacheAvailable() { return m_CacheAvailable; }
78 
80  double GetCacheUpperBound() { return m_CacheUpperBound; }
81 
83  double GetCacheLowerBound() { return m_CacheLowerBound; }
84 
88  virtual MeasureType Evaluate(MeasureType x);
89 
91  double GetInterval()
92  { return m_TableInc; }
93 
99  inline MeasureType GetCachedValue(MeasureType x)
100  {
101  if ( x > m_CacheUpperBound || x < m_CacheLowerBound )
102  {
103  throw ExceptionObject(__FILE__, __LINE__);
104  }
105  // access table
106  int index = (int)( ( x - m_CacheLowerBound ) / m_TableInc );
107  return m_CacheTable[index];
108  }
110 
111 protected:
114  void CreateCache(double lowerBound, double upperBound, SizeValueType sampleSize);
115 
116 private:
119  SizeValueType m_NumberOfSamples;
120 
122  MeasureArrayType m_CacheTable;
123 
125  double m_CacheUpperBound;
126 
128  double m_CacheLowerBound;
129 
131  double m_TableInc;
132 
unsigned long SizeValueType
Definition: itkIntTypes.h:143