EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_projectors.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ projectors headers
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors: Reid Townson
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_PROJECTORS_
38 #define EGS_PROJECTORS_
39 
40 #include "egs_vector.h"
41 #include "egs_math.h"
42 
43 #include <string>
44 using namespace std;
45 
55 public:
56  EGS_Float x, y;
57  EGS_2DVector() : x(0), y(0) {};
58  EGS_2DVector(EGS_Float X, EGS_Float Y) : x(X), y(Y) {};
59  EGS_2DVector(const EGS_2DVector &v) : x(v.x), y(v.y) {};
60  EGS_2DVector &operator=(const EGS_Vector &v) {
61  x = v.x;
62  y = v.y;
63  return *this;
64  };
65  EGS_2DVector operator+(const EGS_2DVector &v) const {
66  return EGS_2DVector(x+v.x, y+v.y);
67  };
68  EGS_2DVector &operator+=(const EGS_2DVector &v) {
69  x += v.x;
70  y += v.y;
71  return *this;
72  };
73  EGS_2DVector operator-(const EGS_2DVector &v) const {
74  return EGS_2DVector(x-v.x, y-v.y);
75  };
76  EGS_2DVector &operator-=(const EGS_2DVector &v) {
77  x -= v.x;
78  y -= v.y;
79  return *this;
80  };
81  EGS_2DVector operator*(const EGS_Float f) const {
82  return EGS_2DVector(x*f,y*f);
83  };
84  EGS_2DVector &operator*=(const EGS_Float f) {
85  x*=f;
86  y*=f;
87  return *this;
88  };
89  EGS_Float operator*(const EGS_2DVector &v) const {
90  return x*v.x + y*v.y;
91  };
92  EGS_Float operator%(const EGS_2DVector &v) const {
93  return x*v.y - y*v.x;
94  };
95  EGS_Vector crossProduct(const EGS_2DVector &v) const {
96  return EGS_Vector(0,0,x*v.y - y*v.x);
97  };
98  EGS_Float length() const {
99  return sqrt(x*x+y*y);
100  };
101  EGS_Float length2() const {
102  return x*x+y*y;
103  };
104  void normalize() {
105  EGS_Float tmp=1./length();
106  x*=tmp;
107  y*=tmp;
108  };
109 };
110 
111 
120 public:
121  EGS_XProjector(const string &Type) : type(Type) {};
122  EGS_Float operator*(const EGS_Vector &x) const {
123  return x.x;
124  };
125  EGS_Vector operator*(EGS_Float t) const {
126  return EGS_Vector(t,0,0);
127  };
128  EGS_Float length() const {
129  return 1;
130  };
131  EGS_2DVector getProjection(const EGS_Vector &x) const {
132  return EGS_2DVector(x.y,x.z);
133  };
134  EGS_Float distance(const EGS_Vector &x) const {
135  return x.x;
136  }
137  const string &getType() const {
138  return type;
139  };
140  void printInfo() const {};
141  EGS_Vector normal() const {
142  return EGS_Vector(1,0,0);
143  };
144  EGS_Vector normal(const EGS_2DVector &x) const {
145  return EGS_Vector(0,x.x,x.y);
146  };
147  EGS_Vector getPoint(const EGS_2DVector &x) const {
148  return normal(x);
149  };
150 private:
151  string type;
152 };
153 
162 public:
163  EGS_YProjector(const string &Type) : type(Type) {};
164  EGS_Float operator*(const EGS_Vector &x) const {
165  return x.y;
166  };
167  EGS_Vector operator*(EGS_Float t) const {
168  return EGS_Vector(0,t,0);
169  };
170  EGS_Float length() const {
171  return 1;
172  };
173  EGS_2DVector getProjection(const EGS_Vector &x) const {
174  return EGS_2DVector(x.x,x.z);
175  };
176  EGS_Float distance(const EGS_Vector &x) const {
177  return x.y;
178  }
179  const string &getType() const {
180  return type;
181  };
182  void printInfo() const {};
183  EGS_Vector normal() const {
184  return EGS_Vector(0,1,0);
185  };
186  EGS_Vector normal(const EGS_2DVector &x) const {
187  return EGS_Vector(x.x,0,x.y);
188  };
189  EGS_Vector getPoint(const EGS_2DVector &x) const {
190  return normal(x);
191  };
192 private:
193  string type;
194 };
195 
204 public:
205  EGS_ZProjector(const string &Type) : type(Type) {};
206  EGS_Float operator*(const EGS_Vector &x) const {
207  return x.z;
208  };
209  EGS_Vector operator*(EGS_Float t) const {
210  return EGS_Vector(0,0,t);
211  };
212  EGS_Float length() const {
213  return 1;
214  };
215  EGS_2DVector getProjection(const EGS_Vector &x) const {
216  return EGS_2DVector(x.x,x.y);
217  };
218  EGS_Float distance(const EGS_Vector &x) const {
219  return x.z;
220  }
221  const string &getType() const {
222  return type;
223  };
224  void printInfo() const {};
225  EGS_Vector normal() const {
226  return EGS_Vector(0,0,1);
227  };
228  EGS_Vector normal(const EGS_2DVector &x) const {
229  return EGS_Vector(x.x,x.y,0);
230  };
231  EGS_Vector getPoint(const EGS_2DVector &x) const {
232  return normal(x);
233  };
234 private:
235  string type;
236 };
237 
243 public:
246  EGS_Projector(const EGS_Vector &A, const string &Type);
247 
250  EGS_Projector(const EGS_Vector &x1, const EGS_Vector &x2,
251  const EGS_Vector &x3, const string &Type);
252 
254  EGS_Float operator*(const EGS_Vector &x) const {
255  return a*x;
256  };
257 
259  EGS_Vector operator*(EGS_Float t) const {
260  return a*t;
261  };
262 
264  EGS_Float length() const {
265  return norm;
266  };
267 
270  EGS_Vector proj = x-distance(x)*normal();
271  return EGS_2DVector(proj.x, proj.y);
272  };
273 
276  EGS_Float distance(const EGS_Vector &x) const {
277  return x*a-d;
278  }
279 
281  const string &getType() const {
282  return type;
283  };
284 
286  void printInfo() const;
287 
289  EGS_Vector normal() const {
290  return a;
291  };
292 
294  EGS_Vector normal(const EGS_2DVector &x) const {
295  return v1*x.x + v2*x.y;
296  };
297 
299  EGS_Vector getPoint(const EGS_2DVector &x) const {
300  return xo + v1*x.x + v2*x.y;
301  };
302 private:
303  EGS_Vector a;
304  EGS_Vector xo;
305  EGS_Vector v1,v2;
307  EGS_Float norm;
308  EGS_Float d;
309  string type;
310 };
311 
312 #endif
#define EGS_EXPORT
Export symbols from the egspp library.
Definition: egs_libconfig.h:90
EGS_Float distance(const EGS_Vector &x) const
Get the distance from x to the plane (positive, negative or zero, depending on which side of the plan...
A class representing 2D vectors.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
EGS_Float y
y-component
Definition: egs_vector.h:61
A class representing 3D vectors.
Definition: egs_vector.h:56
EGS_Vector normal() const
Get the normal to the projection plane.
EGS_Vector operator*(EGS_Float t) const
Get the plane normal scaled by t.
EGS_Float z
z-component
Definition: egs_vector.h:62
EGS_Float length() const
Get the length of the plane normal.
A projector into any plane.
EGS_2DVector getProjection(const EGS_Vector &x) const
Get the 2D projection of the vector x onto the plane.
EGS_Vector normal(const EGS_2DVector &x) const
?
Attempts to fix broken math header files.
A projector into the z-plane.
A projector into the y-plane.
EGS_Float x
x-component
Definition: egs_vector.h:60
const string & getType() const
Get the name (type) of this projector.
A projector into the x-plane.
EGS_Vector getPoint(const EGS_2DVector &x) const
Get a 3D position from the 2D position x.
EGS_Float operator*(const EGS_Vector &x) const
Get the scalar product between x and the plane normal.