CVR-Lib last update 20 Sep 2009

cvrBilinearInterpolation.h

Go to the documentation of this file.
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  * \file   cvrBilinearInterpolation.h
00043  *         Contains the template class cvr::bilinearInterpolation<T>, which is
00044  *         a functor, which uses bilinear interpolation to approximate values
00045  *         between the pixels or elements of vectors and matrices.
00046  * \author Pablo Alvarado
00047  * \date   12.06.2001
00048  *
00049  * revisions ..: $Id: cvrBilinearInterpolation.h,v 1.3 2007/09/10 02:41:51 alvarado Exp $
00050  */
00051 
00052 #ifndef _CVR_BILINEAR_INTERPOLATION_H_
00053 #define _CVR_BILINEAR_INTERPOLATION_H_
00054 
00055 
00056 #include "cvrImage.h"
00057 #include "cvrVector.h"
00058 #include "cvrFixedGridInterpolation.h"
00059 
00060 namespace cvr {
00061 
00062   /**
00063    * This functor use bilinear interpolation to approximate values
00064    * between the pixels or elements of vectors and matrices.
00065    *
00066    * The type T of the template is the type of the elements of the vector
00067    * or matrix used.
00068    *
00069    * @ingroup gInterpolator
00070    */
00071   template<typename T>
00072   class bilinearInterpolation : public fixedGridInterpolation<T> {
00073   public:
00074 
00075     /**
00076      * The parameters for the class bilinearInterpolation
00077      */
00078     class parameters : public fixedGridInterpolation<T>::parameters {
00079     public:
00080       /**
00081        * Default constructor
00082        */
00083       parameters();
00084 
00085       /**
00086        * Copy constructor
00087        * @param other the parameters object to be copied
00088        */
00089       parameters(const parameters& other);
00090 
00091       /**
00092        * Constructor parameters with given with boundary type
00093        */
00094       parameters(const eBoundaryType btype);
00095 
00096       /**
00097        * Destructor
00098        */
00099       ~parameters();
00100 
00101       /**
00102        * Copy the contents of a parameters object
00103        * @param other the parameters object to be copied
00104        * @return a reference to this parameters object
00105        */
00106       parameters& copy(const parameters& other);
00107 
00108       /**
00109        * Copy the contents of a parameters object
00110        * @param other the parameters object to be copied
00111        * @return a reference to this parameters object
00112        */
00113       parameters& operator=(const parameters& other);
00114 
00115       /**
00116        * Returns the name of this type.
00117        */
00118       virtual const std::string& name() const;
00119 
00120       /**
00121        * Returns a pointer to a clone of the parameters
00122        */
00123       virtual parameters* clone() const;
00124 
00125       /**
00126        * Returns a pointer to a new instance of the parameters
00127        */
00128       virtual parameters* newInstance() const;
00129 
00130       /**
00131        * Write the parameters in 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       virtual bool write(ioHandler& handler,const bool complete=true) const;
00138 
00139       /**
00140        * Read the parameters from the given ioHandler
00141        * @param handler the ioHandler to be used
00142        * @param complete if true (the default) the enclosing begin/end will
00143        *        be also written, otherwise only the data block will be written.
00144        * @return true if write was successful
00145        */
00146       virtual bool read(ioHandler& handler,const bool complete=true);
00147 
00148       // ------------------------------------------------
00149       // the parameters
00150       // ------------------------------------------------
00151 
00152       // If you add more parameters manually, do not forget to do following:
00153       // 1. indicate in the default constructor the default values
00154       // 2. make sure that the copy member also copy your new parameters
00155       // 3. make sure that the read and write members also read and
00156       //    write your parameters
00157     };
00158 
00159     /**
00160      * Default constructor
00161      */
00162     bilinearInterpolation();
00163 
00164     /**
00165      * Construct an interpolation with the given boundary type
00166      */
00167     bilinearInterpolation(const eBoundaryType boundaryType);
00168 
00169     /**
00170      * Construct a functor using the given parameters
00171      */
00172     bilinearInterpolation(const parameters& par);
00173 
00174     /**
00175      * Copy constructor
00176      * @param other the object to be copied
00177      */
00178     bilinearInterpolation(const bilinearInterpolation<T>& other);
00179 
00180     /**
00181      * Destructor
00182      */
00183     virtual ~bilinearInterpolation();
00184 
00185     /**
00186      * Returns the name of this type.
00187      */
00188     virtual const std::string& name() const;
00189 
00190     /**
00191      * Returns the interpolated value of the vector at the real valued
00192      * position x.
00193      * @param src vector<T> with the source data.
00194      * @param x the real valued position to be interpolated.
00195      * @return the interpolated value of the vector.
00196      */
00197     virtual T apply(const vector<T>& src,const float& x) const;
00198 
00199     /**
00200      * Returns the interpolated value of the vector specified with
00201      * use() at the real valued position x.
00202      * @param x the real valued position to be interpolated.
00203      * @return the interpolated value of the vector.  */
00204     virtual T apply(const float& x) const;
00205 
00206     /**
00207      * Returns the interpolated value of the matrix at the real valued
00208      * position (row,col).
00209      *
00210      * @param src matrix<T> with the source data.
00211      * @param row which row
00212      * @param col which column
00213      * @return the interpolated value of the matrix.
00214      */
00215     virtual T apply(const matrix<T>& src,
00216                     const float& row,
00217                     const float& col) const;
00218 
00219     /**
00220      * Returns the interpolated value of the matrix at the real valued
00221      * position p.
00222      *
00223      * @param src matrix<T> with the source data.
00224      * @param p the real valued position to be interpolated.
00225      * @return the interpolated value of the matrix.
00226      */
00227     virtual T apply(const matrix<T>& src,const point<float>& p) const;
00228 
00229     /**
00230      * Returns the interpolated value of the matrix specified with
00231      * use() at the real valued position (row,col).
00232      *
00233      * @param row which row
00234      * @param col which column
00235      * @return the interpolated value of the matrix.  */
00236     virtual T apply(const float& row, const float& col) const;
00237 
00238     /**
00239      * Returns the interpolated value of the matrix specified with
00240      * use() at the real valued position p.
00241      *
00242      * @param p the real valued position to be interpolated.
00243      * @return the interpolated value of the matrix.
00244      */
00245     virtual T apply(const point<float>& p) const;
00246 
00247     /**
00248      * Returns the interpolated value of the matrix at the real valued
00249      * position (row,col).  This method is not virtual and can be used
00250      * if this interpolation type is used as template parameter in time
00251      * critical situations
00252      *
00253      * @param src matrix<T> with the source data.
00254      * @param row which row
00255      * @param col which column
00256      * @return the interpolated value of the matrix.
00257      */
00258     T interpolate(const matrix<T>& src,
00259                   const float row,
00260                   const float col) const;
00261 
00262     /**
00263      * Returns the interpolated value of the matrix specified with
00264      * use() at the real valued position (row,col).  This method is
00265      * not virtual and can be used if this interpolation type is used
00266      * as template parameter in time critical situations
00267      *
00268      * @param row which row
00269      * @param col which column
00270      * @return the interpolated value of the matrix.
00271      */
00272     inline T interpolate(const float row,
00273                          const float col) const;
00274 
00275     /**
00276      * Returns the interpolated value of the matrix at the real valued
00277      * position (row,col).
00278      *
00279      * This method does not check if the given coordinates and the rest of
00280      * used points in the src matrix lie within the valid range.  This is
00281      * left to you.  Please consider that for the bilinear interpolation
00282      * not only the point(trunc(col),trunc(row)) is used, but also its three
00283      * "next" neighbors ((col,row+1),(col+1,row),(col+1,row+1)).
00284      *
00285      * This method is not virtual and can be used in time critical situations,
00286      * where you prefer to take the boundary control by yourself.
00287      *
00288      * @param src matrix<T> with the source data.
00289      * @param row which row
00290      * @param col which column
00291      * @return the interpolated value of the matrix.
00292      */
00293     inline T interpolateUnchk(const matrix<T>& src,
00294                               const float row,
00295                               const float col) const;
00296 
00297     /**
00298      * Returns the interpolated value of the matrix specified with
00299      * use() at the real valued position (row,col).  This method is
00300      * not virtual and can be used if this interpolation type is used
00301      * as template parameter in time critical situations
00302      *
00303      * @param row which row
00304      * @param col which column
00305      * @return the interpolated value of the matrix.
00306      */
00307     inline T interpolateUnchk(const float row,
00308                               const float col) const;
00309 
00310     /**
00311      * Compute the bilinear interpolated value for the given coefficients
00312      * and values.
00313      *
00314      * This method is provided for convenience only.  Use at your own
00315      * risk.
00316      *
00317      * @param fy fractional term between 0 and 1
00318      * @param fx fractional term between 0 and 1
00319      * @param syx value for fx==0 fy==0
00320      * @param syx1 value for fx==1 fy==0
00321      * @param sy1x value for fx==0 fy==1
00322      * @param sy1x1 value for fx==1 fy==1
00323      *
00324      * @return interpolated value between the four corners
00325      */
00326     inline T compute(const float fy,
00327                      const float fx,
00328                      const T syx, const T syx1,
00329                      const T sy1x, const T sy1x1) const;
00330 
00331     /**
00332      * Compute the linear interpolated value for the given coefficients
00333      * and values
00334      *
00335      * This method is provided for convenience only.  Use at your own
00336      * risk.
00337      *
00338      * @param fx fractional term between 0 and 1
00339      * @param sx value for sx==0
00340      * @param sx1 value for sx==1
00341      *
00342      * @return interpolated value between the two extremes.
00343      */
00344     inline T compute(const float fx,
00345                      const T sx, const T sx1) const;
00346 
00347 
00348     /**
00349      * Copy data of "other" functor.
00350      * @param other the functor to be copied
00351      * @return a reference to this functor object
00352      */
00353     bilinearInterpolation<T>& copy(const bilinearInterpolation<T>& other);
00354 
00355     /**
00356      * Alias for copy member
00357      * @param other the functor to be copied
00358      * @return a reference to this functor object
00359      */
00360     bilinearInterpolation<T>& operator=(const bilinearInterpolation<T>& other);
00361 
00362     /**
00363      * Returns a pointer to a clone of this functor.
00364      */
00365     virtual bilinearInterpolation<T>* clone() const;
00366 
00367     /**
00368      * Returns a pointer to a new instance of this functor.
00369      */
00370     virtual bilinearInterpolation<T>* newInstance() const;
00371 
00372     /**
00373      * Returns used parameters
00374      */
00375     const parameters& getParameters() const;
00376 
00377     /**
00378      * This method returns which pixel range around the interpolated postition
00379      * is considered by the interpolation functor.
00380      *
00381      * This is very useful for other functors to decide whether they should
00382      * call the interpolate() methods or the faster interpolateUnchk() methods.
00383      *
00384      * If the returned value is a and the interpolated position is (x,y) all
00385      * pixels with coordinates in \f$ [x-a .. x+a] \times [y-a .. y+a] \f$
00386      * may be considered by the interpolation functor.
00387      */
00388     int getRangeOfInfluence() const;
00389 
00390   };
00391 }
00392 
00393 #include "cvrBilinearInterpolation_inline.h"
00394 
00395 #endif
00396 

Generated on Sun Sep 20 22:07:58 2009 for CVR-Lib by Doxygen 1.5.8