ITK  6.0.0
Insight Toolkit
itkCacheableScalarFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 {
60 class ITKBiasCorrection_EXPORT CacheableScalarFunction
61 {
62 public:
63 
65  CacheableScalarFunction();
66 
68  virtual ~CacheableScalarFunction();
69 
71  using MeasureType = double;
72  using MeasureArrayType = Array<MeasureType>;
73 
77  GetNumberOfSamples() const
78  {
79  return m_NumberOfSamples;
80  }
81 
83  bool
84  IsCacheAvailable() const
85  {
86  return m_CacheAvailable;
87  }
88 
90  double
91  GetCacheUpperBound() const
92  {
93  return m_CacheUpperBound;
94  }
95 
97  double
98  GetCacheLowerBound() const
99  {
100  return m_CacheLowerBound;
101  }
102 
106  virtual MeasureType
107  Evaluate(MeasureType x);
108 
110  double
111  GetInterval() const
112  {
113  return m_TableInc;
114  }
115 
121  inline MeasureType
122  GetCachedValue(MeasureType x)
123  {
124  if (x > m_CacheUpperBound || x < m_CacheLowerBound)
125  {
126  throw ExceptionObject(__FILE__, __LINE__);
127  }
128  // access table
129  auto index = static_cast<int>((x - m_CacheLowerBound) / m_TableInc);
130  return m_CacheTable[index];
131  }
134 protected:
137  void
138  CreateCache(double lowerBound, double upperBound, SizeValueType sampleSize);
139 
140 private:
143  SizeValueType m_NumberOfSamples{ 0 };
144 
146  MeasureArrayType m_CacheTable{};
147 
149  double m_CacheUpperBound{ 0.0 };
150 
152  double m_CacheLowerBound{ 0.0 };
153 
155  double m_TableInc{ 0.0 };
156 
itkIntTypes.h
itkArray.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86