ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkCompositeValleyFunction.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 itkCompositeValleyFunction_h
19 #define itkCompositeValleyFunction_h
20 
22 #include "ITKBiasCorrectionExport.h"
23 #include <vector>
24 
25 namespace itk
26 {
73 class TargetClass
74 {
75 public:
77  TargetClass(double mean, double sigma)
78  {
79  m_Mean = mean;
80  m_Sigma = sigma;
81  }
82 
84  void SetMean(double mean) { m_Mean = mean; }
85  double GetMean() { return m_Mean; }
87 
89  void SetSigma(double sigma) { m_Sigma = sigma; }
90  double GetSigma() { return m_Sigma; }
92 
93 private:
94  double m_Mean;
95  double m_Sigma;
96 }; // end of class
97 
98 class ITKBiasCorrection_EXPORT CompositeValleyFunction:public CacheableScalarFunction
99 {
100 public:
101 
103  typedef CacheableScalarFunction Superclass;
104 
106  typedef Superclass::MeasureType MeasureType;
107  typedef Superclass::MeasureArrayType MeasureArrayType;
108 
110  CompositeValleyFunction(const MeasureArrayType & classMeans,
111  const MeasureArrayType & classSigmas);
112 
114  virtual ~CompositeValleyFunction() ITK_OVERRIDE;
115 
117  double GetUpperBound() { return m_UpperBound; }
118 
120  double GetLowerBound() { return m_LowerBound; }
121 
124  MeasureType operator()(MeasureType x)
125  {
126  if ( x > m_UpperBound || x < m_LowerBound )
127  {
128  return 1;
129  }
130 
131  if ( !this->IsCacheAvailable() )
132  {
133  return this->Evaluate(x);
134  }
135  else
136  {
137  return GetCachedValue(x);
138  }
139  }
140 
142  virtual MeasureType Evaluate(MeasureType x) ITK_OVERRIDE;
143 
145  inline MeasureType valley(MeasureType d)
146  {
147  return 1 - 1 / ( 1 + d * d / 3 );
148  }
149 
150 protected:
151  void AddNewClass(double mean, double sigma)
152  {
153  TargetClass aClass(mean, sigma);
154 
155  m_Targets.push_back(aClass);
156  }
157 
159  void Initialize();
160 
161 private:
163  std::vector< TargetClass > m_Targets;
164 
167  double m_UpperBound;
168