ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDistanceMetric.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 __itkDistanceMetric_h
00019 #define __itkDistanceMetric_h
00020 
00021 #include "itkFunctionBase.h"
00022 #include "itkMeasurementVectorTraits.h"
00023 
00024 namespace itk
00025 {
00026 namespace Statistics
00027 {
00046 template< class TVector >
00047 class ITK_EXPORT DistanceMetric:public FunctionBase< TVector, double  >
00048 {
00049 public:
00051   typedef DistanceMetric                  Self;
00052   typedef FunctionBase< TVector, double > Superclass;
00053   typedef SmartPointer< Self >            Pointer;
00054   typedef SmartPointer< const Self >      ConstPointer;
00055 
00057   typedef TVector MeasurementVectorType;
00058 
00063   typedef unsigned int MeasurementVectorSizeType;
00064 
00066   itkTypeMacro(DistanceMetric, FunctionBase);
00067 
00068   typedef Array< double > OriginType;
00069 
00076   void SetOrigin(const OriginType & x);
00077 
00078   itkGetConstReferenceMacro(Origin, OriginType);
00079 
00082   virtual double Evaluate(const MeasurementVectorType & x) const = 0;
00083 
00089   virtual double Evaluate(const MeasurementVectorType & x1,
00090                           const MeasurementVectorType & x2) const = 0;
00091 
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 \
00125                            vector size of a non-resizable vector type"                                                  );
00126         }
00127       }
00128   }
00129 
00131   itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
00132 protected:
00133   DistanceMetric();
00134   virtual ~DistanceMetric() {}
00135   void PrintSelf(std::ostream & os, Indent indent) const;
00137 
00138 private:
00139 
00140   OriginType m_Origin;
00141 
00143   MeasurementVectorSizeType m_MeasurementVectorSize;
00144 };  // end of class
00145 } // end of namespace Statistics
00146 } // end of namespace itk
00147 
00148 #ifndef ITK_MANUAL_INSTANTIATION
00149 #include "itkDistanceMetric.hxx"
00150 #endif
00151 
00152 #endif
00153