latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiMeansFunctor.h 00027 * authors ....: Jochen Wickel 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 25.9.2000 00030 * revisions ..: $Id: ltiBoundsFunctor.h,v 1.7 2006/02/08 12:13:27 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_BOUNDS_FUNCTOR_H_ 00034 #define _LTI_BOUNDS_FUNCTOR_H_ 00035 00036 #include "ltiStatisticsFunctor.h" 00037 #include "ltiVector.h" 00038 #include "ltiMatrix.h" 00039 00040 // because of a stupid implementation of the C library in Visual C++, we 00041 // have to undefine min and max 00042 #undef min 00043 #undef max 00044 00045 namespace lti { 00046 /** 00047 * Boudaries of a hyperbox enclosing all points of a n-dimensional space. 00048 00049 * This functor computes for each "dimension" of points in a n-dimensional 00050 * space the extrema (i.e. minimum and maximum values). This way, 00051 * it computes the boundaries of a hyperbox where all points are contained. 00052 * 00053 * The points are given in form of vectors. If a matrix is given, the 00054 * parameter parameters::rowWise indicates if the vectors are taken from 00055 * the rows (true) or from the columns (false) of the matrix. 00056 * 00057 * Several methods besides the standard apply() are provided in order to 00058 * \e clip points into a given hyperbox. 00059 */ 00060 template <class T> class boundsFunctor : public statisticsFunctor { 00061 public: 00062 /** 00063 * the parameters for the class boundsFunctor 00064 */ 00065 class parameters : public statisticsFunctor::parameters { 00066 public: 00067 /** 00068 * default constructor 00069 */ 00070 parameters() : statisticsFunctor::parameters() { 00071 00072 rowWise=true; 00073 }; 00074 00075 /** 00076 * copy constructor 00077 * @param other the parameters object to be copied 00078 */ 00079 parameters(const parameters& other) 00080 : statisticsFunctor::parameters() { 00081 copy(other); 00082 }; 00083 00084 /** 00085 * destructor 00086 */ 00087 ~parameters() {}; 00088 00089 /** 00090 * returns name of this type 00091 */ 00092 const char* getTypeName() const { 00093 return "boundsFunctor::parameters"; 00094 }; 00095 00096 /** 00097 * copy the contents of a parameters object 00098 * @param other the parameters object to be copied 00099 * @return a reference to this parameters object 00100 */ 00101 parameters& copy(const parameters& other) { 00102 # ifndef _LTI_MSC_6 00103 // MS Visual C++ 6 is not able to compile this... 00104 statisticsFunctor::parameters::copy(other); 00105 # else 00106 // ...so we have to use this workaround. 00107 // Conditional on that, copy may not be virtual. 00108 statisticsFunctor::parameters& (statisticsFunctor::parameters::* p_copy) 00109 (const statisticsFunctor::parameters&) = 00110 statisticsFunctor::parameters::copy; 00111 (this->*p_copy)(other); 00112 # endif 00113 00114 rowWise=other.rowWise; 00115 00116 return *this; 00117 }; 00118 00119 /** 00120 * returns a pointer to a clone of the parameters 00121 */ 00122 virtual functor::parameters* clone() const { 00123 return new parameters(*this); 00124 }; 00125 00126 /** 00127 * If this flag is true, the mean computation will be row-wise, 00128 * i.e. the computation will use the rows of the matrix as row-vectors. 00129 * This is much faster than column-wise, since data do not have to be 00130 * copied. 00131 */ 00132 bool rowWise; 00133 }; 00134 00135 /** 00136 * default constructor 00137 */ 00138 boundsFunctor(); 00139 00140 /** 00141 * copy constructor 00142 * @param other the object to be copied 00143 */ 00144 boundsFunctor(const boundsFunctor& other); 00145 00146 /** 00147 * destructor 00148 */ 00149 virtual ~boundsFunctor(); 00150 00151 /** 00152 * returns the name of this type ("boundsFunctor") 00153 */ 00154 virtual const char* getTypeName() const; 00155 00156 /** 00157 * The result of this function depends on the value of 00158 * parameters.rowWise. If this parameter is true, the functor 00159 * will compute a vector, whose elements contain each the mean 00160 * of one column of the matrix (the computes the mean of the rows, 00161 * where each row is a data point in n-dimensional space. 00162 * if rowWise is false, the result vector contains the mean 00163 * of the columns of the matrix (each column a data point). 00164 * @param src matrix<T> with the source data. 00165 * @param min vector<T> where the minimum vector of the matrix will be 00166 * left 00167 * @param max vector<T> where the maximum vector of the matrix will be 00168 * left 00169 */ 00170 void apply(const matrix<T>& src, vector<T>& min, vector<T>& max) const; 00171 00172 /** 00173 * This function will compute a vector, whose elements contain 00174 * each the minimum of one column of the matrix (this computes the 00175 * n-dimensional equivalent of a lower-left corner of the bounding 00176 * box of a data set, where each row is a data point in 00177 * n-dimensional space). 00178 * @param src matrix<T> with the source data. 00179 * @param dest matrix<T> where the result will be left. */ 00180 void minOfRows(const matrix<T>& src, vector<T>& dest) const; 00181 00182 /** 00183 * Alias for minOfRows 00184 * @param src matrix<T> with the source data. 00185 * @param dest matrix<T> where the result will be left. 00186 */ 00187 inline void minOfRowVectors(const matrix<T>& src, vector<T>& dest) const { 00188 minOfRows(src,dest); 00189 } 00190 00191 /** 00192 * This function 00193 * will compute a vector, whose elements contain each the maximum 00194 * of one column of the matrix (this computes the n-dimensional 00195 * equivalent of an upper-right corner of the bounding box of 00196 * a data set, where each row is a data point in n-dimensional space). 00197 * @param src matrix<T> with the source data. 00198 * @param dest matrix<T> where the result will be left. 00199 */ 00200 void maxOfRows(const matrix<T>& src, vector<T>& dest) const; 00201 00202 /** 00203 * Alias for maxOfRows 00204 * @param src matrix<T> with the source data. 00205 * @param dest matrix<T> where the result will be left. 00206 */ 00207 inline void maxOfRowVectors(const matrix<T>& src, vector<T>& dest) const { 00208 maxOfRows(src,dest); 00209 } 00210 00211 /** 00212 * This function 00213 * will compute a vector, whose elements contain each the minimum 00214 * of one row of the matrix (this computes the n-dimensional 00215 * equivalent of a lower-left corner of the bounding box of 00216 * a data set, where each column is a data point in n-dimensional space). 00217 * @param src matrix<T> with the source data. 00218 * @param dest matrix<T> where the result will be left. 00219 */ 00220 void minOfColumns(const matrix<T>& src, vector<T>& dest) const; 00221 00222 /** 00223 * Alias for minOfColumns 00224 * @param src matrix<T> with the source data. 00225 * @param dest matrix<T> where the result will be left. 00226 */ 00227 inline void minOfColumnVectors(const matrix<T>& src, 00228 vector<T>& dest) const { 00229 minOfColumns(src,dest); 00230 } 00231 00232 /** 00233 * This function 00234 * will compute a vector, whose elements contain each the maximum 00235 * of one row of the matrix (this computes the n-dimensional 00236 * equivalent of an upper-right corner of the bounding box of 00237 * a data set, where each column is a data point in n-dimensional space). 00238 * @param src matrix<T> with the source data. 00239 * @param dest matrix<T> where the result will be left. 00240 */ 00241 void maxOfColumns(const matrix<T>& src, vector<T>& dest) const; 00242 00243 /** 00244 * Alias for maxOfColumns 00245 * @param src matrix<T> with the source data. 00246 * @param dest matrix<T> where the result will be left. 00247 */ 00248 inline void maxOfColumnVectors(const matrix<T>& src, 00249 vector<T>& dest) const { 00250 maxOfColumns(src,dest); 00251 } 00252 00253 /** 00254 * This function is a combination of minOfRows and maxOfRows 00255 * @param src matrix<T> with the source data. 00256 * @param min vector<T> where the minimum will be left. 00257 * @param max vector<T> where the maximum will be left. 00258 */ 00259 void boundsOfRows(const matrix<T>& src, vector<T>& min, 00260 vector<T>& max) const; 00261 00262 /** 00263 * Alias for boundsOfRows 00264 * @param src matrix<T> with the source data. 00265 * @param min vector<T> where the minimum will be left. 00266 * @param max vector<T> where the maximum will be left. 00267 */ 00268 inline void boundsOfRowVectors(const matrix<T>& src, vector<T>& min, 00269 vector<T>& max) const { 00270 boundsOfRows(src,min,max); 00271 } 00272 00273 /** 00274 * This function is a combination of minOfColumns and maxOfColumns 00275 * @param src matrix<T> with the source data. 00276 * @param min vector<T> where the minimum will be left. 00277 * @param max vector<T> where the maximum will be left. 00278 */ 00279 void boundsOfColumns(const matrix<T>& src, 00280 vector<T>& min, vector<T>& max) const; 00281 00282 /** 00283 * Alias for boundsOfColumns 00284 * @param src matrix<T> with the source data. 00285 * @param min vector<T> where the minimum will be left. 00286 * @param max vector<T> where the maximum will be left. 00287 */ 00288 inline void boundsOfColumnVectors(const matrix<T>& src, vector<T>& min, 00289 vector<T>& max) const { 00290 boundsOfColumns(src,min,max); 00291 } 00292 00293 /** 00294 * Computes a vector which contains the minimum elements of a and b 00295 * @param a vector<T> first operand 00296 * @param b vector<T> second operand 00297 * @param dest vector<T> which will receive the element-wise minimum 00298 * of both operands 00299 */ 00300 void min(const vector<T> &a, const vector<T> &b, 00301 vector<T>& dest) const; 00302 00303 /** 00304 * Computes a vector which contains the maximum elements of a and b 00305 * @param a vector<T> first operand 00306 * @param b vector<T> second operand 00307 * @param dest vector<T> which will receive the element-wise maximum 00308 * of both operands 00309 */ 00310 void max(const vector<T> &a, const vector<T> &b, 00311 vector<T>& dest) const; 00312 00313 00314 /** 00315 * Clips the values of the vector a to lowerBounds and upperBounds. 00316 * For each vector element a[i], 00317 * if lowerBounds[i] <= a[i] <= higherBounds[i], 00318 * the value of a[i] remains unchanged. If a[i] < lowerBounds[i], 00319 * a[i] will be set to lowerBounds[i]. Analagous with upperBounds. 00320 * @param a vector<T> to be clipped. 00321 * @param lowerBounds vector<T> which contains the smallest permitted 00322 * elements. 00323 * @param upperBounds vector<T> which contains the largest permitted 00324 * elements. 00325 */ 00326 void clip(vector<T> &a, 00327 const vector<T>& lowerBounds, 00328 const vector<T>& upperBounds) const; 00329 00330 /** 00331 * Clips the values of the matrix a to lowerBounds and upperBounds. 00332 * For each matrix element a[i][j], 00333 * if lowerBounds[i][j] <= a[i][j] <= higherBounds[i][j], 00334 * the value of a[i][j] remains unchanged. If a[i][j] < lowerBounds[i][j], 00335 * a[i][j] will be set to lowerBounds[i][j]. Analagous with upperBounds. 00336 * @param a matrix<T> to be clipped. 00337 * @param lowerBounds matrix<T> which contains the smallest permitted 00338 * elements. 00339 * @param upperBounds matrix<T> which contains the largest permitted 00340 * elements. 00341 */ 00342 void clip(matrix<T> &a, 00343 const matrix<T>& lowerBounds, 00344 const matrix<T>& upperBounds) const; 00345 00346 /** 00347 * copy data of "other" functor. 00348 * @param other the functor to be copied 00349 * @return a reference to this functor object 00350 */ 00351 boundsFunctor& copy(const boundsFunctor& other); 00352 00353 /** 00354 * returns a pointer to a clone of this functor. 00355 */ 00356 virtual functor* clone() const; 00357 00358 /** 00359 * returns used parameters 00360 */ 00361 const parameters& getParameters() const; 00362 }; 00363 } 00364 00365 #include "ltiBoundsFunctor_template.h" 00366 00367 #endif