ITK  4.4.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 
24 namespace itk
25 {
58 class ITK_EXPORT CacheableScalarFunction
59 {
60 public:
62  CacheableScalarFunction();
63 
65  virtual ~CacheableScalarFunction() {}
66 
68  typedef double MeasureType;
69  typedef Array< MeasureType > MeasureArrayType;
70 
73  SizeValueType GetNumberOfSamples() { return m_NumberOfSamples; }
74 
76  bool IsCacheAvailable() { return m_CacheAvailable; }
77 
79  double GetCacheUpperBound() { return m_CacheUpperBound; }
80 
82  double GetCacheLowerBound() { return m_CacheLowerBound; }
83 
87  virtual MeasureType Evaluate(MeasureType x)
88  { return 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 
133