IsoEx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
MatrixT.hh
1 /*===========================================================================*\
2  * *
3  * IsoEx *
4  * Copyright (C) 2002 by Computer Graphics Group, RWTH Aachen *
5  * www.rwth-graphics.de *
6  * *
7  *---------------------------------------------------------------------------*
8  * *
9  * License *
10  * *
11  * This library is free software; you can redistribute it and/or modify it *
12  * under the terms of the GNU Library General Public License as published *
13  * by the Free Software Foundation, version 2. *
14  * *
15  * This library is distributed in the hope that it will be useful, but *
16  * WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
18  * Library General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU Library General Public *
21  * License along with this library; if not, write to the Free Software *
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23  * *
24 \*===========================================================================*/
25 
26 //=============================================================================
27 //
28 // CLASS MatrixT and VectorT
29 //
30 //=============================================================================
31 
32 
33 #ifndef ISOEX_MATRIXT_HH
34 #define ISOEX_MATRIXT_HH
35 
36 
37 //== INCLUDES =================================================================
38 
39 #include <vector>
40 
41 //== NAMESPACES ===============================================================
42 
43 namespace IsoEx {
44 namespace Math {
45 
46 //== CLASS DEFINITION =========================================================
47 
48 
52 template <typename T>
53 class MatrixT
54 {
55 public:
56 
58  MatrixT(unsigned int _rows, unsigned int _cols)
59  : rows_(_rows), cols_(_cols)
60  { data_.resize(_cols*_rows); }
61 
62 
64  T& operator()(unsigned int _i, unsigned int _j)
65  {
66  assert (_i < rows_ && _j < cols_);
67  return data_[_i * cols_ + _j];
68  }
69 
71  const T& operator()(unsigned int _i, unsigned int _j) const
72  {
73  assert (_i < rows_ && _j < cols_);
74  return data_[_i * cols_ + _j];
75  }
76 
78  unsigned int rows() const { return rows_; }
79 
81  unsigned int cols() const { return cols_; }
82 
83 private:
84 
85  unsigned int rows_, cols_;
86  std::vector<T> data_;
87 };
88 
89 
90 //== CLASS DEFINITION =========================================================
91 
92 
96 template <typename T>
97 class VectorT
98 {
99 public:
100 
102  VectorT(unsigned int _n) : n_(_n)
103  { data_.resize(_n); }
104 
106  T& operator()(unsigned int _i)
107  {
108  assert(_i < n_);
109  return data_[_i];
110  }
111 
113  const T& operator()(unsigned int _i) const
114  {
115  assert(_i < n_);
116  return data_[_i];
117  }
118 
120  unsigned int dim() const { return n_; }
121 
122 private:
123  unsigned int n_;
124  std::vector<T> data_;
125 };
126 
127 
128 //=============================================================================
129 } // namespace Math
130 } // namespace IsoEx
131 //=============================================================================
132 #endif // ISOEX_MATRIXT_HH defined
133 //=============================================================================
134 
unsigned int dim() const
Return vector's dimension.
Definition: MatrixT.hh:120
VectorT(unsigned int _n)
Construct with dimension.
Definition: MatrixT.hh:102
unsigned int cols() const
Number of columns.
Definition: MatrixT.hh:81
Definition: MatrixT.hh:97
unsigned int rows() const
Number of rows.
Definition: MatrixT.hh:78
T & operator()(unsigned int _i)
Read & write element access.
Definition: MatrixT.hh:106
const T & operator()(unsigned int _i, unsigned int _j) const
Read only element access.
Definition: MatrixT.hh:71
A type for volume images, or 3D textures.
MatrixT(unsigned int _rows, unsigned int _cols)
Construct with number of rows and columns.
Definition: MatrixT.hh:58
T & operator()(unsigned int _i, unsigned int _j)
Read & write element access.
Definition: MatrixT.hh:64
Definition: MatrixT.hh:53
const T & operator()(unsigned int _i) const
Read only element access.
Definition: MatrixT.hh:113