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 cvrDistanceFunctor.h 00044 * This file contains the class distanceFunctor, the base 00045 * class for calculation of distances between two vectors or 00046 * matrices. 00047 * \author Jochen Wickel 00048 * \date 28.06.2000 00049 * 00050 * $Id: cvrDistanceFunctor.h,v 1.2 2005/06/22 15:26:41 doerfler Exp $ 00051 */ 00052 00053 #ifndef _CVR_DISTANCE_FUNCTOR_H_ 00054 #define _CVR_DISTANCE_FUNCTOR_H_ 00055 00056 #include "cvrFunctor.h" 00057 #include "cvrMath.h" 00058 #include "cvrVector.h" 00059 #include "cvrMatrix.h" 00060 00061 namespace cvr { 00062 00063 /** 00064 * This class is the base class for all functors which compute 00065 * distances between two vectors or matrices. 00066 * 00067 * @see similarityFunctor 00068 * 00069 * Be careful with the use of the parameters::rowWise. It indicates 00070 * if the matrix should be considered as having row vectors (true) of 00071 * columns vectors (false). Depending on that the computations will be 00072 * very different. 00073 */ 00074 template <typename T> 00075 class distanceFunctor: public functor { 00076 public: 00077 /** 00078 * the parameters for the class distanceFunctor 00079 */ 00080 class parameters : public functor::parameters { 00081 public: 00082 /** 00083 * default constructor 00084 */ 00085 parameters(); 00086 00087 /** 00088 * copy constructor 00089 * @param other the parameters object to be copied 00090 */ 00091 parameters(const parameters& other); 00092 00093 /** 00094 * destructor 00095 */ 00096 virtual ~parameters(); 00097 00098 /** 00099 * copy the contents of a parameters object 00100 * @param other the parameters object to be copied 00101 * @return a reference to this parameters object 00102 */ 00103 parameters& copy(const parameters& other); 00104 00105 /** 00106 * Return the name of the class 00107 */ 00108 virtual const std::string& name() const; 00109 00110 /** 00111 * returns a pointer to a clone of the parameters 00112 */ 00113 virtual parameters* clone() const; 00114 00115 /** 00116 * returns a pointer to a new instance of the parameters 00117 */ 00118 virtual parameters* newInstance() const; 00119 00120 /** 00121 * write the parameters in the given ioHandler 00122 * @param handler the ioHandler to be used 00123 * @param complete if true (the default) the enclosing begin/end will 00124 * be also written, otherwise only the data block will be written. 00125 * @return true if write was successful 00126 */ 00127 bool write(ioHandler& handler, 00128 const bool complete) const; 00129 00130 /** 00131 * read the parametersfrom the given ioHandler 00132 * @param handler the ioHandler to be used 00133 * @param complete if true (the default) the enclosing begin/end will 00134 * be also written, otherwise only the data block will be written. 00135 * @return true if write was successful 00136 */ 00137 bool read(ioHandler& handler, 00138 const bool complete); 00139 00140 /** 00141 * determine whether distances between the row vectors in a 00142 * matrix (true) or the column vectors in it (false) should be 00143 * calculated. 00144 * 00145 * Default value: true 00146 */ 00147 bool rowWise; 00148 00149 }; 00150 00151 /** 00152 * default constructor 00153 */ 00154 distanceFunctor(); 00155 00156 /** 00157 * copy constructor 00158 * @param other the object to be copied 00159 */ 00160 distanceFunctor(const distanceFunctor<T>& other); 00161 00162 /** 00163 * destructor 00164 */ 00165 virtual ~distanceFunctor(); 00166 00167 /** 00168 * returns the distance between the vectors a and b. This is a 00169 * shortcut for apply(const vector<T>&, const vector<T>&, T&). 00170 * 00171 * @param a the first vector<T> 00172 * @param b the second vector<T> 00173 * @return the distance between the vectors 00174 */ 00175 virtual T distance(const vector<T>& a, const vector<T>& b) const; 00176 00177 /** 00178 * returns something like the distance between the matrices a and 00179 * b: both matrices are seen as vectors. This is a shortcut for 00180 * apply(const matrix<T>&, const matrix<T>&, T&). 00181 * 00182 * @param a the first matrix<T> 00183 * @param b the second matrix<T> 00184 * @return the 'distance' between the matrices 00185 */ 00186 virtual T distance(const matrix<T>& a, const matrix<T>& b) const; 00187 00188 /** 00189 * calculate the distance between the vectors a and b. 00190 * 00191 * @param a the first vector<T> 00192 * @param b the second vector<T> 00193 * @param dist the distance between the vectors 00194 * @return false on error -> see status string 00195 */ 00196 virtual bool apply(const vector<T>& a, const vector<T>& b, 00197 T& dist) const=0; 00198 00199 /** 00200 * calculate the distances between the rows or columns of the 00201 * matrices a and b, determined by the parameter rowWise. 00202 * 00203 * @param a the first vector<T> 00204 * @param b the second vector<T> 00205 * @param dists the distances between the matrices 00206 * @return false on error -> see status string 00207 */ 00208 virtual bool apply(const matrix<T>& a, const matrix<T>& b, 00209 vector<T>& dists) const=0; 00210 00211 /** 00212 * Calculate the distance between each row or column of m 00213 * depending on the value of rowWise and the vector v. 00214 * 00215 * @param m the matrix<T> 00216 * @param v the vector to be compared with 00217 * @param dest the vector with the distances to the vector v 00218 * @return false on error 00219 */ 00220 virtual bool apply(const matrix<T>& m, const vector<T>& v, 00221 vector<T>& dest) const=0; 00222 00223 /** 00224 * calculate something like the distance between the matrices a and b: 00225 * both matrices are seen as vectors. 00226 * 00227 * @param a the first matrix<T> 00228 * @param b the second matrix<T> 00229 * @param dist the 'distance' between the matrices 00230 * @return false on error -> see status string 00231 */ 00232 virtual bool apply(const matrix<T>& a, const matrix<T>& b, 00233 T& dist) const=0; 00234 00235 /** 00236 * copy data of "other" functor. 00237 * @param other the functor to be copied 00238 * @return a reference to this functor object 00239 */ 00240 distanceFunctor<T>& copy(const distanceFunctor<T>& other); 00241 00242 /** 00243 * Return the name of the class 00244 */ 00245 virtual const std::string& name() const; 00246 00247 /** 00248 * returns a pointer to a clone of this functor. 00249 */ 00250 virtual distanceFunctor<T>* clone() const=0; 00251 00252 /** 00253 * returns a pointer to a new instance of this functor. 00254 */ 00255 virtual distanceFunctor<T>* newInstance() const=0; 00256 00257 /** 00258 * returns used parameters 00259 */ 00260 const parameters& getParameters() const; 00261 }; 00262 00263 } 00264 00265 #include "cvrDistanceFunctor_template.h" 00266 00267 #endif 00268 00269