ITK
4.0.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 __itkMembershipFunctionBase_h 00019 #define __itkMembershipFunctionBase_h 00020 00021 #include "itkFunctionBase.h" 00022 #include "itkMeasurementVectorTraits.h" 00023 #include "itkNumericTraitsCovariantVectorPixel.h" 00024 00025 namespace itk 00026 { 00027 namespace Statistics 00028 { 00056 template< class TVector > 00057 class ITK_EXPORT MembershipFunctionBase: 00058 public FunctionBase< TVector, double > 00059 { 00060 public: 00062 typedef MembershipFunctionBase Self; 00063 typedef FunctionBase< TVector, double > Superclass; 00064 typedef SmartPointer< Self > Pointer; 00065 typedef SmartPointer< const Self > ConstPointer; 00066 00068 itkTypeMacro(MembershipFunctionBase, FunctionBase); 00069 00071 typedef TVector MeasurementVectorType; 00072 00074 typedef unsigned int MeasurementVectorSizeType; 00075 00079 virtual Pointer Clone() const = 0; 00080 00084 virtual double Evaluate(const MeasurementVectorType & x) const = 0; 00085 00093 virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s) 00094 { 00095 // Test whether the vector type is resizable or not 00096 MeasurementVectorType m; 00097 00098 if ( MeasurementVectorTraits::IsResizable(m) ) 00099 { 00100 // then this is a resizable vector type 00101 // 00102 // if the new size is the same as the previou size, just return 00103 if ( s == this->m_MeasurementVectorSize ) 00104 { 00105 return; 00106 } 00107 else 00108 { 00109 this->m_MeasurementVectorSize = s; 00110 this->Modified(); 00111 } 00112 } 00113 else 00114 { 00115 // If this is a non-resizable vector type 00116 MeasurementVectorType m3; 00117 MeasurementVectorSizeType defaultLength = 00118 NumericTraits<MeasurementVectorType>::GetLength(m3); 00119 // and the new length is different from the default one, then throw an 00120 // exception 00121 if ( defaultLength != s ) 00122 { 00123 itkExceptionMacro( 00124 "Attempting to change the measurement vector size of a non-resizable vector type" ); 00125 } 00126 } 00127 } 00128 00130 itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType); 00131 00132 protected: 00133 MembershipFunctionBase() 00134 { 00135 m_MeasurementVectorSize = NumericTraits<MeasurementVectorType>::GetLength( 00136 MeasurementVectorType() ); 00137 } 00138 00139 virtual ~MembershipFunctionBase(void) {} 00140 00141 void PrintSelf(std::ostream & os, Indent indent) const 00142 { 00143 Superclass::PrintSelf(os, indent); 00144 os << indent << "Length of measurement vectors: " 00145 << m_MeasurementVectorSize << std::endl; 00146 } 00147 00148 private: 00149 MembershipFunctionBase(const Self &); //purposely not implemented 00150 void operator=(const Self &); //purposely not implemented 00151 00152 MeasurementVectorSizeType m_MeasurementVectorSize; 00153 00154 }; // end of class 00155 } // end of namespace Statistics 00156 } // end namespace itk 00157 00158 #endif 00159