last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 2007 00003 * Pablo Alvarado 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 * \file cvrGeometricTransform.h 00043 * Contains the classes cvr::geometricTransform<T> and 00044 * cvr::geometricTransformBase, 00045 * which are the parent classes of all geometric transformation 00046 * classes, like rotation, scale, translation, etc. 00047 * \author Pablo Alvarado 00048 * \date 08.09.2007 00049 * 00050 * revisions ..: $Id: cvrGeometricTransform.h,v 1.3 2007/12/19 02:58:28 alvarado Exp $ 00051 */ 00052 00053 #ifndef _CVR_GEOMETRIC_TRANSFORM_H_ 00054 #define _CVR_GEOMETRIC_TRANSFORM_H_ 00055 00056 #include "cvrMatrix.h" 00057 #include "cvrFunctor.h" 00058 #include "cvrMatrixProcessingInterface.h" 00059 00060 namespace cvr { 00061 00062 /** 00063 * Class geometricTransformBase. 00064 * 00065 * This is an abstract class parent of all functors that achieve geometric 00066 * transformation of images, like affine or homogeneous transformations. It 00067 * contains the basic parameters that are not template dependent. 00068 * 00069 * @see geometricTransformBase::parameters. 00070 * 00071 * @ingroup gGeometricTrans 00072 */ 00073 class geometricTransformBase : public functor { 00074 public: 00075 00076 /** 00077 * Enumeration to specified how the dimensions of the resulting image 00078 * has to be computed 00079 */ 00080 enum eResizeMode { 00081 KeepDimensions, /**< Keep the dimensions of the original image, including 00082 * the relative position of the origin. 00083 */ 00084 KeepOrigin, /**< Keep the origin relative position, but adjust the 00085 * rest of the dimensions to hold the complete 00086 * transformed image. 00087 */ 00088 AdjustDimensions /**< Adjust the dimension of the resulting image to 00089 * contain the whole transformed image. This implies 00090 * loosing the relative position of the origin. 00091 */ 00092 00093 }; 00094 00095 /** 00096 * The parameters for the class geometricTransform 00097 */ 00098 class parameters : public functor::parameters { 00099 public: 00100 /** 00101 * Default constructor 00102 */ 00103 parameters(); 00104 00105 /** 00106 * Copy constructor 00107 * @param other the parameters object to be copied 00108 */ 00109 parameters(const parameters& other); 00110 00111 /** 00112 * Destructor 00113 */ 00114 ~parameters(); 00115 00116 /** 00117 * Copy the contents of a parameters object 00118 * @param other the parameters object to be copied 00119 * @return a reference to this parameters object 00120 */ 00121 parameters& copy(const parameters& other); 00122 00123 /** 00124 * Copy the contents of a parameters object 00125 * @param other the parameters object to be copied 00126 * @return a reference to this parameters object 00127 */ 00128 parameters& operator=(const parameters& other); 00129 00130 /** 00131 * Returns the complete name of the parameters class. 00132 */ 00133 virtual const std::string& name() const; 00134 00135 /** 00136 * Returns a pointer to a clone of the parameters. 00137 */ 00138 virtual parameters* clone() const; 00139 00140 /** 00141 * Returns a pointer to a new instance of the parameters. 00142 */ 00143 virtual parameters* newInstance() const; 00144 00145 /** 00146 * Write the parameters in the given ioHandler 00147 * @param handler the ioHandler to be used 00148 * @param complete if true (the default) the enclosing begin/end will 00149 * be also written, otherwise only the data block will be written. 00150 * @return true if write was successful 00151 */ 00152 virtual bool write(ioHandler& handler,const bool complete=true) const; 00153 00154 /** 00155 * Read the parameters from the given ioHandler 00156 * @param handler the ioHandler to be used 00157 * @param complete if true (the default) the enclosing begin/end will 00158 * be also written, otherwise only the data block will be written. 00159 * @return true if write was successful 00160 */ 00161 virtual bool read(ioHandler& handler,const bool complete=true); 00162 00163 // ------------------------------------------------ 00164 // the parameters 00165 // ------------------------------------------------ 00166 /** 00167 * Resize mode. 00168 * 00169 * Choose how to deal with the final result dimensions. 00170 * 00171 * Default value: KeepDimensions 00172 */ 00173 eResizeMode resizeMode; 00174 }; 00175 00176 /** 00177 * Default constructor 00178 */ 00179 geometricTransformBase(); 00180 00181 /** 00182 * Construct a functor using the given parameters 00183 */ 00184 geometricTransformBase(const parameters& par); 00185 00186 /** 00187 * Copy constructor 00188 * @param other the object to be copied 00189 */ 00190 geometricTransformBase(const geometricTransformBase& other); 00191 00192 /** 00193 * Destructor 00194 */ 00195 virtual ~geometricTransformBase(); 00196 00197 /** 00198 * Copy data of "other" functor. 00199 * @param other the functor to be copied 00200 * @return a reference to this functor object 00201 */ 00202 geometricTransformBase& copy(const geometricTransformBase& other); 00203 00204 /** 00205 * Alias for copy member 00206 * @param other the functor to be copied 00207 * @return a reference to this functor object 00208 */ 00209 geometricTransformBase& operator=(const geometricTransformBase& other); 00210 00211 /** 00212 * Returns the complete name of the functor class 00213 */ 00214 virtual const std::string& name() const; 00215 00216 /** 00217 * Returns a pointer to a clone of this functor. 00218 */ 00219 virtual geometricTransformBase* clone() const = 0; 00220 00221 /** 00222 * Returns a pointer to a new instance of this functor. 00223 */ 00224 virtual geometricTransformBase* newInstance() const = 0; 00225 00226 /** 00227 * Returns used parameters 00228 */ 00229 const parameters& getParameters() const; 00230 00231 protected: 00232 /** 00233 * Returns used parameters 00234 */ 00235 parameters& getParameters(); 00236 00237 }; 00238 00239 /** 00240 * Class geometricTransform. 00241 * 00242 * This is an abstract template class, parent of all functors that achieve 00243 * geometric transformation of images, like affine or homogeneous 00244 * transformations. 00245 * 00246 * The template parameter I indicates the interpolator type to be used. 00247 * The class provided must be inherited from cvr::fixedGridInterpolation. 00248 * Note that the interpolator works for one type of containers only, and 00249 * only that type will be supported by this class too. 00250 * 00251 * @see geometricTransform<I>::parameters. 00252 * 00253 * @ingroup gGeometricTrans 00254 */ 00255 template<class I> 00256 class geometricTransform : public geometricTransformBase, 00257 public matrixProcessingInterface<typename I::value_type> { 00258 public: 00259 typedef I interpolator_type; 00260 typedef typename I::value_type value_type; 00261 00262 /** 00263 * The parameters for the class geometricTransform 00264 */ 00265 class parameters : public geometricTransformBase::parameters { 00266 public: 00267 /** 00268 * Default constructor 00269 */ 00270 parameters(); 00271 00272 /** 00273 * Copy constructor 00274 * @param other the parameters object to be copied 00275 */ 00276 parameters(const parameters& other); 00277 00278 /** 00279 * Destructor 00280 */ 00281 ~parameters(); 00282 00283 /** 00284 * Copy the contents of a parameters object 00285 * @param other the parameters object to be copied 00286 * @return a reference to this parameters object 00287 */ 00288 parameters& copy(const parameters& other); 00289 00290 /** 00291 * Copy the contents of a parameters object 00292 * @param other the parameters object to be copied 00293 * @return a reference to this parameters object 00294 */ 00295 parameters& operator=(const parameters& other); 00296 00297 /** 00298 * Returns the complete name of the parameters class. 00299 */ 00300 virtual const std::string& name() const; 00301 00302 /** 00303 * Returns a pointer to a clone of the parameters. 00304 */ 00305 virtual parameters* clone() const = 0; 00306 00307 /** 00308 * Returns a pointer to a new instance of the parameters. 00309 */ 00310 virtual parameters* newInstance() const = 0; 00311 00312 /** 00313 * Write the parameters in the given ioHandler 00314 * @param handler the ioHandler to be used 00315 * @param complete if true (the default) the enclosing begin/end will 00316 * be also written, otherwise only the data block will be written. 00317 * @return true if write was successful 00318 */ 00319 virtual bool write(ioHandler& handler,const bool complete=true) const; 00320 00321 /** 00322 * Read the parameters from the given ioHandler 00323 * @param handler the ioHandler to be used 00324 * @param complete if true (the default) the enclosing begin/end will 00325 * be also written, otherwise only the data block will be written. 00326 * @return true if write was successful 00327 */ 00328 virtual bool read(ioHandler& handler,const bool complete=true); 00329 00330 // ------------------------------------------------ 00331 // the parameters 00332 // ------------------------------------------------ 00333 /** 00334 * Instance of the interpolator parameters to be used. 00335 * 00336 * Default value: default parameters instance 00337 */ 00338 typename interpolator_type::parameters interpolatorParams; 00339 }; 00340 00341 /** 00342 * Default constructor 00343 */ 00344 geometricTransform(); 00345 00346 /** 00347 * Construct a functor using the given parameters 00348 */ 00349 geometricTransform(const parameters& par); 00350 00351 /** 00352 * Copy constructor 00353 * @param other the object to be copied 00354 */ 00355 geometricTransform(const geometricTransform<I>& other); 00356 00357 /** 00358 * Destructor 00359 */ 00360 virtual ~geometricTransform(); 00361 00362 /** 00363 * Transform geometrically the given image and leave the result on the 00364 * same container. 00365 * 00366 * @param srcdest matrix<T> with the source data. The result 00367 * will be left here too. 00368 * @return true if apply successful or false otherwise. 00369 */ 00370 virtual bool apply(matrix<value_type>& srcdest) const; 00371 00372 /** 00373 * Transform geometrically the source image and leave the result on the 00374 * destination container. 00375 * 00376 * Operates on a copy of the given %parameters. 00377 * 00378 * @param src matrix<value_type> with the source data. 00379 * @param dest matrix<value_type> where the result will be left. 00380 * @return true if apply successful or false otherwise. 00381 */ 00382 virtual bool apply(const matrix<value_type>& src, 00383 matrix<value_type>& dest) const = 0; 00384 00385 00386 /** 00387 * Transform geometrically the given image and leave the result on the 00388 * same container. 00389 * 00390 * If the parameters specify to AdjustDimensions, then the offset 00391 * value will contain the relative position of the \a srcdest 00392 * origin with respect to the original image coordinate system. 00393 * To all other resize policies, the value of offset is set to 00394 * (0,0). 00395 * 00396 * @param srcdest matrix<T> with the source data. The result 00397 * will be left here too. 00398 * @param offset position of the origin of the result with respect to the 00399 * coordinate system of the original image. 00400 * @return true if apply successful or false otherwise. 00401 */ 00402 virtual bool apply(matrix<value_type>& srcdest, 00403 fpoint& offset) const; 00404 00405 /** 00406 * Transform geometrically the source image and leave the result on the 00407 * destination container. 00408 * 00409 * 00410 * If the parameters specify to AdjustDimensions, then the offset 00411 * value will contain the relative position of the \a srcdest 00412 * origin with respect to the original image coordinate system. 00413 * To all other resize policies, the value of offset is set to 00414 * (0,0). 00415 * 00416 * @param src matrix<value_type> with the source data. 00417 * @param dest matrix<value_type> where the result will be left. 00418 * @param offset position of the origin of the result with respect to the 00419 * coordinate system of the original image. 00420 * @return true if apply successful or false otherwise. 00421 */ 00422 virtual bool apply(const matrix<value_type>& src, 00423 matrix<value_type>& dest, 00424 fpoint& offset) const = 0; 00425 00426 /** 00427 * Copy data of "other" functor. 00428 * @param other the functor to be copied 00429 * @return a reference to this functor object 00430 */ 00431 geometricTransform& copy(const geometricTransform<I>& other); 00432 00433 /** 00434 * Alias for copy member 00435 * @param other the functor to be copied 00436 * @return a reference to this functor object 00437 */ 00438 geometricTransform& operator=(const geometricTransform<I>& other); 00439 00440 /** 00441 * Returns the complete name of the functor class 00442 */ 00443 virtual const std::string& name() const; 00444 00445 /** 00446 * Returns a pointer to a clone of this functor. 00447 */ 00448 virtual geometricTransform<I>* clone() const = 0; 00449 00450 /** 00451 * Returns a pointer to a new instance of this functor. 00452 */ 00453 virtual geometricTransform<I>* newInstance() const = 0; 00454 00455 /** 00456 * Returns used parameters 00457 */ 00458 const parameters& getParameters() const; 00459 00460 /** 00461 * Update parameters instance 00462 */ 00463 virtual bool updateParameters(); 00464 00465 /** 00466 * Return a read-writable reference to the internal interpolator object. 00467 */ 00468 interpolator_type& getInterpolator(); 00469 00470 /** 00471 * Return a read-only reference to the internal interpolator object. 00472 */ 00473 const interpolator_type& getInterpolator() const; 00474 00475 protected: 00476 /** 00477 * Returns used parameters 00478 */ 00479 parameters& getParameters(); 00480 00481 /** 00482 * Interpolator instance with the appropriate parameters. 00483 * 00484 * The updateParameters method will ensure that the interpolator 00485 * parameters are set appropriatelly 00486 */ 00487 interpolator_type interpolator_; 00488 00489 }; // class geometricTransform<I> 00490 00491 /** 00492 * Read the resize mode 00493 * 00494 * @ingroup gStorable 00495 */ 00496 bool read(ioHandler& handler,geometricTransformBase::eResizeMode& data); 00497 00498 /** 00499 * Write the resize mode 00500 * 00501 * @ingroup gStorable 00502 */ 00503 bool write(ioHandler& handler, 00504 const geometricTransformBase::eResizeMode& data); 00505 } // namespace cvr 00506 00507 #include "cvrGeometricTransform_template.h" 00508 00509 #endif 00510