MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
Matrix.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _MGMatrix_HH_
6 #define _MGMatrix_HH_
7 
11 #include <glm/glm.hpp>
12 #include "mg/MGCL.h"
13 
14 // MGMatrix.h
15 // Defines Class MGMatrix
16 //
17 // Forward Declarations
18 class MGVector;
19 class MGUnit_vector;
20 class MGTransf;
21 class MGIfstream;
22 class MGOfstream;
23 
25 
30 class MG_DLL_DECLR MGMatrix {
31 
32 public:
33 
36 MG_DLL_DECLR friend MGMatrix operator* (double scale, const MGMatrix& mat);
37 
39 MG_DLL_DECLR friend std::ostream& operator<< (std::ostream&, const MGMatrix&);
40 
42 
45 explicit MGMatrix(int sdim=0);
46 
48 MGMatrix(const MGVector&, const MGVector&);
49 
51 MGMatrix(const MGVector&, const MGVector&, const MGVector& );
52 
55 MGMatrix(int dim, double scale);
56 
58 MGMatrix(
59  int dim,
60  const double* values,
61  bool column_wise=true
62 );
64 
68 MGMatrix(const MGVector& vec, double angle);
69 
72 MGMatrix(
73  int dim,
74  int axis1,
75  int axis2,
76  double cosv,
77  double sinv
78 );
80 
83 MGMatrix(int dim, const MGMatrix&, int start1=0, int start2=0);
84 
86 MGMatrix(const MGMatrix& mat);
87 
89 ~MGMatrix(){if(m_matrix) delete[] m_matrix;};
90 
92 
94 MGMatrix& operator=(const MGMatrix& mat);
95 
97 double operator() (int i, int j) const{return ref(i,j);}
98 
100 double& operator() (int i, int j) {
101  assert(i<sdim() && j<sdim());
102  return m_matrix[i+j*m_sdim];
103 }
104 
107 MGMatrix operator* (double) const;
108 
111 MGMatrix& operator*= (double);
112 
115 MGMatrix operator* (const MGMatrix&) const;
116 
119 MGMatrix& operator*= (const MGMatrix&);
120 
123 MGTransf operator* (const MGTransf&) const;
124 
129 bool operator== (const MGMatrix&) const;
130 bool operator!= (const MGMatrix&) const;
131 
133 
135 void convert_to_glMatrix(
136  glm::mat4& glMatI//double glMat[16] ///<OpenGL Matrix will be output.
137 )const;
138 
140 double determinant() const;
141 
146 MGMatrix& from_axis(
147  const MGUnit_vector& uvec,
148  int axis=0
149  );
150 
152 bool is_null()const{return m_sdim==0;};
153 
155 double ref(int i, int j) const;
156 
160 MGMatrix& reflection(const MGVector& vec);
161 
164 void resize(int nsdim);
165 
167 int sdim() const{return m_sdim;}
168 
172 MGMatrix& set_x_axis(
173  const MGUnit_vector& unit
174 );
175 
179 MGMatrix& set_reflect_2D(const MGVector& );
180 
184 MGMatrix& set_rotate_2D(double angle);
185 
188 MGMatrix& set_rotate_2D(double cval, double sval);
189 
193 MGMatrix& set_axis(
194  const MGUnit_vector& uvec,
195  int axis=0
196 );
197 
202 MGMatrix& set_vector(
203  const MGUnit_vector& uvec,
204  int axis=0
205 );
206 
215 MGMatrix& set_xy_axis(
216  const MGUnit_vector& uvecx,
217  const MGUnit_vector& uvecy
218 );
219 
228 MGMatrix& set_xy_vector(
229  const MGUnit_vector& uvecx,
230  const MGUnit_vector& uvecy
231 );
232 
237 MGMatrix& set_reflect_3D (const MGVector& vec);
238 
244 MGMatrix& set_rotate(const MGVector& V0, const MGVector& V1);
245 
249 MGMatrix& set_rotate_3D (const MGVector& vec, double angle);
250 
253 MGMatrix& set_rotate_3D (const MGVector& vec, double cval, double sval);
254 
259 MGMatrix& set_scale (double);
260 
265 MGMatrix& set_diff_scale (double*);
266 
268 MGMatrix& set_glMatrix(const double glMat[16]);
269 
271 void set_null();
272 
275 MGMatrix transpose() const;
276 
280 MGMatrix& to_axis(
281  const MGUnit_vector& uvec,
282  int axis=0
283 );
284 
287 int dump_size() const;
288 
290 int dump(MGOfstream& ) const;
291 
293 int restore(MGIfstream& );
294 
296 double scale()const;
297 
299 
300 private:
301 
303  int m_sdim;
304  double* m_matrix;
305 
307 private:
308 
310 MGMatrix multiply(const MGMatrix& m2) const;
311 
312 };
313 
316 MG_DLL_DECLR MGVector operator* (const MGVector& v, const MGMatrix& m);
317 
320 MG_DLL_DECLR MGVector& operator*= (MGVector& v, const MGMatrix& m);
321 
325 MG_DLL_DECLR MGUnit_vector& operator*= (MGUnit_vector& v,const MGMatrix&);
326  // end of BASE group
328 #endif
MGTransf represents a transformation of a space dimension.
Definition: Transf.h:35
MGIfstream is a class to read the serialized data generated by MGOfstream.
Definition: Ifstream.h:30
std::ostream & operator<<(std::ostream &ostrm, const MGisect &is)
Debug Function.
Definition: isect.h:95
MG_DLL_DECLR MGVector & operator*=(MGVector &v, const MGMatrix &m)
Vector of a general n space dimension.
Definition: Vector.h:26
MG_DLL_DECLR MGVector operator*(const MGVector &v, const MGMatrix &m)
bool is_null() const
Test if this is null.
Definition: Matrix.h:152
MGOfstream is a class to serialize all of the subclasses of MGGel.
Definition: Ofstream.h:31
~MGMatrix()
Definition: Matrix.h:89
int sdim() const
Return space dimension.
Definition: Matrix.h:167
Define a unit vector, is a MGVector.
Definition: Unit_vector.h:17
MGMatrix is a matix of m by m, where m is the space dimension.
Definition: Matrix.h:30