VR-Vantage
Loading...
Searching...
No Matches
DtMatrix3.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2017 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
9#pragma once
10
11#include <vrvMath/DtVector3.h>
12#include <vrvMath/DtMath.h>
13#include <vrvMath/DtAssert.h>
14
15namespace makVrv {
16
19 template<class T>
21 {
22 public:
26 DtMatrix3(const T rhs[3][3]);
28 DtMatrix3(T m00, T m01, T m02
29 , T m10, T m11, T m12
30 , T m20, T m21, T m22);
32 DtMatrix3(const T rhs[9]);
33
34 const void* ptr(void) const;
35
38
40 DtMatrix3 operator*(const DtMatrix3& rhs) const;
41
44
46 void setZero(void);
47
49 void setIdentity(void);
50
53
55 bool IsEqual(const DtMatrix3& rhs, T tolerance) const;
56
57 const T* operator [](size_t iRow) const;
58 T* operator [](size_t iRow);
59
61 private:
62 union
63 {
64 T _m[9];
65 T m[3][3];
66 };
67 };
68
69 template <class T>
71 , 0,1,0
72 , 0,0,1);
73
74 template<class T>
79
80 template<class T>
81 DtMatrix3<T>::DtMatrix3(const T rhs[3][3])
82 {
83 memcpy(_m, rhs, 9*sizeof(T));
84 }
85
86 template<class T>
87 DtMatrix3<T>::DtMatrix3(T m00, T m01, T m02
88 , T m10, T m11, T m12
89 , T m20, T m21, T m22)
90 {
91 m[0][0]=m00;m[0][1]=m01;m[0][2]=m02;
92 m[1][0]=m10;m[1][1]=m11;m[1][2]=m12;
93 m[2][0]=m20;m[2][1]=m21;m[2][2]=m22;
94 }
95
96 template<class T>
98 {
99 memcpy(_m, rhs, 9 * sizeof(T));
100 }
101
102 template<class T>
104 {
105
106 }
107 template<class T>
108 const void* DtMatrix3<T>::ptr(void) const
109 {
110 return _m;
111 }
112
113 template<class T>
114 const T* DtMatrix3<T>::operator [](size_t iRow) const
115 {
117 return m[iRow];
118 }
119 template<class T>
121 {
123 return m[iRow];
124 }
125
128
129 template<class T>
131 {
132 /*
133 | lhs.00, lhs.01, lhs.02 | | rhs.00, rhs.01, rhs.02 |
134 | lhs.10, lhs.11, lhs.12 | | rhs.10, rhs.11, rhs.12 |
135 | lhs.20, lhs.21, lhs.22 | | rhs.20, rhs.21, rhs.22 |
136 */
137 const DtMatrix3& lhs = *this;
138
139 DtMatrix3 result;
140
141 result.m[0][0] = lhs.m[0][0]*rhs.m[0][0] + lhs.m[0][1]*rhs.m[1][0] + lhs.m[0][2]*rhs.m[2][0];
142 result.m[0][1] = lhs.m[0][0]*rhs.m[0][1] + lhs.m[0][1]*rhs.m[1][1] + lhs.m[0][2]*rhs.m[2][1];
143 result.m[0][2] = lhs.m[0][0]*rhs.m[0][2] + lhs.m[0][1]*rhs.m[1][2] + lhs.m[0][2]*rhs.m[2][2];
144
145 result.m[1][0] = lhs.m[1][0]*rhs.m[0][0] + lhs.m[1][1]*rhs.m[1][0] + lhs.m[1][2]*rhs.m[2][0];
146 result.m[1][1] = lhs.m[1][0]*rhs.m[0][1] + lhs.m[1][1]*rhs.m[1][1] + lhs.m[1][2]*rhs.m[2][1];
147 result.m[1][2] = lhs.m[1][0]*rhs.m[0][2] + lhs.m[1][1]*rhs.m[1][2] + lhs.m[1][2]*rhs.m[2][2];
148
149 result.m[2][0] = lhs.m[2][0]*rhs.m[0][0] + lhs.m[2][1]*rhs.m[1][0] + lhs.m[2][2]*rhs.m[2][0];
150 result.m[2][1] = lhs.m[2][0]*rhs.m[0][1] + lhs.m[2][1]*rhs.m[1][1] + lhs.m[2][2]*rhs.m[2][1];
151 result.m[2][2] = lhs.m[2][0]*rhs.m[0][2] + lhs.m[2][1]*rhs.m[1][2] + lhs.m[2][2]*rhs.m[2][2];
152
153 return result;
154 }
155
156 template<class T>
158 {
159 /*
160 | lhs.00, lhs.01, lhs.02 | | rhs.0 |
161 | lhs.10, lhs.11, lhs.12 | | rhs.1 |
162 | lhs.20, lhs.21, lhs.22 | | rhs.2 |
163 */
164 DtVector3<T> vResult;
165
166 const DtMatrix3& lhs = *this;
167
168 vResult.x = lhs.m[0][0]*rhs.x + lhs.m[0][1]*rhs.y + lhs.m[0][2]*rhs.z;
169 vResult.y = lhs.m[1][0]*rhs.x + lhs.m[1][1]*rhs.y + lhs.m[1][2]*rhs.z;
170 vResult.z = lhs.m[2][0]*rhs.x + lhs.m[2][1]*rhs.y + lhs.m[2][2]*rhs.z;
171
172 return vResult;
173 }
174
175 template<class T>
177 {
178 memset(_m, 0, 9*sizeof(T));
179 }
180
181 template<class T>
183 {
184 setZero();
185 m[0][0] = m[1][1] = m[2][2] = 1;
186 }
187
188 template<class T>
190 {
191 return DtMatrix3(
192 m[0][0], m[1][0], m[2][0]
193 , m[0][1], m[1][1], m[2][1]
194 , m[0][2], m[1][2], m[2][2]
195 );
196 }
197
198 template<class T>
199 bool DtMatrix3<T>::IsEqual(const DtMatrix3<T>& rhs, T tolerance) const
200 {
201 const DtMatrix3& lhs = *this;
202 for(size_t i = 0; i < 3; ++i)
203 {
204 for(size_t j = 0; j < 3; ++j)
205 {
206 if (!DtMath::isEqual(lhs[i][j], rhs[i][j], tolerance))
207 return false;
208 }
209 }
210 return true;
211 }
212
213} //namespace makVrv
assert macros
#define ASSERT_PREDICATE_RETURN_ZERO(p)
Definition DtAssert.h:41
Math utilities.
3 dimensional vector
static bool isEqual(int32 lhs, int32 rhs, int32 tolerance=std::numeric_limits< int32 >::epsilon())
Test equality with tolerance.
3 dimensional matrix
Definition DtMatrix3.h:21
void setZero(void)
Set all values to zero.
Definition DtMatrix3.h:176
DtMatrix3 operator*(const DtMatrix3 &rhs) const
Multiply 2 matrices. Returns this*rhs.
Definition DtMatrix3.h:130
double _m[9]
Definition DtMatrix3.h:64
const void * ptr(void) const
Definition DtMatrix3.h:108
double m[3][3]
Definition DtMatrix3.h:65
DtMatrix3(const T rhs[9])
CTOR.
Definition DtMatrix3.h:97
DtMatrix3()
CTOR.
Definition DtMatrix3.h:75
DtMatrix3(const T rhs[3][3])
CTOR.
Definition DtMatrix3.h:81
bool IsEqual(const DtMatrix3 &rhs, T tolerance) const
Check whether this matrix is equivalent to rhs within tolerance.
Definition DtMatrix3.h:199
const T * operator[](size_t iRow) const
Definition DtMatrix3.h:114
~DtMatrix3()
DTOR.
Definition DtMatrix3.h:103
static DtMatrix3 theIdentityMatrix
Definition DtMatrix3.h:60
DtVector3< T > operator*(const DtVector3< T > &rhs) const
Multiply matrix with vector. Returns this*rhs.
Definition DtMatrix3.h:157
void setIdentity(void)
Set matrix to identity matrix.
Definition DtMatrix3.h:182
DtMatrix3 getTranspose(void) const
Get the transpose of this matrix.
Definition DtMatrix3.h:189
DtMatrix3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22)
CTOR.
Definition DtMatrix3.h:87
2 dimensional vector
Definition DtVector3.h:27
T y
Definition DtVector3.h:135
T z
Definition DtVector3.h:135
T x
Definition DtVector3.h:135
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtMatrix3< float > Matrix3_32
Definition DtMatrix3.h:126
DtMatrix3< double > Matrix3_64
Definition DtMatrix3.h:127