latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiScalarValuedInterpolation.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 12.6.2001 00030 * revisions ..: $Id: ltiScalarValuedInterpolation.h,v 1.14 2006/09/05 10:41:26 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_SCALARVALUEDINTERPOLATION_H_ 00034 #define _LTI_SCALARVALUEDINTERPOLATION_H_ 00035 00036 #include "ltiImage.h" 00037 #include "ltiVector.h" 00038 #include "ltiEquallySpacedSamplesInterpolator.h" 00039 00040 namespace lti { 00041 /** 00042 * This abstract class parents all interpolation functors, which are used 00043 * to interpolate the values between the pixels or elements of vectors 00044 * and matrices, espacially images. 00045 * 00046 * The type T of the template is the type of the elements of the vector 00047 * or matrix used. 00048 */ 00049 template <class T> 00050 class scalarValuedInterpolation : public equallySpacedSamplesInterpolator { 00051 public: 00052 00053 /** 00054 * Definition of the type of the elements in the applys (given type T) 00055 */ 00056 typedef T value_type; 00057 00058 /** 00059 * the parameters for the class scalarValuedInterpolation 00060 */ 00061 class parameters : public equallySpacedSamplesInterpolator::parameters { 00062 public: 00063 /** 00064 * Default constructor 00065 */ 00066 parameters() : equallySpacedSamplesInterpolator::parameters() { 00067 }; 00068 00069 /** 00070 * Create constructor with given boundary type 00071 */ 00072 parameters(const eBoundaryType btype) 00073 : equallySpacedSamplesInterpolator::parameters(btype) { 00074 }; 00075 00076 /** 00077 * copy constructor 00078 * @param other the parameters object to be copied 00079 */ 00080 parameters(const parameters& other) 00081 : equallySpacedSamplesInterpolator::parameters() { 00082 copy(other); 00083 }; 00084 00085 /** 00086 * destructor 00087 */ 00088 ~parameters() { 00089 }; 00090 00091 /** 00092 * returns name of this type 00093 */ 00094 const char* getTypeName() const { 00095 return "scalarValuedInterpolation::parameters"; 00096 }; 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 # ifndef _LTI_MSC_6 00105 // MS Visual C++ 6 is not able to compile this... 00106 equallySpacedSamplesInterpolator::parameters::copy(other); 00107 # else 00108 // ...so we have to use this workaround. 00109 // Conditional on that, copy may not be virtual. 00110 equallySpacedSamplesInterpolator::parameters& 00111 (equallySpacedSamplesInterpolator::parameters::* p_copy) 00112 (const equallySpacedSamplesInterpolator::parameters&) = 00113 equallySpacedSamplesInterpolator::parameters::copy; 00114 (this->*p_copy)(other); 00115 # endif 00116 00117 return *this; 00118 }; 00119 00120 /** 00121 * copy the contents of a parameters object 00122 * @param other the parameters object to be copied 00123 * @return a reference to this parameters object 00124 */ 00125 parameters& operator=(const parameters& other) { 00126 return copy(other); 00127 }; 00128 00129 /** 00130 * returns a pointer to a clone of the parameters 00131 */ 00132 virtual functor::parameters* clone() const { 00133 return new parameters(*this); 00134 } 00135 00136 # ifndef _LTI_MSC_6 00137 /** 00138 * write the parameters in the given ioHandler 00139 * @param handler the ioHandler to be used 00140 * @param complete if true (the default) the enclosing begin/end will 00141 * be also written, otherwise only the data block will be written. 00142 * @return true if write was successful 00143 */ 00144 bool write(ioHandler& handler,const bool complete) const 00145 # else 00146 /** 00147 * this function is required by MSVC only, as a workaround for a 00148 * very awful bug, which exists since MSVC V.4.0, and still by 00149 * V.6.0 with all bugfixes (so called "service packs") remains 00150 * there... This method is also public due to another bug, so please 00151 * NEVER EVER call this method directly: use write() instead 00152 */ 00153 bool writeMS(ioHandler& handler,const bool complete) const 00154 # endif 00155 { 00156 bool b = true; 00157 if (complete) { 00158 b = handler.writeBegin(); 00159 } 00160 00161 if (b) { 00162 00163 } 00164 00165 # ifndef _LTI_MSC_6 00166 // This is the standard C++ code, which MS Visual C++ 6 is not able to 00167 // compile... 00168 b = b && equallySpacedSamplesInterpolator::parameters::write(handler,false); 00169 # else 00170 bool (equallySpacedSamplesInterpolator::parameters::* p_writeMS)(ioHandler&, 00171 const bool) const = 00172 equallySpacedSamplesInterpolator::parameters::writeMS; 00173 b = b && (this->*p_writeMS)(handler,false); 00174 # endif 00175 00176 if (complete) { 00177 b = b && handler.writeEnd(); 00178 } 00179 00180 return b; 00181 } 00182 00183 # ifdef _LTI_MSC_6 00184 /** 00185 * write the parameters in the given ioHandler 00186 * @param handler the ioHandler to be used 00187 * @param complete if true (the default) the enclosing begin/end will 00188 * be also written, otherwise only the data block will be written. 00189 * @return true if write was successful 00190 */ 00191 bool write(ioHandler& handler,const bool complete) const { 00192 // ...we need this workaround to cope with another really 00193 // awful MSVC bug. 00194 return writeMS(handler,complete); 00195 } 00196 # endif 00197 00198 # ifndef _LTI_MSC_6 00199 /** 00200 * read the parameters from the given ioHandler 00201 * @param handler the ioHandler to be used 00202 * @param complete if true (the default) the enclosing begin/end will 00203 * be also read, otherwise only the data block will be read. 00204 * @return true if write was successful 00205 */ 00206 bool read(ioHandler& handler,const bool complete) 00207 # else 00208 /** 00209 * this function is required by MSVC only, as a workaround for a 00210 * very awful bug, which exists since MSVC V.4.0, and still by 00211 * V.6.0 with all bugfixes (so called "service packs") remains 00212 * there... This method is also public due to another bug, so please 00213 * NEVER EVER call this method directly: use read() instead 00214 */ 00215 bool readMS(ioHandler& handler,const bool complete) 00216 # endif 00217 { 00218 bool b = true; 00219 if (complete) { 00220 b = handler.readBegin(); 00221 } 00222 00223 if (b) { 00224 00225 } 00226 00227 # ifndef _LTI_MSC_6 00228 // This is the standard C++ code, which MS Visual C++ 6 is not able to 00229 // compile... 00230 b = b && equallySpacedSamplesInterpolator::parameters::read(handler,false); 00231 # else 00232 bool (equallySpacedSamplesInterpolator::parameters::* p_readMS)(ioHandler&,const bool) = 00233 equallySpacedSamplesInterpolator::parameters::readMS; 00234 b = b && (this->*p_readMS)(handler,false); 00235 # endif 00236 00237 if (complete) { 00238 b = b && handler.readEnd(); 00239 } 00240 00241 return b; 00242 } 00243 00244 # ifdef _LTI_MSC_6 00245 /** 00246 * read the parameters from the given ioHandler 00247 * @param handler the ioHandler to be used 00248 * @param complete if true (the default) the enclosing begin/end will 00249 * be also read, otherwise only the data block will be read. 00250 * @return true if write was successful 00251 */ 00252 bool read(ioHandler& handler,const bool complete) { 00253 // ...we need this workaround to cope with another really awful MSVC 00254 // bug. 00255 return readMS(handler,complete); 00256 } 00257 # endif 00258 // ------------------------------------------------ 00259 // the parameters 00260 // ------------------------------------------------ 00261 00262 // no parameters yet 00263 00264 }; 00265 00266 /** 00267 * default constructor 00268 */ 00269 scalarValuedInterpolation(); 00270 00271 /** 00272 * copy constructor 00273 * @param other the object to be copied 00274 */ 00275 scalarValuedInterpolation(const scalarValuedInterpolation& other); 00276 00277 /** 00278 * destructor 00279 */ 00280 virtual ~scalarValuedInterpolation(); 00281 00282 /** 00283 * returns the name of this type ("scalarValuedInterpolation") 00284 */ 00285 virtual const char* getTypeName() const; 00286 00287 /** 00288 * all the next apply methods will return the interpolated values of the 00289 * given vector. 00290 */ 00291 virtual bool use(const vector<T>& vct); 00292 00293 /** 00294 * all the next apply methods will return the interpolated values of the 00295 * given matrix. 00296 */ 00297 virtual bool use(const matrix<T>& vct); 00298 00299 /** 00300 * Returns the interpolated value of the vector at the real valued 00301 * position x. 00302 * @param src vector<T> with the source data. 00303 * @param x the real valued position to be interpolated. 00304 * @return the interpolated value of the vector. 00305 */ 00306 virtual T apply(const vector<T>& src,const float& x) const = 0; 00307 00308 /** 00309 * Returns the interpolated value of the vector specified with 00310 * use() at the real valued position x. 00311 * @param x the real valued position to be interpolated. 00312 * @return the interpolated value of the vector. */ 00313 virtual T apply(const float& x) const = 0; 00314 00315 /** 00316 * Returns the interpolated value of the matrix at the real valued 00317 * position (row,col). 00318 * 00319 * @param src matrix<T> with the source data. 00320 * @param row which row 00321 * @param col which column 00322 * @return the interpolated value of the matrix. 00323 */ 00324 virtual T apply(const matrix<T>& src, 00325 const float& row, 00326 const float& col) const = 0; 00327 00328 /** 00329 * Returns the interpolated value of the matrix at the real valued 00330 * position p. 00331 * 00332 * @param src matrix<T> with the source data. 00333 * @param p the real valued position to be interpolated. 00334 * @return the interpolated value of the matrix. 00335 */ 00336 virtual T apply(const matrix<T>& src,const tpoint<float>& p) const = 0; 00337 00338 /** 00339 * Returns the interpolated value of the matrix specified with 00340 * use() at the real valued position (row,col). 00341 * 00342 * @param row which row 00343 * @param col which column 00344 * @return the interpolated value of the matrix. */ 00345 virtual T apply(const float& row, const float& col) const = 0; 00346 00347 /** 00348 * Returns the interpolated value of the matrix specified with 00349 * use() at the real valued position p. 00350 * 00351 * @param p the real valued position to be interpolated. 00352 * @return the interpolated value of the matrix. 00353 */ 00354 virtual T apply(const tpoint<float>& p) const = 0; 00355 00356 00357 /** 00358 * Returns the interpolated value of the matrix at the real valued 00359 * position (row,col). This method is NOT virtual and can be used 00360 * if this interpolation type is used as template parameter in time 00361 * critical situations. 00362 * 00363 * If not reimplemented in the inherited class, the virtual apply method 00364 * with the same signature will be called. 00365 * 00366 * @param src matrix<T> with the source data. 00367 * @param row which row 00368 * @param col which column 00369 * @return the interpolated value of the matrix. 00370 */ 00371 inline T interpolate(const matrix<T>& src, 00372 const float& row, 00373 const float& col) const { 00374 return apply(src,row,col); 00375 }; 00376 00377 /** 00378 * copy data of "other" functor. 00379 * @param other the functor to be copied 00380 * @return a reference to this functor object 00381 */ 00382 scalarValuedInterpolation& copy(const scalarValuedInterpolation& other); 00383 00384 /** 00385 * returns a pointer to a clone of this functor. 00386 */ 00387 virtual functor* clone() const = 0; 00388 00389 /** 00390 * returns used parameters 00391 */ 00392 const parameters& getParameters() const; 00393 00394 protected: 00395 /** 00396 * the vector in use 00397 */ 00398 const vector<T>* theVector; 00399 00400 /** 00401 * the matrix in use 00402 */ 00403 const matrix<T>* theMatrix; 00404 00405 protected: 00406 /** 00407 * @name Boundary access operators 00408 */ 00409 //@{ 00410 /** 00411 * Access with zero boundary 00412 */ 00413 inline T zeroAt(const vector<T>& img,const int x) const; 00414 00415 /** 00416 * Access with constant boundary 00417 */ 00418 inline T cstAt(const vector<T>& img,const int x) const; 00419 00420 /** 00421 * Access with mirrored boundary 00422 */ 00423 inline T mirrAt(const vector<T>& img,const int x) const; 00424 00425 /** 00426 * Access with periodic boundary 00427 */ 00428 inline T periAt(const vector<T>& img,const int x) const; 00429 00430 00431 /** 00432 * Access with zero boundary 00433 */ 00434 inline T zeroAt(const matrix<T>& img,const int y,const int x) const; 00435 00436 /** 00437 * Access with constant boundary 00438 */ 00439 inline T cstAt(const matrix<T>& img,const int y,const int x) const; 00440 00441 /** 00442 * Access with mirrored boundary 00443 */ 00444 inline T mirrAt(const matrix<T>& img,const int y,const int x) const; 00445 00446 /** 00447 * Access with periodic boundary 00448 */ 00449 inline T periAt(const matrix<T>& img,const int y,const int x) const; 00450 //@} 00451 }; 00452 00453 } 00454 00455 #include "ltiScalarValuedInterpolation_template.h" 00456 00457 #endif