ITK  4.2.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 <vector>
23 
24 namespace itk
25 {
72 class TargetClass
73 {
74 public:
76  TargetClass(double mean, double sigma)
77  {
78  m_Mean = mean;
79  m_Sigma = sigma;
80  }
81 
83  void SetMean(double mean) { m_Mean = mean; }
84  double GetMean() { return m_Mean; }
86 
88  void SetSigma(double sigma) { m_Sigma = sigma; }
89  double GetSigma() { return m_Sigma; }
90 private:
91  double m_Mean;
92  double m_Sigma;
93 }; // end of class
95 
96 class ITK_EXPORT CompositeValleyFunction:public CacheableScalarFunction
97 {
98 public:
99 
101  typedef CacheableScalarFunction Superclass;
102 
104  typedef Superclass::MeasureType MeasureType;
105  typedef Superclass::MeasureArrayType MeasureArrayType;
106 
108  CompositeValleyFunction(const MeasureArrayType & classMeans,
109  const MeasureArrayType & classSigmas);
110 
112  virtual ~CompositeValleyFunction() {}
113 
115  double GetUpperBound() { return m_UpperBound; }
116 
118  double GetLowerBound() { return m_LowerBound; }
119 
122  MeasureType operator()(MeasureType x)
123  {
124  if ( x > m_UpperBound || x < m_LowerBound )
125  {
126  return 1;
127  }
128 
129  if ( !this->IsCacheAvailable() )
130  {
131  return this->Evaluate(x);
132  }
133  else
134  {
135  return GetCachedValue(x);
136  }
137  }
138 
140  inline MeasureType Evaluate(MeasureType x)
141  {
142  MeasureType res = 1;
143 
144  for ( unsigned int k = 0; k < m_Targets.size(); k++ )
145  {
146  res *= valley( ( x - m_Targets[k].GetMean() )
147  / m_Targets[k].GetSigma() );
148  }
149 
150  return res;
151  }
152 
154  inline MeasureType valley(MeasureType d)
155  {
156  return 1 - 1 / ( 1 + d * d / 3 );
157  }
158 
159 protected:
160  void AddNewClass(double mean, double sigma)
161  {
162  TargetClass aClass(mean, sigma);
163 
164  m_Targets.push_back(aClass);
165  }
166 
168  void Initialize();
169 
170 private:
172  std::vector< TargetClass > m_Targets;
173 
176  double m_UpperBound;
177 
178