ITK  4.4.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; }
91 
92 private:
93  double m_Mean;
94  double m_Sigma;
95 }; // end of class
96 
97 class ITK_EXPORT CompositeValleyFunction:public CacheableScalarFunction
98 {
99 public:
100 
102  typedef CacheableScalarFunction Superclass;
103 
105  typedef Superclass::MeasureType MeasureType;
106  typedef Superclass::MeasureArrayType MeasureArrayType;
107 
109  CompositeValleyFunction(const MeasureArrayType & classMeans,
110  const MeasureArrayType & classSigmas);
111 
113  virtual ~CompositeValleyFunction() {}
114 
116  double GetUpperBound() { return m_UpperBound; }
117 
119  double GetLowerBound() { return m_LowerBound; }
120 
123  MeasureType operator()(MeasureType x)
124  {
125  if ( x > m_UpperBound || x < m_LowerBound )
126  {
127  return 1;
128  }
129 
130  if ( !this->IsCacheAvailable() )
131  {
132  return this->Evaluate(x);
133  }
134  else
135  {
136  return GetCachedValue(x);
137  }
138  }
139 
141  inline MeasureType Evaluate(MeasureType x)
142  {
143  MeasureType res = 1;
144 
145  for ( unsigned int k = 0; k < m_Targets.size(); k++ )
146  {
147  res *= valley( ( x - m_Targets[k].GetMean() )
148  / m_Targets[k].GetSigma() );
149  }
150 
151  return res;
152  }
153 
155  inline MeasureType valley(MeasureType d)
156  {
157  return 1 - 1 / ( 1 + d * d / 3 );
158  }
159 
160 protected:
161  void AddNewClass(double mean, double sigma)
162  {
163  TargetClass aClass(mean, sigma);
164 
165  m_Targets.push_back(aClass);
166  }
167 
169  void Initialize();
170 
171 private:
173  std::vector< TargetClass > m_Targets;
174 
177  double m_UpperBound;
178 
179