GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSMatrixOperations.hh
Go to the documentation of this file.
1 #ifndef GUARD_GGEMS_MATHS_GGEMSMATRIXOPERATIONS_HH
2 #define GUARD_GGEMS_MATHS_GGEMSMATRIXOPERATIONS_HH
3 
4 // ************************************************************************
5 // * This file is part of GGEMS. *
6 // * *
7 // * GGEMS is free software: you can redistribute it and/or modify *
8 // * it under the terms of the GNU General Public License as published by *
9 // * the Free Software Foundation, either version 3 of the License, or *
10 // * (at your option) any later version. *
11 // * *
12 // * GGEMS is distributed in the hope that it will be useful, *
13 // * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 // * GNU General Public License for more details. *
16 // * *
17 // * You should have received a copy of the GNU General Public License *
18 // * along with GGEMS. If not, see <https://www.gnu.org/licenses/>. *
19 // * *
20 // ************************************************************************
21 
35 
37 
38  #ifdef __OPENCL_C_VERSION__
39 
43 
51 inline GGfloat3 GGfloat44MultGGfloat3(global GGfloat44 const* matrix, GGfloat3 const* point)
52 {
53  GGfloat4 point4D;
54  point4D.x = point->x; point4D.y = point->y; point4D.z = point->z; point4D.w = 1.0f;
55 
56  GGfloat4 row0;
57  row0.x = matrix->m0_[0]; row0.y = matrix->m0_[1]; row0.z = matrix->m0_[2]; row0.w = matrix->m0_[3];
58 
59  GGfloat4 row1;
60  row1.x = matrix->m1_[0]; row1.y = matrix->m1_[1]; row1.z = matrix->m1_[2]; row1.w = matrix->m1_[3];
61 
62  GGfloat4 row2;
63  row2.x = matrix->m2_[0]; row2.y = matrix->m2_[1]; row2.z = matrix->m2_[2]; row2.w = matrix->m2_[3];
64 
65  GGfloat3 vector = {
66  dot(row0, point4D),
67  dot(row1, point4D),
68  dot(row2, point4D)
69  };
70 
71  return vector;
72 }
73 
77 
85 inline GGfloat3 GGfloat33MultGGfloat3(global GGfloat44 const* matrix, GGfloat3 const* point)
86 {
87  GGfloat3 point3D;
88  point3D.x = point->x; point3D.y = point->y; point3D.z = point->z;
89 
90  GGfloat3 row0;
91  row0.x = matrix->m0_[0]; row0.y = matrix->m0_[1]; row0.z = matrix->m0_[2];
92 
93  GGfloat3 row1;
94  row1.x = matrix->m1_[0]; row1.y = matrix->m1_[1]; row1.z = matrix->m1_[2];
95 
96  GGfloat3 row2;
97  row2.x = matrix->m2_[0]; row2.y = matrix->m2_[1]; row2.z = matrix->m2_[2];
98 
99  GGfloat3 vector = {
100  dot(row0, point3D),
101  dot(row1, point3D),
102  dot(row2, point3D)
103  };
104 
105  return vector;
106 }
107 
111 
119 inline GGfloat3 GGfloat33TransposeMultGGfloat3(global GGfloat44 const* matrix, GGfloat3 const* point)
120 {
121  GGfloat3 point3D;
122  point3D.x = point->x; point3D.y = point->y; point3D.z = point->z;
123 
124  GGfloat3 row0;
125  row0.x = matrix->m0_[0]; row0.y = matrix->m1_[0]; row0.z = matrix->m2_[0];
126 
127  GGfloat3 row1;
128  row1.x = matrix->m0_[1]; row1.y = matrix->m1_[1]; row1.z = matrix->m2_[1];
129 
130  GGfloat3 row2;
131  row2.x = matrix->m0_[2]; row2.y = matrix->m1_[2]; row2.z = matrix->m2_[2];
132 
133  GGfloat3 vector = {
134  dot(row0, point3D),
135  dot(row1, point3D),
136  dot(row2, point3D)
137  };
138 
139  return vector;
140 }
141 
142 #endif
143 
147 
156 {
157  GGfloat44 tmp;
158 
159  // Row 1
160  tmp.m0_[0] = A->m0_[0]*B->m0_[0] + A->m0_[1]*B->m1_[0] + A->m0_[2]*B->m2_[0] + A->m0_[3]*B->m3_[0];
161  tmp.m0_[1] = A->m0_[0]*B->m0_[1] + A->m0_[1]*B->m1_[1] + A->m0_[2]*B->m2_[1] + A->m0_[3]*B->m3_[1];
162  tmp.m0_[2] = A->m0_[0]*B->m0_[2] + A->m0_[1]*B->m1_[2] + A->m0_[2]*B->m2_[2] + A->m0_[3]*B->m3_[2];
163  tmp.m0_[3] = A->m0_[0]*B->m0_[3] + A->m0_[1]*B->m1_[3] + A->m0_[2]*B->m2_[3] + A->m0_[3]*B->m3_[3];
164 
165  // Row 2
166  tmp.m1_[0] = A->m1_[0]*B->m0_[0] + A->m1_[1]*B->m1_[0] + A->m1_[2]*B->m2_[0] + A->m1_[3]*B->m3_[0];
167  tmp.m1_[1] = A->m1_[0]*B->m0_[1] + A->m1_[1]*B->m1_[1] + A->m1_[2]*B->m2_[1] + A->m1_[3]*B->m3_[1];
168  tmp.m1_[2] = A->m1_[0]*B->m0_[2] + A->m1_[1]*B->m1_[2] + A->m1_[2]*B->m2_[2] + A->m1_[3]*B->m3_[2];
169  tmp.m1_[3] = A->m1_[0]*B->m0_[3] + A->m1_[1]*B->m1_[3] + A->m1_[2]*B->m2_[3] + A->m1_[3]*B->m3_[3];
170 
171  // Row 3
172  tmp.m2_[0] = A->m2_[0]*B->m0_[0] + A->m2_[1]*B->m1_[0] + A->m2_[2]*B->m2_[0] + A->m2_[3]*B->m3_[0];
173  tmp.m2_[1] = A->m2_[0]*B->m0_[1] + A->m2_[1]*B->m1_[1] + A->m2_[2]*B->m2_[1] + A->m2_[3]*B->m3_[1];
174  tmp.m2_[2] = A->m2_[0]*B->m0_[2] + A->m2_[1]*B->m1_[2] + A->m2_[2]*B->m2_[2] + A->m2_[3]*B->m3_[2];
175  tmp.m2_[3] = A->m2_[0]*B->m0_[3] + A->m2_[1]*B->m1_[3] + A->m2_[2]*B->m2_[3] + A->m2_[3]*B->m3_[3];
176 
177  // Row 4
178  tmp.m3_[0] = A->m3_[0]*B->m0_[0] + A->m3_[1]*B->m1_[0] + A->m3_[2]*B->m2_[0] + A->m3_[3]*B->m3_[0];
179  tmp.m3_[1] = A->m3_[0]*B->m0_[1] + A->m3_[1]*B->m1_[1] + A->m3_[2]*B->m2_[1] + A->m3_[3]*B->m3_[1];
180  tmp.m3_[2] = A->m3_[0]*B->m0_[2] + A->m3_[1]*B->m1_[2] + A->m3_[2]*B->m2_[2] + A->m3_[3]*B->m3_[2];
181  tmp.m3_[3] = A->m3_[0]*B->m0_[3] + A->m3_[1]*B->m1_[3] + A->m3_[2]*B->m2_[3] + A->m3_[3]*B->m3_[3];
182 
183  return tmp;
184 }
185 
186 #endif // End of GUARD_GGEMS_MATHS_MATRIX_FUNCTIONS_HH
GGfloat44_t::m2_
GGfloat m2_[4]
Definition: GGEMSMatrixTypes.hh:56
GGfloat44_t::m0_
GGfloat m0_[4]
Definition: GGEMSMatrixTypes.hh:54
GGEMSMatrixTypes.hh
Class managing the matrix types.
GGfloat44_t::m1_
GGfloat m1_[4]
Definition: GGEMSMatrixTypes.hh:55
A
__constant GGfloat A
Definition: GGEMSSystemOfUnits.hh:126
GGfloat3
#define GGfloat3
Definition: GGEMSTypes.hh:275
GGEMSSystemOfUnits.hh
Namespace storing all the usefull physical units.
GGfloat44MultGGfloat44
GGfloat44 GGfloat44MultGGfloat44(GGfloat44 const *A, GGfloat44 const *B)
Perform the matrix (4x4) multiplication.
Definition: GGEMSMatrixOperations.hh:155
GGfloat4
#define GGfloat4
Definition: GGEMSTypes.hh:276
GGfloat44_t::m3_
GGfloat m3_[4]
Definition: GGEMSMatrixTypes.hh:57
GGfloat44_t
Structure storing float 4 x 4 matrix.
Definition: GGEMSMatrixTypes.hh:53