EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_dynamic_shape.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ dynamic shape 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: Reid Townson
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_DYNAMIC_SHAPE_
38 #define EGS_DYNAMIC_SHAPE_
39 
40 #include "egs_shapes.h"
41 #include "egs_rndm.h"
42 #include "egs_application.h"
43 
44 #ifdef WIN32
45 
46  #ifdef BUILD_DYNAMIC_SHAPE_DLL
47  #define EGS_DYNAMIC_SHAPE_EXPORT __declspec(dllexport)
48  #else
49  #define EGS_DYNAMIC_SHAPE_EXPORT __declspec(dllimport)
50  #endif
51  #define EGS_DYNAMIC_SHAPE_LOCAL
52 
53 #else
54 
55  #ifdef HAVE_VISIBILITY
56  #define EGS_DYNAMIC_SHAPE_EXPORT __attribute__ ((visibility ("default")))
57  #define EGS_DYNAMIC_SHAPE_LOCAL __attribute__ ((visibility ("hidden")))
58  #else
59  #define EGS_DYNAMIC_SHAPE_EXPORT
60  #define EGS_DYNAMIC_SHAPE_LOCAL
61  #endif
62 
63 #endif
64 
106 class EGS_DYNAMIC_SHAPE_EXPORT EGS_DynamicShape : public EGS_BaseShape {
107 
108 public:
109 
117  EGS_DynamicShape(EGS_BaseShape *Shape, EGS_Input *dyninp, const string &Name="",EGS_ObjectFactory *f=0) :
118  EGS_BaseShape(Name,f), shape(Shape) {
119  if (shape) {
120  shape->ref();
121  otype = "dynamic ";
122  otype += shape->getObjectType();
123  }
124  else {
125  otype = "Invalid DynamicShape";
126  }
127 
128  // Build dynamic shape is where many of the geometry attributes (including control points) are extracted
129  buildDynamicShape(dyninp);
130 
131  if (cpts.size() < 2) {
132  egsWarning("DynamicShape: not enough or missing control points.\n");
133  }
134  else {
135  if (cpts[0].time > 0.0) {
136  egsWarning("DynamicShape: time index of control point 1 > 0.0. This will generate many warning messages.\n");
137  }
138  int npts = cpts.size();
139  for (int i=0; i<npts; i++) {
140  if (i>0 && cpts[i].time < cpts[i-1].time-epsilon) {
141  egsWarning("DynamicShape: time index of control point %i < time index of control point %i\n",i,i-1);
142  }
143  if (cpts[i].time<0.0) {
144  egsWarning("DynamicShape: time index of control point %i < 0.0\n",i);
145  }
146  }
147 
148  // Normalize time values
149  for (int i=0; i<npts-1; i++) {
150  cpts[i].time /= cpts[npts-1].time;
151  }
152  }
153  };
154 
160  };
161 
168  EGS_Vector v(shape->getPoint(rndm));
169  return v;
170  };
171 
179  getNextShapePosition(rndm);
180  return shape->getRandomPoint(rndm);
181  };
182 
187  EGS_Float time;
188  vector<EGS_Float> trnsl;
189  vector<EGS_Float> rot;
190  };
191 
200  EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt) {
201  if (shape->supportsDirectionMethod()) {
202  getNextShapePosition(rndm);
203  shape->getPointSourceDirection(Xo, rndm, u, wt);
204  }
205  }
206 
207 protected:
208 
210 
211  vector<EGS_ControlPoint> cpts;
212 
213  int ncpts;
214 
215  EGS_Float ptime;
216 
221  void getNextShapePosition(EGS_RandomGenerator *rndm);
222 
227  void containsDynamic(bool &hasdynamic) {
228  hasdynamic = true;
229  }
230 
235  bool supportsDirectionMethod() const {
236  return shape->supportsDirectionMethod();
237  }
238 
245  int getCoord(EGS_Float rand, EGS_ControlPoint &gipt);
246 
251  void buildDynamicShape(EGS_Input *dyninp);
252 
253 };
254 
255 #endif
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition: egs_shapes.h:114
virtual bool supportsDirectionMethod() const
Definition: egs_shapes.h:206
An dynamic shape.
EGS_Float ptime
Time index corresponding to particle.
EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Get a random point from the dynamic shape.
EGS_Vector getRandomPoint(EGS_RandomGenerator *rndm)
Returns a random 3D vector.
void containsDynamic(bool &hasdynamic)
Determine whether the simulation geometry contains a dynamic shape.
EGS_DynamicShape(EGS_BaseShape *Shape, EGS_Input *dyninp, const string &Name="", EGS_ObjectFactory *f=0)
Constructor for EGS_DynamicShape.
vector< EGS_ControlPoint > cpts
Control points.
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Get the direction of the point source for a given position.
~EGS_DynamicShape()
Destructor for EGS_DynamicShape.
int ncpts
Number of control points.
EGS_BaseShape * shape
Base shape made dynamic.
bool supportsDirectionMethod() const
Check if the shape supports the direction method.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
An object factory.
int ref()
Increase the reference count to this object.
static void deleteObject(EGS_Object *o)
Delete an object.
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_RandomGenerator class header file.
EGS_BaseShape and shape classes header file.
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 representing a control point for dynamic motion.
vector< EGS_Float > rot
Rotation vector.
EGS_Float time
Time index for control point.
vector< EGS_Float > trnsl
Vector specifying x, y, z translation.