EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_dynamic_geometry.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ dynamic_geometry geometry 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: Alexandre Demelo 2023
25 #
26 # Contributors: Reid Townson
27 #
28 ###############################################################################
29 */
30 
36 #ifndef EGS_DYNAMIC_GEOMETRY_
37 #define EGS_DYNAMIC_GEOMETRY_
38 
39 #include "egs_base_geometry.h"
40 #include "egs_transformations.h"
41 #include "egs_rndm.h"
42 #include "egs_vector.h"
43 #include "egs_application.h"
44 #include <vector>
45 #include <string>
46 #include <sstream>
47 
48 #ifdef WIN32
49 
50  #ifdef BUILD_DYNAMIC_GEOMETRY_DLL
51  #define EGS_DYNAMIC_GEOMETRY_EXPORT __declspec(dllexport)
52  #else
53  #define EGS_DYNAMIC_GEOMETRY_EXPORT __declspec(dllimport)
54  #endif
55  #define EGS_DYNAMIC_GEOMETRY_LOCAL
56 
57 #else
58 
59  #ifdef HAVE_VISIBILITY
60  #define EGS_DYNAMIC_GEOMETRY_EXPORT __attribute__ ((visibility ("default")))
61  #define EGS_DYNAMIC_GEOMETRY_LOCAL __attribute__ ((visibility ("hidden")))
62  #else
63  #define EGS_DYNAMIC_GEOMETRY_EXPORT
64  #define EGS_DYNAMIC_GEOMETRY_LOCAL
65  #endif
66 
67 #endif
68 
110 class EGS_DYNAMIC_GEOMETRY_EXPORT EGS_DynamicGeometry :
111  public EGS_BaseGeometry {
112 
113 public:
114 
120  EGS_Float time;
121  vector<EGS_Float> trnsl;
122  vector<EGS_Float> rot;
123  };
124 
131  EGS_DynamicGeometry(EGS_BaseGeometry *G, EGS_Input *dyninp, const string &Name = "") : EGS_BaseGeometry(Name), g(G) {
132  type = g->getType() + "D";
133  nreg = g->regions();
134  is_convex = g->isConvex();
135  has_rho_scaling = g->hasRhoScaling();
136  has_B_scaling = g->hasBScaling();
138 
139  if (cpts.size() < 2) {
140  egsWarning("EGS_DynamicGeometry: not enough or missing control points.\n");
141  }
142  else {
143  if (cpts[0].time > 0.0) {
144  egsWarning("EGS_DynamicGeometry: time index of control point 1 > 0.0. This will generate many warning messages.\n");
145  }
146  int npts = cpts.size();
147  for (int i = 0; i < npts; i++) {
148  if (i > 0 && cpts[i].time < cpts[i - 1].time - epsilon) {
149  egsWarning("EGS_DynamicGeometry: time index of control point %i < time index of control point %i\n", i, i - 1);
150  }
151  if (cpts[i].time < 0.0) {
152  egsWarning("EGS_DynamicGeometry: time index of control point %i < 0.0\n", i);
153  }
154  }
155  // Normalize time values
156  for (int i = 0; i < npts - 1; i++) {
157  cpts[i].time /= cpts[npts - 1].time;
158  }
159  }
160 
161  };
162 
165  if (!g->deref()) {
166  delete g;
167  }
168  };
169 
176  T = t;
177  };
178 
189  int computeIntersections(int ireg, int n, const EGS_Vector &x,
190  const EGS_Vector &u, EGS_GeometryIntersections *isections);
191 
198  bool isRealRegion(int ireg) const;
199 
206  bool isInside(const EGS_Vector &x);
207 
214  int isWhere(const EGS_Vector &x);
215 
222  int inside(const EGS_Vector &x);
223 
230  int medium(int ireg) const;
231 
240  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u);
241 
253  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0);
254 
262  EGS_Float hownear(int ireg, const EGS_Vector &x);
263 
269  int getMaxStep() const;
270 
278  bool hasBooleanProperty(int ireg, EGS_BPType prop) const;
279 
285  void setBooleanProperty(EGS_BPType prop);
286 
292  void addBooleanProperty(int bit);
293 
302  void setBooleanProperty(EGS_BPType prop, int start, int end, int step=1);
303 
312  void addBooleanProperty(int bit, int start, int end, int step=1);
313 
319  const string &getType() const;
320 
327  EGS_Float getRelativeRho(int ireg) const;
328 
336  void setRelativeRho(int start, int end, EGS_Float rho);
337 
342  void setRelativeRho(EGS_Input *);
343 
350  EGS_Float getBScaling(int ireg) const;
351 
359  void setBScaling(int start, int end, EGS_Float bf);
360 
364  void setBScaling(EGS_Input *);
365 
372  void getLabelRegions(const string &str, vector<int> &regs);
373 
379  void getNextGeom(EGS_RandomGenerator *rndm);
380 
386  void updatePosition(EGS_Float time);
387 
393  void containsDynamic(bool &hasdynamic);
394 
395 protected:
397  string type;
399  vector<EGS_ControlPoint> cpts;
400  int ncpts;
401  EGS_Float ptime;
402 
410  void setMedia(EGS_Input *inp, int, const int *);
411 
419  int getCoordGeom(EGS_Float rand, EGS_ControlPoint &gipt);
420 
427  void buildDynamicGeometry(EGS_BaseGeometry *g, EGS_Input *dyninp);
428 };
429 
430 #endif
A class providing affine transformations.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual int computeIntersections(int ireg, int n, const EGS_Vector &x, const EGS_Vector &u, EGS_GeometryIntersections *isections)
Calculates intersection distances to region boundaries.
virtual EGS_Float hownear(int ireg, const EGS_Vector &x)=0
Calculate the distance to a boundary for position x in any direction.
virtual int inside(const EGS_Vector &x)=0
Returns the region index, if inside, or -1 if outside (obsolete)
virtual bool hasBooleanProperty(int ireg, EGS_BPType prop) const
Is the boolean property prop set for region ireg ?
virtual EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u)
virtual EGS_Float getBScaling(int ireg) const
Get the B field scaling factor in region ireg.
virtual void setBScaling(int start, int end, EGS_Float bf)
Set the B field scaling factor in regions.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
virtual const string & getType() const =0
Get the geometry type.
virtual void getLabelRegions(const string &str, vector< int > &regs)
Get the list of all regions labeled with str.
virtual int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0)=0
Calculate the distance to a boundary from x along the direction u.
virtual bool isRealRegion(int ireg) const
Returnes true if ireg is a real region, false otherwise.
virtual bool isInside(const EGS_Vector &x)=0
Is the position x inside the geometry?
virtual EGS_Float getRelativeRho(int ireg) const
Get the relative mass density in region ireg.
virtual void setBooleanProperty(EGS_BPType prop)
Set the boolean properties of the entire geometry to prop.
virtual int getMaxStep() const
Returns the maximum number of steps through the geometry.
virtual int medium(int ireg) const
Returns the medium index in region ireg.
virtual void setRelativeRho(int start, int end, EGS_Float rho)
Set the relative mass density in regions.
virtual void addBooleanProperty(int bit)
Add a boolean property for the entire geometry by setting the bit'th bit.
virtual int isWhere(const EGS_Vector &x)=0
In which region is poisition x?
A dynamic geometry.
int ncpts
Number of control points.
EGS_BaseGeometry * g
The geometry undergoing dynamic motion.
void setTransformation(EGS_AffineTransform t)
Sets the current state transform of the geometry. This is called when checking location....
string type
The geometry type.
void buildDynamicGeometry(EGS_BaseGeometry *g, EGS_Input *dyninp)
Builds the dynamic geometry using input specifications.
EGS_DynamicGeometry(EGS_BaseGeometry *G, EGS_Input *dyninp, const string &Name="")
Construct a dynamic geometry using G as the geometry and cpts as the control points.
vector< EGS_ControlPoint > cpts
Control points for dynamic motion.
EGS_AffineTransform T
Affine transformation representing the current state.
EGS_Float ptime
Time index corresponding to the particle.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
Base random number generator class. All random number generators should be derived from this class.
Definition: egs_rndm.h:67
A class representing 3D vectors.
Definition: egs_vector.h:57
EGS_Application class header file.
EGS_BaseGeometry class header file.
EGS_RandomGenerator class header file.
EGS_AffineTransform and EGS_RotationMatrix class header file.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
Definition: egs_functions.h:62
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
Structure to store control point information for dynamic geometry.
vector< EGS_Float > rot
Vector specifying rotation.
EGS_Float time
Time index for control point.
vector< EGS_Float > trnsl
Vector specifying x, y, z translation.