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

ltiCyclicTridiagonalEquationSystem.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 Digital Image/Signal Processing Library
00026  * file .......: ltiCyclicTridiagonalEquationSystem.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 15.04.2003
00030  * revisions ..: $Id: ltiCyclicTridiagonalEquationSystem.h,v 1.6 2006/02/08 12:16:23 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_CYCLIC_TRIDIAGONAL_EQUATION_SYSTEM_H_
00034 #define _LTI_CYCLIC_TRIDIAGONAL_EQUATION_SYSTEM_H_
00035 
00036 #include "ltiTridiagonalEquationSystem.h"
00037 
00038 namespace lti {
00039 
00040   /**
00041    * Solves a special kind of linear equation system, where only the
00042    * main diagonal and the first lower and upper sub-diagonals and the
00043    * two "other corners" (top right and bottom left) of the matrix are
00044    * non-zero. The solution can be found in O(n) time. Let the system
00045    * be \f$A\cdot x=r\f$ with
00046    *
00047    * \f[
00048    * \begin{bmatrix}
00049    * b_1 & c_1 & 0 & 0 & \cdots & & & & tr\\
00050    * a_2 & b_2 & c_2 & 0 & \cdots & & & & \vdots \\
00051    * 0 & & & & \cdots & & & & 0 \\
00052    * \vdots & & & & \cdots & 0 & a_{n-1} & b_{n-1} & c_{n-1}\\
00053    * bl & & & & \cdots & 0 & 0 & a_n & b_n
00054    * \end{bmatrix} \cdot \begin{bmatrix}
00055    * x_1\\ x_2 \\ \vdots \\ x_{n-1}\\ x_n
00056    * \end{bmatrix} = \begin{bmatrix}
00057    * r_1\\ r_2\\ \vdots\\ r_{n-1}\\ r_n \end{bmatrix}
00058    * \f]
00059    *
00060    * This kind of equation system occurs when cyclic boundary
00061    * conditions are used, hence the name.
00062    *
00063    * The diagonals a, b, and c can be stored in the parameters of this
00064    * functor (see also tridiagonalEquationSystem) or given directly
00065    * via the appropriate apply method. The same is true for the other
00066    * two values tr and bl.
00067    * 
00068    * \b Note: The algorithm does not perform pivoting and can thus
00069    * fail. In this case the apply methods return false. Use
00070    * luSolution or qrSolution instead.
00071    *
00072    * \b Note: The first element of the main diagonal b must not be 0!
00073    */
00074   template<class T>
00075   class cyclicTridiagonalEquationSystem : public tridiagonalEquationSystem<T> {
00076   public:
00077     /**
00078      * cyclicTridiagonalEquationSystem parameter class
00079      */
00080     class parameters : public tridiagonalEquationSystem<T>::parameters {
00081     public:
00082       /**
00083        * default constructor
00084        */
00085       parameters() : tridiagonalEquationSystem<T>::parameters() {
00086         tr=T(0);
00087         bl=T(0);
00088       };
00089 
00090      /**
00091        * copy constructor
00092        */
00093       parameters(const parameters& other)
00094         : tridiagonalEquationSystem<T>::parameters() {
00095         copy(other);
00096       };
00097       
00098       /**
00099        * returns the name of this type
00100        */
00101       virtual const char* getTypeName() const {
00102         return "cyclicTridiagonalEquationSystem::parameters";
00103       };
00104 
00105       /**
00106        * copy member.
00107        */
00108       parameters& copy(const parameters& other) {
00109 #     ifndef _LTI_MSC_6
00110         // MS Visual C++ 6 is not able to compile this...
00111         tridiagonalEquationSystem<T>::parameters::copy(other);
00112 #     else
00113         // ...so we have to use this workaround.
00114         // Conditional on that, copy may not be virtual.
00115         tridiagonalEquationSystem<T>::parameters&
00116           (tridiagonalEquationSystem<T>::parameters::* p_copy)
00117           (const tridiagonalEquationSystem<T>::parameters&) =
00118           tridiagonalEquationSystem<T>::parameters::copy;
00119         (this->*p_copy)(other);
00120 #     endif
00121 
00122         tr=other.tr;
00123         bl=other.bl;
00124 
00125         return (*this);
00126       };
00127       /**
00128        * returns a pointer to a clone of the parameters.
00129        */
00130       virtual functor::parameters* clone() const {
00131         return (new parameters(*this));
00132       };
00133 
00134       // The parameters
00135 
00136       /**
00137        * Value on the top right corner of the matrix A. Default 0.
00138        */
00139       T tr;
00140 
00141       /**
00142        * Value on the bottom left corner of the matrix A. Default 0.
00143        */ 
00144       T bl;
00145 
00146     };
00147 
00148     /**
00149      * default constructor
00150      */
00151     cyclicTridiagonalEquationSystem() : tridiagonalEquationSystem<T>() {};
00152 
00153     /**
00154      * constructor, sets the parameters
00155      */
00156     cyclicTridiagonalEquationSystem(const parameters& theParams);
00157 
00158     /**
00159      * constructor, sets the diagonals and the top right and bottom
00160      * left values of the matrix.
00161      * @param a lower sub-diagonal
00162      * @param b main diagonal
00163      * @param c upper sub-diagonal
00164      * @param tr top right element in the matrix
00165      * @param bl bottom left element in the matrix
00166      */
00167     cyclicTridiagonalEquationSystem(const vector<T> a, const vector<T> b, 
00168                                     const vector<T> c, 
00169                                     const T& tr, const T& bl);
00170 
00171     /**
00172      * returns the current parameters.
00173      */
00174     const parameters& getParameters() const;
00175 
00176     /**
00177      * copy data of "other" functor.
00178      */
00179     cyclicTridiagonalEquationSystem& 
00180     copy(const cyclicTridiagonalEquationSystem& other);
00181 
00182     /**
00183      * returns a pointer to a clone of the functor.
00184      */
00185     virtual functor* clone() const {
00186       return (new cyclicTridiagonalEquationSystem<T>(*this));
00187     };
00188 
00189     /**
00190      * returns the name of this type
00191      */
00192     virtual const char* getTypeName() const {
00193       return "cyclicTridiagonalEquationSystem";
00194     };
00195 
00196     /**
00197      * onPlace version of apply.
00198      *
00199      * Uses the diagonals from the parameters to calculate a
00200      * solution. \a r also contains the result.
00201      * @param r right side of the equation as input and solution of the 
00202      *          equation system as output
00203      */
00204     bool apply(vector<T>& r);
00205 
00206     /** onCopy version of apply.
00207      *
00208      * Uses the diagonals from the parameters to calculate a
00209      * solution.
00210      * @param r right side of the equation
00211      * @param x solution of the equation system
00212      */
00213     bool apply(const vector<T>& r,vector<T>& x);
00214 
00215     /**
00216      * Uses the given diagonals instead of those in the parameters to
00217      * calculate the solution.
00218      * @param a lower sub-diagonal
00219      * @param b main diagonal
00220      * @param c upper sub-diagonal
00221      * @param tr top right element in the matrix
00222      * @param bl bottom left element in the matrix
00223      * @param r right side of the equation
00224      * @param x solution of the equation system
00225      */
00226     bool apply(const vector<T>& a, const vector<T>& b, const vector<T>& c,
00227                const T& tr, const T& bl,
00228                const vector<T>& r, vector<T>& x);
00229 
00230   };
00231 
00232 }
00233 
00234 #endif

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