Main Page   Class Hierarchy   Compound List   File List   Compound Members  

simMatrix.inline.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_simulator_simMatrix_inline_h
00020 #define freecloth_simulator_simMatrix_inline_h
00021 
00022 #include <freecloth/simulator/simVector.h>
00023 
00024 FREECLOTH_NAMESPACE_START
00025 
00026 ////////////////////////////////////////////////////////////////////////////////
00027 // CLASS SimMatrix::Element
00028 
00029 //------------------------------------------------------------------------------
00030 
00031 inline SimMatrix::Element::Element( const GeMatrix3& data, UInt32 column )
00032   : _data( data ),
00033     _column( column )
00034 {
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////////////////
00038 // CLASS SimMatrix::Row
00039 
00040 //------------------------------------------------------------------------------
00041 
00042 inline SimMatrix::ColumnIterator SimMatrix::Row::beginColumn()
00043 {
00044     return _columns.begin();
00045 }
00046 
00047 //------------------------------------------------------------------------------
00048 
00049 inline SimMatrix::ColumnIterator SimMatrix::Row::endColumn()
00050 {
00051     return _columns.end();
00052 }
00053 
00054 //------------------------------------------------------------------------------
00055 
00056 inline SimMatrix::ColumnConstIterator SimMatrix::Row::beginColumn() const
00057 {
00058     return _columns.begin();
00059 }
00060 
00061 //------------------------------------------------------------------------------
00062 
00063 inline SimMatrix::ColumnConstIterator SimMatrix::Row::endColumn() const
00064 {
00065     return _columns.end();
00066 }
00067 
00068 //------------------------------------------------------------------------------
00069 
00070 inline GeMatrix3& SimMatrix::Row::operator[] ( UInt32 col )
00071 {
00072     // FIXME: need a way to assert this
00073     //DGFX_ASSERT( col < nbColumns() );
00074     ColumnIterator cit( beginColumn() );
00075     while( cit != endColumn() && cit->_column < col ) {
00076         ++cit;
00077     }
00078     if ( cit == endColumn() || cit->_column != col ) {
00079         cit = _columns.insert( cit, Element( GeMatrix3::ZERO, col ) );
00080     }
00081     DGFX_ASSERT( cit != endColumn() && cit->_column == col );
00082     return cit->_data;
00083 }
00084 
00085 //------------------------------------------------------------------------------
00086 
00087 inline const GeMatrix3& SimMatrix::Row::operator[] ( UInt32 col ) const
00088 {
00089     // FIXME: need a way to assert this
00090     //DGFX_ASSERT( col < nbColumns() );
00091     ColumnConstIterator cit( beginColumn() );
00092     while( cit != endColumn() && cit->_column < col ) {
00093         ++cit;
00094     }
00095     if ( cit == endColumn() || cit->_column != col ) {
00096         return GeMatrix3::ZERO;
00097     }
00098     return cit->_data;
00099 }
00100 
00101 
00102 ////////////////////////////////////////////////////////////////////////////////
00103 // CLASS SimMatrix
00104 
00105 //------------------------------------------------------------------------------
00106 
00107 inline SimMatrix::SimMatrix()
00108   : _nbRows( 0 ),
00109     _nbColumns( 0 )
00110 {}
00111 
00112 //------------------------------------------------------------------------------
00113 
00114 inline SimMatrix::SimMatrix( UInt32 nbRows, UInt32 nbColumns )
00115   : _nbRows( nbRows ),
00116     _nbColumns( nbColumns ),
00117     _rows( nbRows )
00118 {}
00119 
00120 //------------------------------------------------------------------------------
00121 
00122 inline UInt32 SimMatrix::nbRows() const
00123 {
00124     return _nbRows;
00125 }
00126 
00127 //------------------------------------------------------------------------------
00128 
00129 inline UInt32 SimMatrix::nbColumns() const
00130 {
00131     return _nbColumns;
00132 }
00133 
00134 //------------------------------------------------------------------------------
00135 
00136 inline SimMatrix::RowIterator SimMatrix::beginRow()
00137 {
00138     return _rows.begin();
00139 }
00140 
00141 //------------------------------------------------------------------------------
00142 
00143 inline SimMatrix::RowIterator SimMatrix::endRow()
00144 {
00145     return _rows.end();
00146 }
00147 
00148 //------------------------------------------------------------------------------
00149 
00150 inline SimMatrix::RowConstIterator SimMatrix::beginRow() const
00151 {
00152     return _rows.begin();
00153 }
00154 
00155 //------------------------------------------------------------------------------
00156 
00157 inline SimMatrix::RowConstIterator SimMatrix::endRow() const
00158 {
00159     return _rows.end();
00160 }
00161 
00162 //------------------------------------------------------------------------------
00163 
00164 inline SimMatrix::Row& SimMatrix::operator[] ( UInt32 row )
00165 {
00166     DGFX_ASSERT( row < nbRows() );
00167     return _rows[ row ];
00168 }
00169 
00170 //------------------------------------------------------------------------------
00171 
00172 inline const SimMatrix::Row& SimMatrix::operator[] ( UInt32 row ) const
00173 {
00174     DGFX_ASSERT( row < nbRows() );
00175     return _rows[ row ];
00176 }
00177 
00178 //------------------------------------------------------------------------------
00179 
00180 inline GeMatrix3& SimMatrix::operator() ( UInt32 row, UInt32 col )
00181 {
00182     DGFX_ASSERT( row < nbRows() );
00183     return operator[]( row )[ col ];
00184 }
00185 
00186 //------------------------------------------------------------------------------
00187 
00188 inline const GeMatrix3& SimMatrix::operator() ( UInt32 row, UInt32 col ) const
00189 {
00190     DGFX_ASSERT( row < nbRows() );
00191     return operator[]( row )[ col ];
00192 }
00193 
00194 //------------------------------------------------------------------------------
00195 
00196 inline SimMatrix& SimMatrix::operator*=( Float rhs )
00197 {
00198     for( RowIterator r = beginRow(); r != endRow(); ++r ) {
00199         for( ColumnIterator c = r->beginColumn(); c != r->endColumn(); ++c ) {
00200             c->_data *= rhs;
00201         }
00202     }
00203     return *this;
00204 }
00205 
00206 //------------------------------------------------------------------------------
00207 
00208 inline SimMatrix SimMatrix::operator*( Float rhs ) const
00209 {
00210     SimMatrix temp( *this );
00211     temp *= rhs;
00212     return temp;
00213 }
00214 
00215 //------------------------------------------------------------------------------
00216 
00217 inline SimVector SimMatrix::operator*( const SimVector& rhs ) const
00218 {
00219     SimVector result;
00220     multiply( result, *this, rhs );
00221     return result;
00222 }
00223 
00224 //------------------------------------------------------------------------------
00225 
00226 inline SimMatrix SimMatrix::operator+( const SimMatrix& rhs ) const
00227 {
00228     SimMatrix temp( *this );
00229     temp += rhs;
00230     return temp;
00231 }
00232 
00233 
00234 ////////////////////////////////////////////////////////////////////////////////
00235 // GLOBAL FUNCTIONS
00236 //
00237 
00238 //------------------------------------------------------------------------------
00239 
00240 inline SimMatrix operator*( Float lhs, const SimMatrix& rhs )
00241 {
00242     return rhs * lhs;
00243 }
00244 
00245 FREECLOTH_NAMESPACE_END
00246 
00247 #endif

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