CVR-Lib last update 20 Sep 2009

cvrFixedGridInterpolation.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2004
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   cvrFixedGridInterpolation.h
00043  *         Contains the class cvr::fixedGridInterpolation, which is
00044  *         parent class for all interpolation functors, whose samples have
00045  *         equal distances to each other (per dimension).
00046  * \author Peter Doerfler, Pablo Alvarado
00047  * \date   03.05.2003
00048  *
00049  * $Id: cvrFixedGridInterpolation.h,v 1.4 2007/09/10 02:47:54 alvarado Exp $
00050  */
00051 
00052 #ifndef _CVR_FIXED_GRID_INTERPOLATION_H_
00053 #define _CVR_FIXED_GRID_INTERPOLATION_H_
00054 
00055 
00056 #include "cvrFunctor.h"
00057 #include "cvrVector.h"
00058 #include "cvrMatrix.h"
00059 #include "cvrBoundaryType.h"
00060 #include "cvrPoint.h"
00061 
00062 namespace cvr {
00063 
00064   /**
00065    * This abstract class parents all interpolation functors, whose
00066    * samples have equal distances to each other (per dimension),
00067    * i.e. data is in a vector or matrix which includes images.
00068    *
00069    *
00070    * @ingroup gInterpolator
00071    */
00072   template <typename T>
00073   class fixedGridInterpolation : public functor {
00074   public:
00075 
00076     /**
00077      * Definition of the type of the elements in the applys (given type T)
00078      */
00079     typedef T value_type;
00080 
00081     /**
00082      * The parameters for the class fixedGridInterpolation
00083      */
00084     class parameters : public functor::parameters {
00085     public:
00086       /**
00087        * Default constructor
00088        */
00089       parameters();
00090 
00091       /**
00092        * Copy constructor
00093        * @param other the parameters object to be copied
00094        */
00095       parameters(const parameters& other);
00096 
00097       /**
00098        * Constructor parameters with given with boundary type
00099        */
00100       parameters(const eBoundaryType btype);
00101 
00102       /**
00103        * Destructor
00104        */
00105       ~parameters();
00106 
00107       /**
00108        * Copy the contents of a parameters object
00109        * @param other the parameters object to be copied
00110        * @return a reference to this parameters object
00111        */
00112       parameters& copy(const parameters& other);
00113 
00114       /**
00115        * Copy the contents of a parameters object
00116        * @param other the parameters object to be copied
00117        * @return a reference to this parameters object
00118        */
00119       parameters& operator=(const parameters& other);
00120 
00121       /**
00122        * Returns the name of this class.
00123        */
00124       const std::string& name() const;
00125 
00126       /**
00127        * Returns a pointer to a clone of the parameters
00128        */
00129       virtual parameters* clone() const;
00130 
00131       /**
00132        * Returns a pointer to a new instance of the parameters
00133        */
00134       virtual parameters* newInstance() const;
00135 
00136       /**
00137        * Write the parameters in the given ioHandler
00138        * @param handler the ioHandler to be used
00139        * @param complete if true (the default) the enclosing begin/end will
00140        *        be also written, otherwise only the data block will be written.
00141        * @return true if write was successful
00142        */
00143       virtual bool write(ioHandler& handler,const bool complete=true) const;
00144 
00145       /**
00146        * Read the parameters from 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 read(ioHandler& handler,const bool complete=true);
00153 
00154       // ------------------------------------------------
00155       // the parameters
00156       // ------------------------------------------------
00157 
00158       /**
00159        * Specify how the boundaries will be used.
00160        *
00161        * See the documentation for cvr::eBoundaryType for more information
00162        *
00163        * Default: cvr::Zero
00164        */
00165       eBoundaryType boundaryType;
00166     };
00167 
00168     /**
00169      * Default constructor
00170      */
00171     fixedGridInterpolation();
00172 
00173     /**
00174      * Construct a functor using the given parameters
00175      */
00176     fixedGridInterpolation(const parameters& par);
00177 
00178     /**
00179      * Copy constructor
00180      * @param other the object to be copied
00181      */
00182     fixedGridInterpolation(const fixedGridInterpolation& other);
00183 
00184     /**
00185      * Destructor
00186      */
00187     virtual ~fixedGridInterpolation();
00188 
00189     /**
00190      * Returns the name of this class.
00191      */
00192     const std::string& name() const;
00193 
00194     /**
00195      * Copy data of "other" functor.
00196      * @param other the functor to be copied
00197      * @return a reference to this functor object
00198      */
00199     fixedGridInterpolation& copy(const fixedGridInterpolation& other);
00200 
00201     /**
00202      * Alias for copy member
00203      * @param other the functor to be copied
00204      * @return a reference to this functor object
00205      */
00206     fixedGridInterpolation& operator=(const fixedGridInterpolation& other);
00207 
00208     /**
00209      * Returns used parameters
00210      */
00211     const parameters& getParameters() const;
00212 
00213     /**
00214      * all the next apply methods will return the interpolated values of the
00215      * given vector.
00216      */
00217     virtual bool use(const vector<T>& vct);
00218 
00219     /**
00220      * all the next apply methods will return the interpolated values of the
00221      * given matrix.
00222      */
00223     virtual bool use(const matrix<T>& vct);
00224 
00225     /**
00226      * Returns the interpolated value of the vector at the real valued
00227      * position x.
00228      * @param src vector<T> with the source data.
00229      * @param x the real valued position to be interpolated.
00230      * @return the interpolated value of the vector.
00231      */
00232     virtual T apply(const vector<T>& src,const float& x) const = 0;
00233 
00234     /**
00235      * Returns the interpolated value of the vector specified with
00236      * use() at the real valued position x.
00237      * @param x the real valued position to be interpolated.
00238      * @return the interpolated value of the vector.  */
00239     virtual T apply(const float& x) const = 0;
00240 
00241     /**
00242      * Returns the interpolated value of the matrix at the real valued
00243      * position (row,col).
00244      *
00245      * @param src matrix<T> with the source data.
00246      * @param row which row
00247      * @param col which column
00248      * @return the interpolated value of the matrix.
00249      */
00250     virtual T apply(const matrix<T>& src,
00251                     const float& row,
00252                     const float& col) const = 0;
00253 
00254     /**
00255      * Returns the interpolated value of the matrix at the real valued
00256      * position p.
00257      *
00258      * @param src matrix<T> with the source data.
00259      * @param p the real valued position to be interpolated.
00260      * @return the interpolated value of the matrix.
00261      */
00262     virtual T apply(const matrix<T>& src,const fpoint& p) const = 0;
00263 
00264     /**
00265      * Returns the interpolated value of the matrix specified with
00266      * use() at the real valued position (row,col).
00267      *
00268      * @param row which row
00269      * @param col which column
00270      * @return the interpolated value of the matrix.  */
00271     virtual T apply(const float& row, const float& col) const = 0;
00272 
00273     /**
00274      * Returns the interpolated value of the matrix specified with
00275      * use() at the real valued position p.
00276      *
00277      * @param p the real valued position to be interpolated.
00278      * @return the interpolated value of the matrix.
00279      */
00280     virtual T apply(const fpoint& p) const = 0;
00281 
00282 
00283     /**
00284      * Returns the interpolated value of the matrix at the real valued
00285      * position (row,col).  This method is NOT virtual and can be used
00286      * if this interpolation type is used as template parameter in time
00287      * critical situations.
00288      *
00289      * If not reimplemented in the inherited class, the virtual apply method
00290      * with the same signature will be called.
00291      *
00292      * @param src matrix<T> with the source data.
00293      * @param row which row
00294      * @param col which column
00295      * @return the interpolated value of the matrix.
00296      */
00297     inline T interpolate(const matrix<T>& src,
00298                          const float& row,
00299                          const float& col) const;
00300 
00301     /**
00302      * This method returns which pixel range around the interpolated postition
00303      * is considered by the interpolation functor.
00304      *
00305      * This is very useful for other functors to decide whether they should
00306      * call the interpolate() methods or the faster interpolateUnchk() methods.
00307      *
00308      * If the returned value is a and the interpolated position is (x,y) all
00309      * pixels with coordinates in \f$ [x-a .. x+a] \times [y-a .. y+a] \f$
00310      * may be considered by the interpolation functor.
00311      */
00312     virtual int getRangeOfInfluence() const = 0;
00313 
00314     /**
00315      * Shortcut for setting the boundary type of a functor derived from
00316      * modifier.
00317      *
00318      * \b Note: The boundaryType is modified via direct access to the
00319      * internal parameters object.
00320      */
00321     bool setBoundaryType(const eBoundaryType boundaryType);
00322 
00323   protected:
00324     /**
00325      * the vector in use
00326      */
00327     const vector<T>* theVector_;
00328 
00329     /**
00330      * the matrix in use
00331      */
00332     const matrix<T>* theMatrix_;
00333 
00334     /**
00335      * @name Boundary access operators
00336      *
00337      * These inline non-virtual methods are intended to be used by
00338      * inherited classes to access the extended versions of the at() matrix
00339      * access methods, for still integer indices.
00340      */
00341     //@{
00342     /**
00343      * Access with zero boundary
00344      */
00345     inline T zeroAt(const vector<T>& img,const int x) const;
00346 
00347     /**
00348      * Access with constant boundary
00349      */
00350     inline T cstAt(const vector<T>& img,const int x) const;
00351 
00352     /**
00353      * Access with mirrored boundary
00354      */
00355     inline T mirrAt(const vector<T>& img,const int x) const;
00356 
00357     /**
00358      * Access with periodic boundary
00359      */
00360     inline T periAt(const vector<T>& img,const int x) const;
00361 
00362     /**
00363      * Access with zero boundary
00364      */
00365     inline T zeroAt(const matrix<T>& img,const int y,const int x) const;
00366 
00367     /**
00368      * Access with constant boundary
00369      */
00370     inline T cstAt(const matrix<T>& img,const int y,const int x) const;
00371 
00372     /**
00373      * Access with mirrored boundary
00374      */
00375     inline T mirrAt(const matrix<T>& img,const int y,const int x) const;
00376 
00377     /**
00378      * Access with periodic boundary
00379      */
00380     inline T periAt(const matrix<T>& img,const int y,const int x) const;
00381     //@}
00382 
00383   };
00384 }
00385 
00386 #include "cvrFixedGridInterpolation_inline.h"
00387 #include "cvrFixedGridInterpolation_template.h"
00388 
00389 #endif
00390 

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