ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkCompositeValleyFunction_h 00019 #define __itkCompositeValleyFunction_h 00020 00021 #include "itkCacheableScalarFunction.h" 00022 #include <vector> 00023 00024 namespace itk 00025 { 00072 class TargetClass 00073 { 00074 public: 00076 TargetClass(double mean, double sigma) 00077 { 00078 m_Mean = mean; 00079 m_Sigma = sigma; 00080 } 00081 00083 void SetMean(double mean) { m_Mean = mean; } 00084 double GetMean() { return m_Mean; } 00086 00088 void SetSigma(double sigma) { m_Sigma = sigma; } 00089 double GetSigma() { return m_Sigma; } 00090 private: 00091 double m_Mean; 00092 double m_Sigma; 00093 }; // end of class 00095 00096 class ITK_EXPORT CompositeValleyFunction:public CacheableScalarFunction 00097 { 00098 public: 00099 00101 typedef CacheableScalarFunction Superclass; 00102 00104 typedef Superclass::MeasureType MeasureType; 00105 typedef Superclass::MeasureArrayType MeasureArrayType; 00106 00108 CompositeValleyFunction(const MeasureArrayType & classMeans, 00109 const MeasureArrayType & classSigmas); 00110 00112 virtual ~CompositeValleyFunction() {} 00113 00115 double GetUpperBound() { return m_UpperBound; } 00116 00118 double GetLowerBound() { return m_LowerBound; } 00119 00122 MeasureType operator()(MeasureType x) 00123 { 00124 if ( x > m_UpperBound || x < m_LowerBound ) 00125 { 00126 return 1; 00127 } 00128 00129 if ( !this->IsCacheAvailable() ) 00130 { 00131 return this->Evaluate(x); 00132 } 00133 else 00134 { 00135 return GetCachedValue(x); 00136 } 00137 } 00138 00140 inline MeasureType Evaluate(MeasureType x) 00141 { 00142 MeasureType res = 1; 00143 00144 for ( unsigned int k = 0; k < m_Targets.size(); k++ ) 00145 { 00146 res *= valley( ( x - m_Targets[k].GetMean() ) 00147 / m_Targets[k].GetSigma() ); 00148 } 00149 00150 return res; 00151 } 00152 00154 inline MeasureType valley(MeasureType d) 00155 { 00156 return 1 - 1 / ( 1 + d * d / 3 ); 00157 } 00158 00159 protected: 00160 void AddNewClass(double mean, double sigma) 00161 { 00162 TargetClass aClass(mean, sigma); 00163 00164 m_Targets.push_back(aClass); 00165 } 00166 00168 void Initialize(); 00169 00170 private: 00172 std::vector< TargetClass > m_Targets; 00173 00176 double m_UpperBound; 00177 00178