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 .......: ltiMapperFunctor.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 10.7.2000 00030 * revisions ..: $Id: ltiMapperFunctor.h,v 1.7 2006/02/08 12:32:50 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_MAPPER_FUNCTOR_H_ 00034 #define _LTI_MAPPER_FUNCTOR_H_ 00035 00036 #include "ltiObject.h" 00037 #include "ltiFunctor.h" 00038 #include "ltiHistogram.h" 00039 00040 namespace lti { 00041 00042 /** 00043 * This class maps a vector in a n-dimensional space into another vector 00044 * in a m-dimensional space. The main use of the "mappers" is to 00045 * map a n-dimensional space in the integers cell space required by the 00046 * histograms. 00047 * 00048 * The type of the input space is <code>Tin</code>, and the type of the 00049 * output space is <code>Tout</code> (default value <code>int</code>. 00050 * 00051 * This is an abstract class. For an example see lti::linearMapper 00052 * 00053 * There are only on-copy apply-members. 00054 */ 00055 template <class Tin,class Tout=int> 00056 class mapperFunctor : public functor { 00057 public: 00058 /** 00059 * the parameters for the class mapperFunctor 00060 */ 00061 class parameters : public functor::parameters { 00062 public: 00063 /** 00064 * default constructor 00065 */ 00066 parameters() : functor::parameters() { 00067 }; 00068 00069 /** 00070 * copy constructor 00071 * @param other the parameters object to be copied 00072 */ 00073 parameters(const parameters& other) 00074 : functor::parameters() { 00075 copy(other); 00076 }; 00077 00078 /** 00079 * destructor 00080 */ 00081 ~parameters() {}; 00082 00083 /** 00084 * returns name of this type 00085 */ 00086 const char* getTypeName() const { 00087 return "mapperFunctor::parameters"; 00088 }; 00089 00090 /** 00091 * copy the contents of a parameters object 00092 * @param other the parameters object to be copied 00093 * @return a reference to this parameters object 00094 */ 00095 parameters& copy(const parameters& other) { 00096 # ifndef _LTI_MSC_6 00097 // MS Visual C++ 6 is not able to compile this... 00098 functor::parameters::copy(other); 00099 # else 00100 // ...so we have to use this workaround. 00101 // Conditional on that, copy may not be virtual. 00102 functor::parameters& (functor::parameters::* p_copy) 00103 (const functor::parameters&) = 00104 functor::parameters::copy; 00105 (this->*p_copy)(other); 00106 # endif 00107 00108 lowerLimitsInput.copy(other.lowerLimitsInput); 00109 lowerLimitsOutput.copy(other.lowerLimitsOutput); 00110 upperLimitsInput.copy(other.upperLimitsInput); 00111 upperLimitsOutput.copy(other.upperLimitsOutput); 00112 00113 return *this; 00114 }; 00115 00116 /** 00117 * returns a pointer to a clone of the parameters 00118 */ 00119 virtual functor::parameters* clone() const { 00120 return new parameters(*this); 00121 }; 00122 00123 /** 00124 * use the description of a histogram to initialize 00125 * the parameter members. 00126 * 00127 * The size of the four limits-vectors will be changed to the 00128 * dimensionality of the histogram, and the output range will 00129 * be set to the valid range of the histogram. The input intervall 00130 * will be left uninitialized! (normally you will use fill to set 00131 * the values you want here: see lti::ltiLinearMapperFunctor for an 00132 * example) 00133 */ 00134 void generateFrom(const histogram& histo) { 00135 lowerLimitsInput.resize(histo.dimensions(),Tin(0.0),false); 00136 upperLimitsInput.resize(histo.dimensions(),Tout(1.0),false); 00137 lowerLimitsOutput.castFrom(histo.getFirstCell()); 00138 upperLimitsOutput.castFrom(histo.getLastCell()); 00139 }; 00140 00141 /** 00142 * a vector with the input dimensionality, which contains the 00143 * lower bounds of the input vector space. 00144 */ 00145 vector<Tin> lowerLimitsInput; 00146 00147 /** 00148 * a vector with the input dimensionality, which contains the 00149 * upper bounds of the input vector space 00150 */ 00151 vector<Tin> upperLimitsInput; 00152 00153 /** 00154 * a vector with the output dimensionality, which contains the 00155 * lower bounds of the output vector space. 00156 */ 00157 vector<Tout> lowerLimitsOutput; 00158 00159 /** 00160 * a vector with the output dimensionality, which contains the 00161 * upper bounds of the output vector space 00162 */ 00163 vector<Tout> upperLimitsOutput; 00164 }; 00165 00166 /** 00167 * default constructor 00168 */ 00169 mapperFunctor(); 00170 00171 /** 00172 * copy constructor 00173 * @param other the object to be copied 00174 */ 00175 mapperFunctor(const mapperFunctor& other); 00176 00177 /** 00178 * destructor 00179 */ 00180 virtual ~mapperFunctor(); 00181 00182 /** 00183 * returns the name of this type ("mapperFunctor") 00184 */ 00185 virtual const char* getTypeName() const; 00186 00187 /** 00188 * Map the input vector src in the output vector dest. 00189 * @param src vector<Tin> with the source data. 00190 * @param dest vector<Tout> where the result will be left. 00191 * @result a reference to the <code>dest</code>. 00192 */ 00193 virtual vector<Tout>& apply(const vector<Tin>& src, 00194 vector<Tout>& dest) const; 00195 00196 /** 00197 * For the two dimensional case, maps a two dimensional vector in a 00198 * integer vector coded as a point 00199 * @param src ivector with the source data. 00200 * @param dest point where the result will be left. 00201 * @result a reference to the <code>dest</code>. 00202 */ 00203 point& apply(const vector<Tin>& src,point& dest) const; 00204 00205 /** 00206 * For the two dimensional case, maps a two dimensional vector in a 00207 * integer vector coded as a point 00208 * @param src0 the first element of the input vector 00209 * @param src1 the second element of the input vector 00210 * @param dest point where the result will be left. 00211 * @result a reference to the <code>dest</code>. 00212 */ 00213 point& apply(const Tin& src0,const Tin& src1, 00214 point& dest) const; 00215 00216 00217 /** 00218 * For the two dimensional case, maps a two dimensional integer vector in a 00219 * integer vector coded both as points 00220 * @param src the original point 00221 * @param dest point where the result will be left. 00222 * @result a reference to the <code>dest</code>. 00223 */ 00224 point& apply(const point& src,point& dest) const; 00225 00226 /** 00227 * For the one dimensional case, maps the input vector into a one 00228 * dimensional vector of type Tout. 00229 * @param src int with the source data. 00230 * @param dest int where the result will be left. 00231 * @result a reference to the <code>dest</code>. 00232 */ 00233 Tout& apply(const vector<Tin>& src,Tout& dest) const; 00234 00235 /** 00236 * For the one dimensional case, maps a one dimensional vector in a 00237 * output vector 00238 * @param src one-dimensional vector with the source data. 00239 * @param dest one-dimensional vector where the result will be left. 00240 * @result a reference to the <code>dest</code>. 00241 */ 00242 Tout& apply(const Tin& src,Tout& dest) const; 00243 00244 /** 00245 * copy data of "other" functor. 00246 * @param other the functor to be copied 00247 * @return a reference to this functor object 00248 */ 00249 mapperFunctor& copy(const mapperFunctor& other); 00250 00251 /** 00252 * returns a pointer to a clone of this functor. 00253 */ 00254 virtual functor* clone() const; 00255 00256 /** 00257 * returns used parameters 00258 */ 00259 const parameters& getParameters() const; 00260 }; 00261 } 00262 00263 #include "ltiMapperFunctor_template.h" 00264 00265 #endif