ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMembershipFunctionBase.h
Go to the documentation of this file.
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 double Evaluate(const MeasurementVectorType & x) const = 0;
00080 
00088   virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
00089   {
00090     // Test whether the vector type is resizable or not
00091     MeasurementVectorType m;
00092 
00093     if ( MeasurementVectorTraits::IsResizable(m) )
00094       {
00095       // then this is a resizable vector type
00096       //
00097       // if the new size is the same as the previou size, just return
00098       if ( s == this->m_MeasurementVectorSize )
00099         {
00100         return;
00101         }
00102       else
00103         {
00104         this->m_MeasurementVectorSize = s;
00105         this->Modified();
00106         }
00107       }
00108     else
00109       {
00110       // If this is a non-resizable vector type
00111       MeasurementVectorType     m3;
00112       MeasurementVectorSizeType defaultLength =
00113         NumericTraits<MeasurementVectorType>::GetLength(m3);
00114       // and the new length is different from the default one, then throw an
00115       // exception
00116       if ( defaultLength != s )
00117         {
00118         itkExceptionMacro(
00119           "Attempting to change the measurement vector size of a non-resizable vector type" );
00120         }
00121       }
00122   }
00123 
00125   itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
00126 
00127 protected:
00128   MembershipFunctionBase()
00129   {
00130     m_MeasurementVectorSize = NumericTraits<MeasurementVectorType>::GetLength(
00131       MeasurementVectorType() );
00132   }
00133 
00134   virtual ~MembershipFunctionBase(void) {}
00135 
00136   void PrintSelf(std::ostream & os, Indent indent) const
00137   {
00138     Superclass::PrintSelf(os, indent);
00139     os << indent << "Length of measurement vectors: "
00140        << m_MeasurementVectorSize << std::endl;
00141   }
00142 
00143 private:
00144   MembershipFunctionBase(const Self &);   //purposely not implemented
00145   void operator=(const Self &); //purposely not implemented
00146 
00147   MeasurementVectorSizeType m_MeasurementVectorSize;
00148 
00149 };  // end of class
00150 } // end of namespace Statistics
00151 } // end namespace itk
00152 
00153 #endif
00154