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

ltiSymmetricMatrixInversion.h

00001 /*
00002  * Copyright (C) 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-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiSymmetricMatrixInversion.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 2.8.2003
00030  * revisions ..: $Id: ltiSymmetricMatrixInversion.h,v 1.8 2006/02/08 12:47:56 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_SYMMETRIC_MATRIX_INVERSION_H_
00034 #define _LTI_SYMMETRIC_MATRIX_INVERSION_H_
00035 
00036 
00037 #include "ltiMatrix.h"
00038 #include "ltiLinearAlgebraFunctor.h"
00039 #include "ltiCholeskyDecomposition.h"
00040 
00041 namespace lti {
00042   /**
00043    * Functor for inversion of symmetric, positive definite
00044    * matrices. The functor uses the choleskyDecomposition for
00045    * inversion unless the size of the matrix is smaller than or equal
00046    * to four. In that case the cofactor method is used which can
00047    * handle matrices that are not positiv definite but requires them
00048    * to be non-singular.
00049    *
00050    * @see lti::matrixInversion
00051    *
00052    * @ingroup gLinearAlgebra
00053    */
00054   template<class T>
00055   class symmetricMatrixInversion : public linearAlgebraFunctor {
00056   public:
00057     /**
00058      * the parameters for the class symmetricMatrixInversion
00059      */
00060     class parameters : public linearAlgebraFunctor::parameters {
00061     public:
00062       /**
00063        * default constructor
00064        */
00065       parameters() : linearAlgebraFunctor::parameters() {
00066         //TODO: Initialize your parameter values!
00067         // If you add more parameters manually, do not forget to do following:
00068         // 1. indicate in the default constructor the default values
00069         // 2. make sure that the copy member also copy your new parameters
00070         // 3. make sure that the read and write members also read and
00071         //    write your parameters
00072         
00073       };
00074 
00075       /**
00076        * copy constructor
00077        * @param other the parameters object to be copied
00078        */
00079       parameters(const parameters& other) : linearAlgebraFunctor::parameters() {
00080         copy(other);
00081       }
00082       
00083       /**
00084        * destructor
00085        */
00086       ~parameters() {
00087       };
00088 
00089       /**
00090        * returns name of this type
00091        */
00092       const char* getTypeName() const {
00093         return "symmetricMatrixInversion::parameters";
00094       };
00095 
00096       /**
00097        * copy the contents of a parameters object
00098        * @param other the parameters object to be copied
00099        * @return a reference to this parameters object
00100        */
00101       parameters& copy(const parameters& other) {
00102 #     ifndef _LTI_MSC_6
00103         // MS Visual C++ 6 is not able to compile this...
00104         linearAlgebraFunctor::parameters::copy(other);
00105 #     else
00106         // ...so we have to use this workaround.
00107         // Conditional on that, copy may not be virtual.
00108         linearAlgebraFunctor::parameters& (linearAlgebraFunctor::parameters::* p_copy)
00109                             (const linearAlgebraFunctor::parameters&) =
00110                             linearAlgebraFunctor::parameters::copy;
00111         (this->*p_copy)(other);
00112 #     endif
00113 
00114         
00115         
00116         return *this;
00117       };
00118 
00119       /**
00120        * copy the contents of a parameters object
00121        * @param other the parameters object to be copied
00122        * @return a reference to this parameters object
00123        */
00124       parameters& operator=(const parameters& other) {
00125         return copy(other);
00126       };
00127 
00128       /**
00129        * returns a pointer to a clone of the parameters
00130        */
00131       virtual functor::parameters* clone() const {
00132         return new parameters(*this);
00133       };
00134 
00135 #     ifndef _LTI_MSC_6
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 #     else
00145       /**
00146        * this function is required by MSVC only, as a workaround for a
00147        * very awful bug, which exists since MSVC V.4.0, and still by
00148        * V.6.0 with all bugfixes (so called "service packs") remains
00149        * there...  This method is also public due to another bug, so please
00150        * NEVER EVER call this method directly: use write() instead
00151        */
00152       bool writeMS(ioHandler& handler,const bool complete=true) const
00153 #     endif
00154       {
00155         bool b = true;
00156         if (complete) {
00157           b = handler.writeBegin();
00158         }
00159         
00160         if (b) {
00161           
00162         }
00163 
00164 #     ifndef _LTI_MSC_6
00165         // This is the standard C++ code, which MS Visual C++ 6 is not able to
00166         // compile...
00167         b = b && linearAlgebraFunctor::parameters::write(handler,false);
00168 #     else
00169         bool (linearAlgebraFunctor::parameters::* p_writeMS)(ioHandler&,
00170                                                          const bool) const =
00171           linearAlgebraFunctor::parameters::writeMS;
00172         b = b && (this->*p_writeMS)(handler,false);
00173 #     endif
00174 
00175         if (complete) {
00176           b = b && handler.writeEnd();
00177         }
00178 
00179         return b;
00180       }
00181 
00182 #     ifdef _LTI_MSC_6
00183       /**
00184        * write the parameters in the given ioHandler
00185        * @param handler the ioHandler to be used
00186        * @param complete if true (the default) the enclosing begin/end will
00187        *        be also written, otherwise only the data block will be written.
00188        * @return true if write was successful
00189        */
00190       bool write(ioHandler& handler,
00191                  const bool complete=true) 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 
00199 #     ifndef _LTI_MSC_6
00200       /**
00201        * read the parameters from the given ioHandler
00202        * @param handler the ioHandler to be used
00203        * @param complete if true (the default) the enclosing begin/end will
00204        *        be also written, otherwise only the data block will be written.
00205        * @return true if write was successful
00206        */
00207       virtual bool read(ioHandler& handler,const bool complete=true)
00208 #     else
00209       /**
00210        * this function is required by MSVC only, as a workaround for a
00211        * very awful bug, which exists since MSVC V.4.0, and still by
00212        * V.6.0 with all bugfixes (so called "service packs") remains
00213        * there...  This method is also public due to another bug, so please
00214        * NEVER EVER call this method directly: use read() instead
00215        */
00216       bool readMS(ioHandler& handler,const bool complete=true)
00217 #     endif
00218       {
00219         bool b = true;
00220         if (complete) {
00221           b = handler.readBegin();
00222         }
00223         
00224         if (b) {
00225           
00226         }
00227 
00228 #       ifndef _LTI_MSC_6
00229         // This is the standard C++ code, which MS Visual C++ 6 is not
00230         // able to compile...
00231         b = b && linearAlgebraFunctor::parameters::read(handler,false);
00232 #       else
00233         bool (linearAlgebraFunctor::parameters::* p_readMS)(ioHandler&,
00234                                                         const bool) =
00235           linearAlgebraFunctor::parameters::readMS;
00236         b = b && (this->*p_readMS)(handler,false);
00237 #       endif
00238 
00239         if (complete) {
00240           b = b && handler.readEnd();
00241         }
00242         
00243         return b;
00244       }
00245 
00246 #     ifdef _LTI_MSC_6
00247       /**
00248        * read the parameters from the given ioHandler
00249        * @param handler the ioHandler to be used
00250        * @param complete if true (the default) the enclosing begin/end will
00251        *        be also written, otherwise only the data block will be written.
00252        * @return true if write was successful
00253        */
00254       bool read(ioHandler& handler,const bool complete=true) {
00255         // ...we need this workaround to cope with another really awful MSVC
00256         // bug.
00257         return readMS(handler,complete);
00258       }
00259 #     endif
00260 
00261       // ------------------------------------------------
00262       // the parameters
00263       // ------------------------------------------------
00264 
00265       //TODO: comment the parameters of your functor
00266       // If you add more parameters manually, do not forget to do following:
00267       // 1. indicate in the default constructor the default values
00268       // 2. make sure that the copy member also copy your new parameters
00269       // 3. make sure that the read and write members also read and
00270       //    write your parameters
00271       
00272 
00273     };
00274 
00275     /**
00276      * default constructor
00277      */
00278     symmetricMatrixInversion();
00279 
00280     /**
00281      * Construct a functor using the given parameters
00282      */
00283     symmetricMatrixInversion(const parameters& par);
00284 
00285     /**
00286      * copy constructor
00287      * @param other the object to be copied
00288      */
00289     symmetricMatrixInversion(const symmetricMatrixInversion& other);
00290 
00291     /**
00292      * destructor
00293      */
00294     virtual ~symmetricMatrixInversion();
00295 
00296     /**
00297      * returns the name of this type ("symmetricMatrixInversion")
00298      */
00299     virtual const char* getTypeName() const;
00300 
00301     //TODO: comment your apply methods!
00302     
00303     /**
00304      * Inverts the symmetric matrix \a srcdest. If the dimension of \a
00305      * srcdest ist greater than 4 it must be positive definite as
00306      * well.
00307      * @param srcdest matrix<T> with the source data.  The result
00308      *                 will be left here too.
00309      * @return true if apply successful or false otherwise.
00310      */
00311     bool apply(matrix<T>& srcdest) const;
00312 
00313     /**
00314      * Inverts the symmetric matrix \a src and leaves the result in \a
00315      * dest. If the dimension of \a src ist greater than 4 it must
00316      * be positive definite as well.
00317      * @param src matrix<T> with the source data.
00318      * @param dest matrix<T> where the result will be left.
00319      * @return true if apply successful or false otherwise.
00320      */
00321     bool apply(const matrix<T>& src,matrix<T>& dest) const;
00322 
00323     /**
00324      * copy data of "other" functor.
00325      * @param other the functor to be copied
00326      * @return a reference to this functor object
00327      */
00328     symmetricMatrixInversion& copy(const symmetricMatrixInversion& other);
00329 
00330     /**
00331      * alias for copy member
00332      * @param other the functor to be copied
00333      * @return a reference to this functor object
00334      */
00335     symmetricMatrixInversion& operator=(const symmetricMatrixInversion& other);
00336 
00337     /**
00338      * returns a pointer to a clone of this functor.
00339      */
00340     virtual functor* clone() const;
00341 
00342     /**
00343      * returns used parameters
00344      */
00345     const parameters& getParameters() const;
00346 
00347     //TODO: comment the attributes of your functor
00348     // If you add more attributes manually, do not forget to do following:
00349     // 1. indicate in the default constructor the default values
00350     // 2. make sure that the copy member also copy your new attributes, or
00351     //    to ensure there, that these attributes are properly initialized.
00352 
00353   protected:
00354 
00355     /**
00356      * invert the matrix \a m using the cholesky decomposition
00357      */
00358     bool choleskyInversion(const matrix<T>& m, matrix<T>& inv) const;
00359 
00360     /**
00361      * inverts a 2x2 matrix
00362      */
00363     bool invert2(const matrix<T>& m, matrix<T>& inv) const;
00364 
00365     /**
00366      * inverts a 3x3 matrix
00367      */
00368     bool invert3(const matrix<T>& m, matrix<T>& inv) const;
00369 
00370     /**
00371      * inverts a 4x4 matrix
00372      */
00373     bool invert4(const matrix<T>& m, matrix<T>& inv) const;
00374 
00375     /**
00376      * Cholesky Decomposition functor.
00377      */
00378     choleskyDecomposition<T> chol;
00379   };
00380 }
00381 
00382 #endif

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