LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiRealFFT.h

00001 /*
00002  * Copyright (C) 1999, 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 .......: ltiRealFFT.h
00027  * authors ....: Stefan Syberichs, Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 06.12.99
00030  * revisions ..: $Id: ltiRealFFT.h,v 1.6 2006/02/08 11:43:51 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_REAL_FFT_H_
00034 #define _LTI_REAL_FFT_H_
00035 
00036 #include "ltiFunctor.h"
00037 #include "ltiImage.h"
00038 #include "ltiMath.h"
00039 #include "ltiTransform.h"
00040 
00041 namespace lti {
00042 
00043   /**
00044    * A class for FFT.
00045    * realFFT is a class for Fast Fourier Transforms on lti::vectors
00046    * and lti::channels.  The output can either be in polar or cartesic
00047    * format, specified by the parameter mode. The FFT on
00048    * channels produces two full-sized output matrices (i.e the size of
00049    * the input data), while the vector FFT generates only one half (!)
00050    * of the Fourier coefficients per dimension (real and
00051    * imaginary). The output data will be padded to a power of 2 (is
00052    * done automatically).
00053    *
00054    * In the case of channels, the DC component of the signal is in the
00055    * upper-left corner of the two-dimensional FFT!  The apply-methods
00056    * are based on fast FFT-routines written by Takuya Ooura (the original
00057    * code can be found
00058    * <a href="http://momonga.t.u-tokyo.ac.jp/~ooura/fft.html">here</a>)
00059    * that have been adapted for the use on lti::vectors and channels. Note
00060    * that the cartesic output computes faster.
00061    *
00062    * Usage:
00063    *  \code
00064    *  #include "ltiRealFFT.h"
00065    *  #include "ltiRealInvFFT.h"
00066    *
00067    *  lti::realFFT fft2d;       // for 2-dimensional FFT
00068    *  lti::realInvFFT ifft2d;   // for 2-dimensional inverse FFT
00069    *
00070    *  lti::realFFT::parameters par2d;
00071    *  lti::realInvFFT::parameters ipar2d;
00072    *
00073    *  par2d.mode = lti::realFFT::parameters::Polar;
00074    *
00075    *  ifft2d.setParameters(par2d);
00076    *  fft2d.setParameters(par2d);
00077    *
00078    *  fft2d.apply(R, re, im);       // the actual FFT
00079    *
00080    *  ifft2d.apply(re, im, back);   // inverse FFT
00081    *  \endcode
00082    */
00083   class realFFT : public transform {
00084   public:
00085 
00086     /**
00087      * Parameter class of the realFFT class.
00088      * the one and only parameter is the mode (i.e. Cartesic or Polar).
00089      * Note that the cartesic transformation is faster.
00090      */
00091     class parameters : public transform::parameters {
00092     public:
00093       /**
00094        * default constructor
00095        */
00096       parameters();
00097 
00098       /**
00099        * copy constructor
00100        */
00101       parameters(const parameters& other) 
00102         : transform::parameters() {copy(other);};
00103 
00104       /**
00105        * copy member
00106        */
00107       parameters& copy(const parameters& other);
00108 
00109       /**
00110        * returns a pointer to a clone of the parameters.
00111        */
00112       virtual functor::parameters* clone() const;
00113 
00114       /**
00115        * returns name of this class
00116        */
00117       virtual const char* getTypeName() const;
00118 
00119       /**
00120        * write the parameters in the given ioHandler
00121        * @param handler the ioHandler to be used
00122        * @param complete if true (the default) the enclosing begin/end will
00123        *        be also written, otherwise only the data block will be written.
00124        * @return true if write was successful
00125        */
00126       virtual bool write(ioHandler& handler,const bool complete=true) const;
00127 
00128       /**
00129        * write the parameters in the given ioHandler
00130        * @param handler the ioHandler to be used
00131        * @param complete if true (the default) the enclosing begin/end will
00132        *        be also written, otherwise only the data block will be written.
00133        * @return true if write was successful
00134        */
00135       virtual bool read(ioHandler& handler,const bool complete=true);
00136 
00137 #     ifdef _LTI_MSC_6
00138       /**
00139        * this function is required by MSVC only, as a workaround for a
00140        * very awful bug, which exists since MSVC V.4.0, and still by
00141        * V.6.0 with all bugfixes (so called "service packs") remains
00142        * there...  This method is also public due to another bug, so please
00143        * NEVER EVER call this method directly: use read() instead
00144        */
00145       bool readMS(ioHandler& handler,const bool complete=true);
00146 
00147       /**
00148        * this function is required by MSVC only, as a workaround for a
00149        * very awful bug, which exists since MSVC V.4.0, and still by
00150        * V.6.0 with all bugfixes (so called "service packs") remains
00151        * there...  This method is also public due to another bug, so please
00152        * NEVER EVER call this method directly: use write() instead
00153        */
00154       bool writeMS(ioHandler& handler,const bool complete=true) const;
00155 #     endif
00156 
00157       // ------------------------------------------------
00158       // the parameters
00159       // ------------------------------------------------
00160       /**
00161        * enum type for mode parameter
00162        */
00163       enum eMode{
00164         Cartesic, /**< cartesic coordinates */
00165         Polar     /**< polar coordinates */
00166       };
00167 
00168       /**
00169        * format of the output vectors
00170        * can be either cartesic or polar. Note that cartesic is faster.
00171        * Default: Cartesic
00172        */
00173       eMode mode;
00174 
00175     };
00176 
00177     /**
00178      * constructor
00179      */
00180     realFFT(void);
00181 
00182     /**
00183      * destructor
00184      */
00185     ~realFFT(void);
00186 
00187     /**
00188      * returns current parameters.
00189      */
00190     const parameters& getParameters() const;
00191 
00192     /**
00193      * returns the name of this type
00194      */
00195     virtual const char* getTypeName() const;
00196 
00197     /**
00198      * returns a pointer to a clone of the functor.
00199      */
00200     virtual functor* clone() const;
00201 
00202     /**
00203      * on-copy operator for vectors. The size of the output data is half of
00204      * the input data (possibly padded to power of 2).
00205      * The output vectors will have the dimension of the padded input divided
00206      * by 2 plus one.
00207      * @param input the real input data (constant)
00208      * @param realOutput the real output data (e.g. FFT: the real part)
00209      * @param imagOutput the imaginary output data (e.g. FFT: the imaginary
00210      * part)
00211      */
00212     virtual void apply(const vector<float>& input,
00213            vector<float>& realOutput,
00214            vector<float>& imagOutput) const;
00215 
00216     /**
00217      * on-copy operator for vectors. The size of the output data is half of
00218      * the input data (possibly padded to power of 2).
00219      * The output vectors will have the dimension of the padded input divided
00220      * by 2 plus one.
00221      * @param input the real input data (constant)
00222      * @param realOutput the real output data (e.g. FFT: the real part)
00223      * @param imagOutput the imaginary output data (e.g. FFT: the imaginary
00224      * part)
00225      */
00226     virtual void apply(const vector<double>& input,
00227            vector<double>& realOutput,
00228            vector<double>& imagOutput) const;
00229 
00230     /**
00231      * on-copy operator for channels.
00232      * The output is full-size (possibly padded to power of 2).
00233      * The DC component of the signal is in the  upper-left corner of the
00234      * two-dimensional FFT!
00235      * @param input the real input data (constant)
00236      * @param realOutput the real output data (e.g. FFT: the real part)
00237      * @param imagOutput the imaginary output data (e.g. FFT: the imaginary
00238      * part)
00239      */
00240     void apply(const matrix<float>& input,
00241                      matrix<float>& realOutput,
00242                      matrix<float>& imagOutput) const;
00243 
00244   };
00245 } // namespace lti
00246 #endif

Generated on Sat Apr 10 15:26:03 2010 for LTI-Lib by Doxygen 1.6.1