Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

MatrixT.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                                IsoEx                                      *
00004  *        Copyright (C) 2002 by Computer Graphics Group, RWTH Aachen         *
00005  *                         www.rwth-graphics.de                              *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *                                                                           *
00009  *                                License                                    *
00010  *                                                                           *
00011  *  This library is free software; you can redistribute it and/or modify it  *
00012  *  under the terms of the GNU Library General Public License as published   *
00013  *  by the Free Software Foundation, version 2.                              *
00014  *                                                                           *
00015  *  This library is distributed in the hope that it will be useful, but      *
00016  *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
00018  *  Library General Public License for more details.                         *
00019  *                                                                           *
00020  *  You should have received a copy of the GNU Library General Public        *
00021  *  License along with this library; if not, write to the Free Software      *
00022  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
00023  *                                                                           *
00024 \*===========================================================================*/
00025 
00026 //=============================================================================
00027 //
00028 //  CLASS MatrixT and VectorT
00029 //
00030 //=============================================================================
00031 
00032 
00033 #ifndef ISOEX_MATRIXT_HH
00034 #define ISOEX_MATRIXT_HH
00035 
00036 
00037 //== INCLUDES =================================================================
00038 
00039 #include <vector>
00040 
00041 //== NAMESPACES ===============================================================
00042 
00043 namespace IsoEx {
00044 namespace Math {
00045 
00046 //== CLASS DEFINITION =========================================================
00047 
00048 
00052 template <typename T>
00053 class MatrixT
00054 {
00055 public:
00056    
00058   MatrixT(unsigned int _rows, unsigned int _cols) 
00059     : rows_(_rows), cols_(_cols)
00060   { data_.resize(_cols*_rows); }
00061 
00062 
00064   T& operator()(unsigned int _i, unsigned int _j)
00065   {
00066     assert (_i < rows_ && _j < cols_);
00067     return data_[_i * cols_ + _j];
00068   }
00069 
00071   const T& operator()(unsigned int _i, unsigned int _j) const
00072   {
00073     assert (_i < rows_ && _j < cols_);
00074     return data_[_i * cols_ + _j];
00075   }
00076   
00078   unsigned int rows() const { return rows_; }
00079 
00081   unsigned int cols() const { return cols_; }
00082   
00083 private:
00084 
00085   unsigned int    rows_, cols_;
00086   std::vector<T>  data_;
00087 };
00088 
00089 
00090 //== CLASS DEFINITION =========================================================
00091 
00092 
00096 template <typename T> 
00097 class VectorT
00098 {
00099 public:
00100 
00102   VectorT(unsigned int _n) : n_(_n)
00103   { data_.resize(_n); }
00104 
00106   T& operator()(unsigned int _i)
00107   {
00108     assert(_i < n_);
00109     return data_[_i];
00110   }
00111 
00113   const T& operator()(unsigned int _i) const
00114   {
00115     assert(_i < n_);
00116     return data_[_i];
00117   }
00118 
00120   unsigned int dim() const { return n_; }
00121 
00122 private:
00123   unsigned int    n_;
00124   std::vector<T>  data_;
00125 };
00126 
00127 
00128 //=============================================================================
00129 } // namespace Math
00130 } // namespace IsoEx
00131 //=============================================================================
00132 #endif // ISOEX_MATRIXT_HH defined
00133 //=============================================================================
00134 

Generated on Mon Jul 5 18:07:08 2004 for IsoEx by doxygen 1.3.6-20040222