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

ltiLinearAlgebraFunctor.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 .......: ltiLinearAlgebraFunctor.h
00027  * authors ....: Thomas Rusert
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 01.06.99
00030  * revisions ..: $Id: ltiLinearAlgebraFunctor.h,v 1.8 2006/02/08 12:30:31 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_LINEAR_ALGEBRA_FUNCTOR_H_
00034 #define _LTI_LINEAR_ALGEBRA_FUNCTOR_H_
00035 
00036 #include "ltiFunctor.h"
00037 #include "ltiException.h"
00038 #include "ltiVector.h"
00039 #include "ltiMatrix.h"
00040 
00041 namespace lti {
00042   /**
00043    * Base class for all lti linear algebra functors.
00044    *
00045    * @ingroup gLinearAlgebra
00046    */
00047   class linearAlgebraFunctor : public functor {
00048   public:
00049     /**
00050      * singular matrix exception
00051      */
00052     class singularMatrixException : public exception {
00053     public:
00054       /**
00055        * Default constructor
00056        */
00057       singularMatrixException()
00058         : exception("a matrix singularity was encountered") {}
00059       /**
00060        * Return the name of this class
00061        */
00062       virtual const char* getTypeName() const {
00063         return "linearAlgebraFunctor::singularMatrixException";
00064       };
00065     };
00066     /**
00067      * incompatible dimensions exception
00068      */
00069     class incompatibleDimensionsException : public exception {
00070     public:
00071       /**
00072        * Default constructor
00073        */
00074       incompatibleDimensionsException()
00075         : exception("MathObject dimensions do not match") {};
00076       /**
00077        * Return the name of this class
00078        */
00079       virtual const char* getTypeName() const {
00080         return "linearAlgebraFunctor::incompatibleDimensionsException";
00081       };
00082     };
00083 
00084     /**
00085      * the parameters for the linear algebra functors
00086      */
00087     class parameters : public functor::parameters {
00088     public:
00089       /**
00090        * default constructor
00091        */
00092       parameters() : functor::parameters() {
00093       };
00094 
00095       /**
00096        * copy constructor
00097        * @param other the parameters object to be copied
00098        */
00099       parameters(const parameters& other) : functor::parameters() {
00100         copy(other);
00101       };
00102 
00103       /**
00104        * destructor
00105        */
00106       virtual ~parameters() {
00107       };
00108 
00109       /**
00110        * returns name of this type
00111        */
00112       const char* getTypeName() const {
00113         return "linearAlgebraFunctor::parameters";
00114       };
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 # ifndef _LTI_MSC_6
00123     // MS Visual C++ 6 is not able to compile this...
00124         functor::parameters::copy(other);
00125 # else
00126     // ...so we have to use this workaround.
00127     // Conditional on that, copy may not be virtual.
00128         functor::parameters& (functor::parameters::* p_copy)
00129           (const functor::parameters&) = functor::parameters::copy;
00130           (this->*p_copy)(other);
00131 # endif
00132 
00133         return *this;
00134       };
00135 
00136       /**
00137        * returns a pointer to a clone of the parameters
00138        */
00139       virtual functor::parameters* clone() const {
00140         return new parameters(*this);
00141       };
00142 
00143 # ifndef _LTI_MSC_6
00144       /**
00145        * write the parameters in the given ioHandler
00146        * @param handler the ioHandler to be used
00147        * @param complete if true (the default) the enclosing begin/end will
00148        *        be also written, otherwise only the data block will be written.
00149        * @return true if write was successful
00150        */
00151       bool write(ioHandler& handler,
00152                  const bool complete) const
00153 # else
00154       /**
00155        * this function is required by MSVC only, as a workaround for a
00156        * very awful bug, which exists since MSVC V.4.0, and still by
00157        * V.6.0 with all bugfixes (so called "service packs") remains
00158        * there...  This method is also public due to another bug, so please
00159        * NEVER EVER call this method directly: use write() instead
00160        */
00161       bool writeMS(ioHandler& handler,
00162                    const bool complete) const
00163 # endif
00164       {
00165         bool b(true);
00166 
00167         if (complete) {
00168           b = b && handler.writeBegin();
00169         }
00170 
00171         if (complete) {
00172           b = b && handler.writeEnd();
00173         }
00174 
00175         return b;
00176       }
00177 
00178 # ifdef _LTI_MSC_6
00179       /**
00180        * write the parameters in the given ioHandler
00181        * @param handler the ioHandler to be used
00182        * @param complete if true (the default) the enclosing begin/end will
00183        *        be also written, otherwise only the data block will be written.
00184        * @return true if write was successful
00185        */
00186       bool write(ioHandler& handler,
00187                  const bool complete) const {
00188        // ...we need this workaround to cope with another really awful MSVC
00189        // bug.
00190         return writeMS(handler,complete);
00191       }
00192 # endif
00193 
00194 
00195 # ifndef _LTI_MSC_6
00196       /**
00197        * read the parametersfrom the given ioHandler
00198        * @param handler the ioHandler to be used
00199        * @param complete if true (the default) the enclosing begin/end will
00200        *        be also written, otherwise only the data block will be written.
00201        * @return true if write was successful
00202        */
00203       bool read(ioHandler& handler,
00204                 const bool complete)
00205 # else
00206       /**
00207        * this function is required by MSVC only, as a workaround for a
00208        * very awful bug, which exists since MSVC V.4.0, and still by
00209        * V.6.0 with all bugfixes (so called "service packs") remains
00210        * there...  This method is also public due to another bug, so please
00211        * NEVER EVER call this method directly: use read() instead
00212        */
00213       bool readMS(ioHandler& handler,
00214                   const bool complete)
00215 # endif
00216       {
00217         bool b(true);
00218 
00219         if (complete) {
00220           b = b && handler.readBegin();
00221         }
00222 
00223         if (complete) {
00224           b = b && handler.readEnd();
00225         }
00226 
00227         return b;
00228       }
00229 
00230 # ifdef _LTI_MSC_6
00231       /**
00232        * read the parametersfrom the given ioHandler
00233        * @param handler the ioHandler to be used
00234        * @param complete if true (the default) the enclosing begin/end will
00235        *        be also written, otherwise only the data block will be written.
00236        * @return true if write was successful
00237        */
00238       bool read(ioHandler& handler,
00239                 const bool complete) {
00240         // ...we need this workaround to cope with another really awful MSVC
00241         // bug.
00242         return readMS(handler,complete);
00243       }
00244 # endif
00245 
00246     };
00247 
00248     /**
00249      * returns the name of this type
00250      */
00251     virtual const char* getTypeName() const {
00252       return "linearAlgebraFunctor";
00253     };
00254   };
00255 
00256   /**
00257    * Dot Product of two vectors.
00258    *
00259    * computes the dot product of two vectors (elementtypes T and U) and
00260    * returns the product (type T!)
00261    *
00262    * @ingroup gLinearAlgebra
00263    */
00264   template<class T,class U=T>
00265   class scalarProduct : public linearAlgebraFunctor {
00266     public:
00267     /**
00268      * default constructor
00269      */
00270     scalarProduct()
00271       : linearAlgebraFunctor() {};
00272     /**
00273      * destructor
00274      */
00275     virtual ~scalarProduct() {};
00276 
00277     /**
00278      * onCopy version of apply.
00279      */
00280     T& apply(const vector<T>& mult1,
00281              const vector<U>& mult2,
00282                    T& result) const;
00283 
00284     /**
00285      * returns a pointer to a clone of the functor.
00286      */
00287     virtual functor* clone() const {
00288       return (new scalarProduct<T,U>(*this));
00289     };
00290 
00291     /**
00292      * returns the name of this type
00293      */
00294     virtual const char* getTypeName() const {return "scalarProduct";};
00295   };
00296 
00297 }
00298 
00299 #include "ltiLinearAlgebraFunctor_template.h"
00300 
00301 #endif

Generated on Sat Apr 10 15:25:44 2010 for LTI-Lib by Doxygen 1.6.1