CVR-Lib last update 20 Sep 2009

cvrMinimizeBasis.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  * \file   cvrMinimizeBasis.h
00042  *         Contains the template class cvr::minimizeBasis<T>, which generates
00043  *         a minimum number of basis vectors to approximate a given
00044  *         set of vectors within a given deviation.
00045  * \author Thomas Rusert
00046  * \date   09.06.1999
00047  *
00048  * $Id: cvrMinimizeBasis.h,v 1.4 2005/01/07 15:22:18 doerfler Exp $
00049  */
00050 
00051 #ifndef _CVR_MINIMIZE_BASIS_H_
00052 #define _CVR_MINIMIZE_BASIS_H_
00053 
00054 #include "cvrMatrix.h"
00055 #include "cvrVector.h"
00056 #include "cvrLinearAlgebraFunctor.h"
00057 
00058 namespace cvr {
00059 
00060   /**
00061    * Functor for the minimization of a basis.
00062    *
00063    * This functor generates a minimum number of basis vectors to approximate
00064    * a given set of vectors within a given deviation.
00065    *
00066    * There is a Fast and an Exact method of computing the minimized
00067    * basis.  Normally the Exact method should be used, because it does
00068    * not only compute the exact solution and the smallest basis, but
00069    * may even be faster than the "Fast" method. The "Fast" method is
00070    * not exact and may return a basis which is larger than
00071    * necessary.
00072    *
00073    * @ingroup gLinearAlgebra
00074    */
00075   class minimizeBasis : public linearAlgebraFunctor  {
00076   public:    
00077     /** 
00078      * Enumeration of deviation types 
00079      */
00080     enum eDeviationType {Element, /**< the elements of the approximating 
00081            *   vectors must not deviate more than
00082            *   maxDeviation */
00083        Vector,  /**< the l2VectorNorm of deviation vector
00084            *   between the approximated vector must
00085            *   not be larger than maxDeviation
00086            */
00087        Matrix   /**< the l2MatrixNorm of the difference
00088            *   matrix between the approximating
00089            *   and the approximated set of vectors 
00090            *   must not be larger than maxDeviation
00091            */
00092     };
00093 
00094     /**
00095      * The parameters for the class minimizeBasis
00096      */
00097     class parameters : public linearAlgebraFunctor::parameters {
00098     public:
00099       /**
00100        * Default constructor
00101        */
00102       parameters();
00103 
00104       /**
00105        * Copy constructor
00106        * @param other the parameters object to be copied
00107        */
00108       parameters(const parameters& other);
00109 
00110       /**
00111        * Destructor
00112        */
00113       ~parameters();
00114 
00115       /**
00116        * Copy the contents of a parameters object
00117        * @param other the parameters object to be copied
00118        * @return a reference to this parameters object
00119        */
00120       parameters& copy(const parameters& other);
00121 
00122       /**
00123        * Copy the contents of a parameters object
00124        * @param other the parameters object to be copied
00125        * @return a reference to this parameters object
00126        */
00127       parameters& operator=(const parameters& other);
00128 
00129       /**
00130        * Returns the name of this class.
00131        */
00132       const std::string& name() const;
00133 
00134       /**
00135        * Returns a pointer to a clone of the parameters
00136        */
00137       virtual parameters* clone() const;
00138 
00139       /**
00140        * Returns a pointer to a new instance of the parameters
00141        */
00142       virtual parameters* newInstance() const;
00143 
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       virtual bool write(ioHandler& handler,const bool complete=true) const;
00152 
00153       /**
00154        * Read the parameters from the given ioHandler
00155        * @param handler the ioHandler to be used
00156        * @param complete if true (the default) the enclosing begin/end will
00157        *        be also written, otherwise only the data block will be written.
00158        * @return true if write was successful
00159        */
00160       virtual bool read(ioHandler& handler,const bool complete=true);
00161 
00162       // ------------------------------------------------
00163       // the parameters
00164       // ------------------------------------------------
00165       /**
00166        * Deviation type
00167        *
00168        * Default: Element
00169        */
00170       eDeviationType deviationType;
00171       
00172       /**
00173        * Maximal deviation
00174        *
00175        * Default: 0.1
00176        */
00177       double maxDeviation;
00178     };
00179 
00180     /**
00181      * Default constructor
00182      */
00183     minimizeBasis();
00184 
00185     /**
00186      * Construct a functor using the given parameters
00187      */
00188     minimizeBasis(const parameters& par);
00189 
00190     /**
00191      * Copy constructor
00192      * @param other the object to be copied
00193      */
00194     minimizeBasis(const minimizeBasis& other);
00195 
00196     /**
00197      * Destructor
00198      */
00199     virtual ~minimizeBasis();
00200 
00201     /**
00202      * Operates on the given %parameter.
00203      *
00204      * @param testVectors the rows of this matrix
00205      *        should contain the vectors to be approximated
00206      * @param newBasis the columns of this matrix 
00207      *        will contain the new basis vectors
00208      * @param factors the rows of this matrix will contain
00209      *        the factors to multiply the new basis vectors
00210      *        by to approximate the testVectors
00211      * @return true if apply successful or false otherwise.
00212      */
00213     template<typename T>
00214     bool apply(const matrix<T>& testVectors,
00215          matrix<T>& newBasis,
00216          matrix<T>& factors) const;
00217 
00218 
00219     /**
00220      * Copy data of "other" functor.
00221      * @param other the functor to be copied
00222      * @return a reference to this functor object
00223      */
00224     minimizeBasis& copy(const minimizeBasis& other);
00225 
00226     /**
00227      * Alias for copy member
00228      * @param other the functor to be copied
00229      * @return a reference to this functor object
00230      */
00231     minimizeBasis& operator=(const minimizeBasis& other);
00232 
00233     /**
00234      * Returns the name of this class.
00235      */
00236     const std::string& name() const;
00237 
00238     /**
00239      * Returns a pointer to a clone of this functor.
00240      */
00241     virtual minimizeBasis* clone() const;
00242 
00243     /**
00244      * Returns a pointer to a new instance of this functor.
00245      */
00246     virtual minimizeBasis* newInstance() const;
00247 
00248     /**
00249      * Returns used parameters
00250      */
00251     const parameters& getParameters() const;
00252 
00253   protected:
00254     /**
00255      * Compute error depending on the given deviation type
00256      */
00257     template<typename T>
00258     T computeError(const eDeviationType& deviation,
00259                    const matrix<T>& shouldBe,
00260                    const matrix<T>& current) const;
00261 
00262   };
00263 
00264   /**
00265    * Read a minimizeBasis<T>::eDeviationType
00266    *
00267    * @ingroup gStorable
00268    */
00269   bool read(ioHandler& handler,minimizeBasis::eDeviationType& data);
00270 
00271   /**
00272    * Write a minimizeBasis<T>::eDeviationType
00273    *
00274    * @ingroup gStorable
00275    */
00276   bool write(ioHandler& handler,const minimizeBasis::eDeviationType& data);
00277 
00278 }
00279 
00280 #include "cvrMinimizeBasis_template.h"
00281 
00282 #endif
00283 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8