Subversion Repositories gelsvn

Rev

Rev 10 | Rev 43 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 12
Line 5... Line 5...
5
#include <iostream>
5
#include <iostream>
6
 
6
 
7
#include "CGLA.h"
7
#include "CGLA.h"
8
 
8
 
9
 
9
 
10
namespace CGLA {
10
namespace CGLA 
-
 
11
{
11
 
12
 
12
	/** Basic class template for matrices.
13
  /** Basic class template for matrices.
13
		
14
		
14
	In this template a matrix is defined as an array of vectors. This may
15
  In this template a matrix is defined as an array of vectors. This may
15
	not in all cases be the most efficient but it has the advantage that 
16
  not in all cases be the most efficient but it has the advantage that 
Line 64... Line 65...
64
 
65
 
65
 
66
 
66
		/// Construct a matrix with two rows.
67
      /// Construct a matrix with two rows.
67
		ArithMatFloat(HVT _a, HVT _b)
68
      ArithMatFloat(HVT _a, HVT _b)
68
		{
69
	{
-
 
70
	  assert(ROWS==2);
69
			data[0] = _a;
71
	  data[0] = _a;
70
			data[1] = _b;
72
	  data[1] = _b;
71
		}
73
	}
72
 
74
 
73
		/// Construct a matrix with three rows.
75
      /// Construct a matrix with three rows.
74
		ArithMatFloat(HVT _a, HVT _b, HVT _c)
76
      ArithMatFloat(HVT _a, HVT _b, HVT _c)
75
		{
77
	{
-
 
78
	  assert(ROWS==3);
76
			data[0] = _a;
79
	  data[0] = _a;
77
			data[1] = _b;
80
	  data[1] = _b;
78
			data[2] = _c;
81
	  data[2] = _c;
79
		}
82
	}
80
 
83
 
81
		/// Construct a matrix with four rows.
84
      /// Construct a matrix with four rows.
82
		ArithMatFloat(HVT _a, HVT _b, HVT _c, HVT _d)
85
      ArithMatFloat(HVT _a, HVT _b, HVT _c, HVT _d)
83
		{
86
	{
-
 
87
	  assert(ROWS==4);
84
			data[0] = _a;
88
	  data[0] = _a;
85
			data[1] = _b;
89
	  data[1] = _b;
86
			data[2] = _c;
90
	  data[2] = _c;
87
			data[3] = _d;
91
	  data[3] = _d;
88
		}
92
	}
Line 110... Line 114...
110
		ScalarType* get()
114
      ScalarType* get()
111
		{
115
	{
112
			return data[0].get();
116
	  return data[0].get();
113
		}
117
	}
114
 
118
 
115
		/** Set values by passing an array to the matrix.
-
 
116
				The values should be ordered like [[row][row]...[row]] */
-
 
117
		void set(const ScalarType* sa) 
-
 
118
		{
-
 
119
			memcpy(get(), sa, sizeof(ScalarType)*get_h_dim()*get_v_dim());
-
 
120
		}
-
 
121
 
-
 
122
		/// Construct a matrix from an array of scalar values.
-
 
123
		explicit ArithMatFloat(const ScalarType* sa) 
-
 
124
		{
-
 
125
			set(sa);
-
 
126
		}
-
 
127
 
-
 
128
		/// Assign the rows of a 2D matrix.
-
 
129
		void set(HVT _a, HVT _b)
-
 
130
		{
-
 
131
			assert(ROWS==2);
-
 
132
			data[0] = _a;
-
 
133
			data[1] = _b;
-
 
134
		}
-
 
135
 
-
 
136
		/// Assign the rows of a 3D matrix.
-
 
137
		void set(HVT _a, HVT _b, HVT _c)
-
 
138
		{
-
 
139
			assert(ROWS==3);
-
 
140
			data[0] = _a;
-
 
141
			data[1] = _b;
-
 
142
			data[2] = _c;
-
 
143
		}
-
 
144
 
-
 
145
		/// Assign the rows of a 4D matrix.
-
 
146
		void set(HVT _a, HVT _b, HVT _c, HVT _d)
-
 
147
		{
-
 
148
			assert(ROWS==4);
-
 
149
			data[0] = _a;
-
 
150
			data[1] = _b;
-
 
151
			data[2] = _c;
-
 
152
			data[3] = _d;
-
 
153
		}
-
 
154
 
-
 
155
 
-
 
156
		//----------------------------------------------------------------------
119
      //----------------------------------------------------------------------
157
		// index operators
120
      // index operators
158
		//----------------------------------------------------------------------
121
      //----------------------------------------------------------------------
159
 
122
 
160
		/// Const index operator. Returns i'th row of matrix.
123
      /// Const index operator. Returns i'th row of matrix.
Line 431... Line 394...
431
																	const ArithMatFloat<VVT,HVT,MT,ROWS>& m)
394
				    const ArithMatFloat<VVT,HVT,MT,ROWS>& m)
432
	{
395
    {
433
		for(int i=0;i<ROWS;i++) is>>m[i];
396
      for(int i=0;i<ROWS;i++) is>>m[i];
434
		return is;
397
      return is;
435
	}
398
    }
436
 
-
 
437
 
-
 
438
 
-
 
439
 
-
 
440
}
399
}
441
#endif
400
#endif