last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998 - 2005 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 00042 /** 00043 * \file cvrEuclideanDistanceFunctor.h 00044 * This file contains the class euclideandistanceFunctor, 00045 * a class for calculating the L2 distance between two vectors or 00046 * matrices. 00047 * \author Jochen Wickel 00048 * \date 28.06.2000 00049 * 00050 * $Id: cvrEuclideanDistanceFunctor.h,v 1.1 2005/03/29 13:26:46 doerfler Exp $ 00051 */ 00052 00053 #ifndef _CVR_EUCLIDEAN_DISTANCE_FUNCTOR_H_ 00054 #define _CVR_EUCLIDEAN_DISTANCE_FUNCTOR_H_ 00055 00056 #include "cvrDistanceFunctor.h" 00057 #include "cvrMath.h" 00058 00059 namespace cvr { 00060 00061 /** 00062 * This class is the base class for all functors which compute 00063 * distances between two vectors or matrices. 00064 * 00065 * @see similarityFunctor 00066 * 00067 * Be careful with the use of the parameters::rowWise. It indicates 00068 * if the matrix should be considered as having row vectors (true) of 00069 * columns vectors (false). Depending on that the computations will be 00070 * very different. 00071 */ 00072 template <typename T> 00073 class euclideanDistanceFunctor : public distanceFunctor<T> { 00074 public: 00075 00076 /** 00077 * The parameters of euclideanDistanceFunctor are equivalent to 00078 * those of distanceFunctor 00079 */ 00080 typedef typename distanceFunctor<T>::parameters parameters; 00081 00082 /** 00083 * default constructor 00084 */ 00085 euclideanDistanceFunctor(); 00086 00087 /** 00088 * copy constructor 00089 * @param other the object to be copied 00090 */ 00091 euclideanDistanceFunctor(const euclideanDistanceFunctor<T>& other); 00092 00093 /** 00094 * destructor 00095 */ 00096 virtual ~euclideanDistanceFunctor(); 00097 00098 00099 /** 00100 * calculate the distance between the vectors a and b. By default 00101 * uses the distance member function. 00102 * 00103 * @param a the first vector<T> 00104 * @param b the second vector<T> 00105 * @param dist the distance between the vectors 00106 * @return false on error -> see status string 00107 */ 00108 virtual bool apply(const vector<T>& a, const vector<T>& b, 00109 T& dist) const; 00110 00111 /** 00112 * calculate the distances between the rows or columns of the 00113 * matrices a and b, determined by the parameters rowWise. 00114 * By default uses the distance() member function. 00115 * 00116 * @param a the first vector<T> 00117 * @param b the second vector<T> 00118 * @param dists the distances between the matrices 00119 * @return false on error -> see status string 00120 */ 00121 virtual bool apply(const matrix<T>& a, const matrix<T>& b, 00122 vector<T>& dists) const; 00123 00124 /** 00125 * Calculate the distance between each row or column of m 00126 * depending on the value of rowWise and the vector v. 00127 * By default uses the distance() member function. 00128 * 00129 * @param m the matrix<T> 00130 * @param v the vector to be compared with 00131 * @param dest the vector with the distances to the vector v 00132 * @return false on error 00133 */ 00134 virtual bool apply(const matrix<T>& m, const vector<T>& v, 00135 vector<T>& dest) const; 00136 00137 /** 00138 * calculate something like the distance between the matrices a and b: 00139 * both matrices are seen as vectors. 00140 * By default uses the distance() member function. 00141 * 00142 * @param a the first matrix<T> 00143 * @param b the second matrix<T> 00144 * @param dist the 'distance' between the matrices 00145 * @return false on error -> see status string 00146 */ 00147 virtual bool apply(const matrix<T>& a, const matrix<T>& b, 00148 T& dist) const; 00149 00150 /** 00151 * copy data of "other" functor. 00152 * @param other the functor to be copied 00153 * @return a reference to this functor object 00154 */ 00155 euclideanDistanceFunctor<T>& 00156 copy(const euclideanDistanceFunctor<T>& other); 00157 00158 /** 00159 * returns a pointer to a clone of this functor. 00160 */ 00161 virtual euclideanDistanceFunctor<T>* clone() const; 00162 00163 /** 00164 * returns a pointer to a new instance of this functor. 00165 */ 00166 virtual euclideanDistanceFunctor<T>* newInstance() const; 00167 00168 /** 00169 * Return the name of the class 00170 */ 00171 virtual const std::string& name() const; 00172 00173 /** 00174 * returns used parameters 00175 */ 00176 const parameters& getParameters() const; 00177 }; 00178 00179 } 00180 00181 // #include "cvrEuclideanDistanceFunctor_template.h" 00182 00183 #endif 00184 00185