GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSReferentialTransformation.hh
Go to the documentation of this file.
1 #ifndef GUARD_GGEMS_MATHS_GGEMSREFERENTIALTRANSFORMATION_HH
2 #define GUARD_GGEMS_MATHS_GGEMSREFERENTIALTRANSFORMATION_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 
36 #ifdef __OPENCL_C_VERSION__
37 
41 
49 inline GGfloat3 RotateUnitZ(GGfloat3* vector, GGfloat3 const* new_uz)
50 {
51  GGfloat u1 = new_uz->x;
52  GGfloat u2 = new_uz->y;
53  GGfloat u3 = new_uz->z;
54 
55  GGfloat up = u1*u1 + u2*u2;
56  if (up > 0) {
57  up = sqrt(up);
58  GGfloat px = vector->x, py = vector->y, pz = vector->z;
59  vector->x = (u1*u3*px - u2*py) /up + u1*pz;
60  vector->y = (u2*u3*px + u1*py) /up + u2*pz;
61  vector->z = -up*px + u3*pz;
62  }
63  else if (u3 < 0.) {
64  vector->x = -vector->x; // phi=0 theta=gpu_pi
65  vector->z = -vector->z;
66  }
67 
68  GGfloat3 tmp = {vector->x, vector->y, vector->z};
69  return tmp;
70 }
71 
75 
83 inline GGfloat3 GlobalToLocalPosition(global GGfloat44 const* matrix, GGfloat3 const* point)
84 {
85  // Current point minus translation
86  GGfloat3 new_point = {
87  point->x - matrix->m0_[3],
88  point->y - matrix->m1_[3],
89  point->z - matrix->m2_[3]
90  };
91 
92  return GGfloat33TransposeMultGGfloat3(matrix, &new_point);
93 }
94 
98 
106 inline GGfloat3 LocalToGlobalPosition(global GGfloat44 const* matrix, GGfloat3 const* point)
107 {
108  return GGfloat44MultGGfloat3(matrix, point);
109 }
110 
114 
122 inline GGfloat3 GlobalToLocalDirection(global GGfloat44 const* matrix, GGfloat3 const* point)
123 {
124  return normalize(GGfloat33TransposeMultGGfloat3(matrix, point));
125 }
126 
130 
138 inline GGfloat3 LocalToGlobalDirection(global GGfloat44 const* matrix, GGfloat3 const* point)
139 {
140  return normalize(GGfloat33MultGGfloat3(matrix, point));
141 }
142 
143 #endif
144 
145 #endif // End of GUARD_GGEMS_MATHS_GGEMSREFERENTIALTRANSFORMATION_HH
GGfloat3
#define GGfloat3
Definition: GGEMSTypes.hh:275
GGEMSMatrixOperations.hh
Definitions of functions using matrix.
GGfloat44_t
Structure storing float 4 x 4 matrix.
Definition: GGEMSMatrixTypes.hh:53
GGfloat
#define GGfloat
Definition: GGEMSTypes.hh:273