Main Page   Class Hierarchy   Compound List   File List   Compound Members  

simMatrix.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_sim_simMatrix_h
00020 #define freecloth_sim_simMatrix_h
00021 
00022 #ifndef freecloth_simulator_package_h
00023 #include <freecloth/simulator/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_geom_geMatrix3_h
00027 #include <freecloth/geom/geMatrix3.h>
00028 #endif
00029 
00030 #ifndef freecloth_base_list
00031 #include <freecloth/base/list>
00032 #endif
00033 
00034 #ifndef freecloth_base_vector
00035 #include <freecloth/base/vector>
00036 #endif
00037 
00038 FREECLOTH_NAMESPACE_START
00039 
00040 ////////////////////////////////////////////////////////////////////////////////
00041 // FORWARD DECLARATIONS
00042 
00043 class SimVector;
00044 
00045 ////////////////////////////////////////////////////////////////////////////////
00046 /*!
00047  * \class SimMatrix freecloth/simulator/simMatrix.h
00048  * \brief Sparse matrix class.
00049  *
00050  * Uses compressed row storage format, with each entry being a
00051  * 3x3 GeMatrix3 matrix.
00052  *
00053  * This implements the bare minimum necessary for the cloth simulation class,
00054  * and is not really intended as a general purpose sparse matrix class.
00055  *
00056  * Formerly, both MTL and uBLAS were used for this purpose.
00057  * - MTL: poor code clarity (looks like assembly), not easily portable to
00058  *   Visual C++, no support for 3x3 matrix as base element.
00059  * - uBLAS: good code clarity, easily portable, poor support for 3x3 matrix as
00060  *   base element, sparse matrices are second class citizens, with dense
00061  *   matrices getting best testing. Doesn't appear to use sparse matrices in
00062  *   debug mode. In the end, given maintenance issues and the difficulty of
00063  *   setting up Boost, this was abandoned to make the library easier to
00064  *   compile.
00065  */
00066 
00067 class SimMatrix
00068 {
00069 public:
00070     // ----- classes -----
00071 
00072     // FIXME 2003/04/23: out-of-line these classes. At present, MSVC6 cannot
00073     // handle out-of-line nested classes.
00074 
00075     ////////////////////////////////////////////////////////////////////////////
00076     /*!
00077      * \class Element freecloth/simulator/simMatrix.h
00078      * \brief Entry in a sparse matrix.
00079      */
00080     class Element {
00081     public:
00082         Element( const GeMatrix3& data, UInt32 column );
00083         GeMatrix3 _data;
00084         UInt32 _column;
00085     };
00086 
00087     // ----- types and enumerations -----
00088     typedef std::list<Element> ColumnContainer;
00089     typedef ColumnContainer::iterator ColumnIterator;
00090     typedef ColumnContainer::const_iterator ColumnConstIterator;
00091 
00092     // ----- classes -----
00093     ////////////////////////////////////////////////////////////////////////////
00094     /*!
00095      * \class Row freecloth/simulator/simMatrix.h
00096      * \brief Row in a sparse matrix.
00097      */
00098     class Row {
00099     public:
00100         ColumnContainer _columns;
00101 
00102         ColumnIterator beginColumn();
00103         ColumnIterator endColumn();
00104         ColumnConstIterator beginColumn() const;
00105         ColumnConstIterator endColumn() const;
00106 
00107         const GeMatrix3& operator[]( UInt32 column ) const;
00108         // Will insert a new entry into row if one does not exist.
00109         GeMatrix3& operator[]( UInt32 column );
00110     };
00111 
00112 
00113     // ----- types and enumerations -----
00114     typedef std::vector<Row> RowContainer;
00115     typedef RowContainer::iterator RowIterator;
00116     typedef RowContainer::const_iterator RowConstIterator;
00117     
00118     // ----- static member functions -----
00119     
00120     static void multiply(
00121         SimVector& destV,
00122         const SimMatrix& srcM,
00123         const SimVector& srcV
00124     );
00125     
00126     // ----- member functions -----
00127     
00128     SimMatrix();
00129     SimMatrix( UInt32 nbRows, UInt32 nbColumns );
00130     // Default copy constructor is fine.
00131 
00132     UInt32 nbRows() const;
00133     UInt32 nbColumns() const;
00134     RowIterator beginRow();
00135     RowIterator endRow();
00136     RowConstIterator beginRow() const;
00137     RowConstIterator endRow() const;
00138 
00139     // Default assignment operator is fine.
00140     const Row& operator[]( UInt32 row ) const;
00141     Row& operator[]( UInt32 row );
00142     const GeMatrix3& operator()( UInt32 row, UInt32 col ) const;
00143     // Will insert a new entry into matrix if one does not exist.
00144     GeMatrix3& operator()( UInt32 row, UInt32 col );
00145     SimMatrix& operator*=( Float );
00146     SimMatrix& operator+=( const SimMatrix& );
00147     SimVector operator*( const SimVector& ) const;
00148     SimMatrix operator*( Float ) const;
00149     SimMatrix operator+( const SimMatrix& ) const;
00150 
00151     // ----- static data members -----
00152 
00153 private:
00154     // ----- member functions -----
00155 
00156     // ----- data members -----
00157 
00158     UInt32 _nbRows, _nbColumns;
00159     RowContainer _rows;
00160 };
00161 
00162 ////////////////////////////////////////////////////////////////////////////////
00163 // GLOBAL FUNCTIONS
00164 //
00165 std::ostream& operator<<( std::ostream&, const SimMatrix& );
00166 SimMatrix operator*( Float, const SimMatrix& );
00167 
00168 FREECLOTH_NAMESPACE_END
00169 
00170 #include <freecloth/simulator/simMatrix.inline.h>
00171 
00172 #endif

Generated on Fri May 2 16:51:13 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002