gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
Matrix4x4.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __Matrix4x4_h
36 #define __Matrix4x4_h
37 
38 
66 //******************************************************************************
67 // Include
68 //******************************************************************************
69 #ifndef GVXR_CONFIG_H
71 #endif
72 
73 #include <vector>
74 
75 #ifndef GVXR_VEC3_H
76 #include "gVirtualXRay/Vec3.h"
77 #endif
78 
79 
80 //******************************************************************************
81 // namespace
82 //******************************************************************************
83 namespace gVirtualXRay {
84 
85 
86 //******************************************************************************
87 // class declaration
88 //******************************************************************************
89 template<typename T> class Matrix4x4;
90 
91 
92 //******************************************************************************
93 // function declaration
94 //******************************************************************************
95 template <typename T> std::ostream& operator<<(std::ostream& anOutputStream,
96  const Matrix4x4<T>& aMatrix);
97 
98 
99 //==============================================================================
104 //==============================================================================
105 template<typename T> class Matrix4x4
106 //------------------------------------------------------------------------------
107 {
108 //******************************************************************************
109 public:
110  //--------------------------------------------------------------------------
112 
130  //--------------------------------------------------------------------------
131  Matrix4x4(const T& a1 = 1.0f,
132  const T& a2 = 0.0f,
133  const T& a3 = 0.0f,
134  const T& a4 = 0.0f,
135  const T& a5 = 0.0f,
136  const T& a6 = 1.0f,
137  const T& a7 = 0.0f,
138  const T& a8 = 0.0f,
139  const T& a9 = 0.0f,
140  const T& a10 = 0.0f,
141  const T& a11 = 1.0f,
142  const T& a12 = 0.0f,
143  const T& a13 = 0.0f,
144  const T& a14 = 0.0f,
145  const T& a15 = 0.0f,
146  const T& a16 = 1.0f);
147 
148 
149  //--------------------------------------------------------------------------
151 
154  //--------------------------------------------------------------------------
155  Matrix4x4(const Matrix4x4& aMatrix);
156 
157 
158  //--------------------------------------------------------------------------
160 
163  //--------------------------------------------------------------------------
164  Matrix4x4(const Matrix4x4* apMatrix);
165 
166 
167  //--------------------------------------------------------------------------
169 
172  //--------------------------------------------------------------------------
173  Matrix4x4(const T* apMatrix);
174 
175 
176  //--------------------------------------------------------------------------
178 
181  //--------------------------------------------------------------------------
182  Matrix4x4(const std::vector<double>& apMatrix);
183 
184 
185  //--------------------------------------------------------------------------
187  //--------------------------------------------------------------------------
188  void loadIdentity();
189 
190 
191  //--------------------------------------------------------------------------
193 
196  //--------------------------------------------------------------------------
197  void setFromVector(const std::vector<double>& apMatrix);
198 
199 
200  //--------------------------------------------------------------------------
202 
206  //--------------------------------------------------------------------------
207  void rotate(const double anAngle, const Vec3<T>& aVector);
208 
209 
210  //--------------------------------------------------------------------------
212 
217  //--------------------------------------------------------------------------
218  void yawPitchRollRotate(double yaw, double pitch, double roll);
219 
220 
221  //--------------------------------------------------------------------------
223 
226  //--------------------------------------------------------------------------
227  void translate(const Vec3<T>& aVector);
228 
229 
230  //--------------------------------------------------------------------------
232 
237  //--------------------------------------------------------------------------
238  void translate(T x, T y, T z);
239 
240 
241  //--------------------------------------------------------------------------
243 
246  //--------------------------------------------------------------------------
248 
249 
250  //--------------------------------------------------------------------------
252 
256  //--------------------------------------------------------------------------
257  static Matrix4x4 buildTranslationMatrix(const Vec3<T>& aVector);
258 
259 
260  //--------------------------------------------------------------------------
262 
269  //--------------------------------------------------------------------------
270  static Matrix4x4 buildRotationMatrix(T anAngle, T x, T y, T z);
271 
272 
273  //--------------------------------------------------------------------------
275 
281  //--------------------------------------------------------------------------
282  static Matrix4x4 buildYawPitchRollRotationMatrix(T yaw, T pitch, T roll);
283 
284 
285  //--------------------------------------------------------------------------
287 
291  //--------------------------------------------------------------------------
292  static Matrix4x4 buildScaleMatrix( const Vec3<T>& aVector );
293 
294 
295  //--------------------------------------------------------------------------
297 
304  //--------------------------------------------------------------------------
305  static Matrix4x4 buildScaleMatrix( T x, T y, T z );
306 
307 
308  //--------------------------------------------------------------------------
310 
315  //--------------------------------------------------------------------------
316  static Matrix4x4 buildRotationMatrix(T anAngle, const Vec3<T>& aVector);
317 
318 
319  //--------------------------------------------------------------------------
321 
327  //--------------------------------------------------------------------------
328  static Matrix4x4 buildTranslationMatrix(T x, T y, T z);
329 
330 
331  //--------------------------------------------------------------------------
333 
338  //--------------------------------------------------------------------------
339  void scale(T x, T y, T z);
340 
341 
342  //--------------------------------------------------------------------------
344 
347  //--------------------------------------------------------------------------
348  Matrix4x4 getTranspose() const;
349 
350 
351  //--------------------------------------------------------------------------
353 
356  //--------------------------------------------------------------------------
357  T determinant() const;
358 
359 
360  //--------------------------------------------------------------------------
362 
365  //--------------------------------------------------------------------------
366  Matrix4x4 getInverse() const;
367 
368 
369  //--------------------------------------------------------------------------
371 
375  //--------------------------------------------------------------------------
376  Matrix4x4& operator=(const Matrix4x4& aMatrix);
377 
378 
379  //--------------------------------------------------------------------------
381 
384  //--------------------------------------------------------------------------
385  const T* get() const;
386 
387 
388  //--------------------------------------------------------------------------
390 
393  //--------------------------------------------------------------------------
394  const T* get4x4() const;
395 
396 
397  //--------------------------------------------------------------------------
399 
402  //--------------------------------------------------------------------------
403  const T* get3x3();
404 
405 
406  //--------------------------------------------------------------------------
408 
411  //--------------------------------------------------------------------------
412  std::vector<double> getAsVector() const;
413 
414 
415  //--------------------------------------------------------------------------
417 
421  //--------------------------------------------------------------------------
422  Vec3<T> operator*(const Vec3<T>& aVector) const;
423 
424 
425  //--------------------------------------------------------------------------
427 
431  //--------------------------------------------------------------------------
432  Matrix4x4 operator*(const Matrix4x4& aMatrix) const;
433 
434 
435  //--------------------------------------------------------------------------
438 
442  //--------------------------------------------------------------------------
443  Matrix4x4& operator*=(const Matrix4x4& aMatrix);
444 
445 
446  //--------------------------------------------------------------------------
448  //--------------------------------------------------------------------------
449  void print() const;
450 
451 
452  //--------------------------------------------------------------------------
454 
457  //--------------------------------------------------------------------------
458  void print(std::ostream& anOutputStream) const;
459 
460 
461 //******************************************************************************
462 protected:
464  T m_p_4x4_data[4 * 4];
465 
466 
468  T m_p_3x3_data[3 * 3];
469 
470 
474 };
475 
476 
477 } // namespace gVirtualXRay
478 
479 
480 //******************************************************************************
481 #include "Matrix4x4.inl"
482 
483 
484 #endif // __Matrix4x4_h
static Matrix4x4 buildTranslationMatrix(const Vec3< T > &aVector)
Build a tranlation matrix.
Definition: Matrix4x4.inl:249
void loadIdentity()
Load identity matrix.
Definition: Matrix4x4.inl:151
void rotate(const double anAngle, const Vec3< T > &aVector)
Multiply the current matrix by a rotation matrix.
Definition: Matrix4x4.inl:195
T m_p_4x4_data[4 *4]
the matrix data
Definition: Matrix4x4.h:464
Matrix4x4 getTranspose() const
Get the transpose of the current matrix.
Definition: Matrix4x4.inl:424
void scale(T x, T y, T z)
Multiply the current matrix by a scaling matrix.
Definition: Matrix4x4.inl:399
static Matrix4x4 buildYawPitchRollRotationMatrix(T yaw, T pitch, T roll)
Build a rotation matrix.
Definition: Matrix4x4.inl:356
void setFromVector(const std::vector< double > &apMatrix)
Load the matrix.
Definition: Matrix4x4.inl:179
T m_p_3x3_data[3 *3]
the matrix data
Definition: Matrix4x4.h:468
const T * get4x4() const
Accessor on the 4x4 matrix data.
Definition: Matrix4x4.inl:556
Matrix4x4 & operator=(const Matrix4x4 &aMatrix)
Copy operator.
Definition: Matrix4x4.inl:481
Matrix4x4(const T &a1=1.0f, const T &a2=0.0f, const T &a3=0.0f, const T &a4=0.0f, const T &a5=0.0f, const T &a6=1.0f, const T &a7=0.0f, const T &a8=0.0f, const T &a9=0.0f, const T &a10=0.0f, const T &a11=1.0f, const T &a12=0.0f, const T &a13=0.0f, const T &a14=0.0f, const T &a15=0.0f, const T &a16=1.0f)
Default Constructor (create an identity matrix).
Definition: Matrix4x4.inl:87
Vec3 is a template class to handle a 3D vector.
Definition: Vec3.h:88
Matrix4x4 & operator*=(const Matrix4x4 &aMatrix)
Definition: Matrix4x4.inl:536
static Matrix4x4 buildIdentityMatrix()
Build an identity matrix.
Definition: Matrix4x4.inl:237
void yawPitchRollRotate(double yaw, double pitch, double roll)
Multiply the current matrix by a yaw, pitch, roll rotation matrix.
Definition: Matrix4x4.inl:205
Template class to handle 3D vectors.
static Matrix4x4 buildRotationMatrix(T anAngle, T x, T y, T z)
Build a rotation matrix.
Definition: Matrix4x4.inl:307
Template class to handle 4x4 matrices.
std::vector< double > getAsVector() const
Accessor on the 4x4 matrix data.
Definition: Matrix4x4.inl:590
const T * get3x3()
Accessor on the 3x3 matrix data.
Definition: Matrix4x4.inl:564
void translate(const Vec3< T > &aVector)
Multiply the current matrix by a translation matrix.
Definition: Matrix4x4.inl:217
Vec3< T > operator*(const Vec3< T > &aVector) const
Operator * to multiply the current matrix by a vector.
Definition: Matrix4x4.inl:493
void print() const
Print the matrix in the console.
Definition: Matrix4x4.inl:605
std::ostream & operator<<(std::ostream &anOutputSream, const gVirtualXRay::AtomicElement &anElement)
operator <<
static Matrix4x4 buildScaleMatrix(const Vec3< T > &aVector)
Build a scale matrix.
Definition: Matrix4x4.inl:268
Matrix4x4 is a template class to handle a 4 by 4 matrix.
Definition: Matrix4x4.h:89
Matrix4x4 getInverse() const
Get the inverse of the current matrix.
Definition: Matrix4x4.inl:450
T determinant() const
Compute the determinant of the current matrix.
Definition: Matrix4x4.inl:436