EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_gtransformed.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ gtransformed 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: Iwan Kawrakow, 2005
25 #
26 # Contributors: Frederic Tessier
27 # Reid Townson
28 # Ernesto Mainegra-Hing
29 # Alexandre Demelo
30 #
31 ###############################################################################
32 */
33 
34 
40 #ifndef EGS_GTRANSFORMED_
41 #define EGS_GTRANSFORMED_
42 
43 #include "egs_base_geometry.h"
44 #include "egs_transformations.h"
45 
46 #ifdef WIN32
47 
48  #ifdef BUILD_GTRANSFORMED_DLL
49  #define EGS_GTRANSFORMED_EXPORT __declspec(dllexport)
50  #else
51  #define EGS_GTRANSFORMED_EXPORT __declspec(dllimport)
52  #endif
53  #define EGS_GTRANSFORMED_LOCAL
54 
55 #else
56 
57  #ifdef HAVE_VISIBILITY
58  #define EGS_GTRANSFORMED_EXPORT __attribute__ ((visibility ("default")))
59  #define EGS_GTRANSFORMED_LOCAL __attribute__ ((visibility ("hidden")))
60  #else
61  #define EGS_GTRANSFORMED_EXPORT
62  #define EGS_GTRANSFORMED_LOCAL
63  #endif
64 
65 #endif
66 
132 class EGS_GTRANSFORMED_EXPORT EGS_TransformedGeometry :
133  public EGS_BaseGeometry {
134 
135 protected:
136 
139  string type;
140 
141 public:
142 
147  const string &Name = "") : EGS_BaseGeometry(Name), g(G), T(t) {
148  type = g->getType();
149  type += "T";
150  nreg = g->regions();
151  is_convex = g->isConvex();
152  has_rho_scaling = g->hasRhoScaling();
153  has_B_scaling = g->hasBScaling();
154  };
155 
157  if (!g->deref()) {
158  delete g;
159  }
160  };
161 
162  void setTransformation(const EGS_AffineTransform &t) {
163  T = t;
164  };
165 
166  int computeIntersections(int ireg, int n, const EGS_Vector &x,
167  const EGS_Vector &u, EGS_GeometryIntersections *isections) {
168  EGS_Vector xt(x), ut(u);
169  T.inverseTransform(xt);
170  T.rotateInverse(ut);
171  return g->computeIntersections(ireg,n,xt,ut,isections);
172  //return g->computeIntersections(ireg,n,x*T,u*T.getRotation(),isections);
173  };
174  bool isRealRegion(int ireg) const {
175  return g->isRealRegion(ireg);
176  };
177  bool isInside(const EGS_Vector &x) {
178  EGS_Vector xt(x);
179  T.inverseTransform(xt);
180  return g->isInside(xt);
181  //return g->isInside(x*T);
182  };
183  int isWhere(const EGS_Vector &x) {
184  EGS_Vector xt(x);
185  T.inverseTransform(xt);
186  return g->isWhere(xt);
187  //return g->isWhere(x*T);
188  };
189  int inside(const EGS_Vector &x) {
190  return isWhere(x);
191  };
192 
193  int medium(int ireg) const {
194  return g->medium(ireg);
195  };
196 
197  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x,
198  const EGS_Vector &u) {
199  return ireg >= 0 ? g->howfarToOutside(ireg,x*T,u*T.getRotation()) : 0;
200  };
201  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
202  EGS_Float &t, int *newmed=0, EGS_Vector *normal=0) {
203  EGS_Vector xt(x), ut(u);
204  T.inverseTransform(xt);
205  T.rotateInverse(ut);
206  int inew = g->howfar(ireg,xt,ut,t,newmed,normal);
207  //int inew = g->howfar(ireg,x*T,u*T.getRotation(),t,newmed,normal);
208  if (inew != ireg && normal) {
209  *normal = T.getRotation()*(*normal);
210  }
211  return inew;
212  };
213 
214  EGS_Float hownear(int ireg, const EGS_Vector &x) {
215  EGS_Vector xt(x);
216  T.inverseTransform(xt);
217  return g->hownear(ireg,xt);
218  //return g->hownear(ireg,x*T);
219  };
220 
221  void getNextGeom(EGS_RandomGenerator *rndm) {
222  // calls getNextGeom on its component geometries to update dynamic
223  // geometries in the simulation
224  g->getNextGeom(rndm);
225 
226  };
227 
228  void updatePosition(EGS_Float time) {
229  // calls updatePosition on its component geometries to update dynamic
230  // geometries in the simulation
231  g->updatePosition(time);
232  };
233 
234  void containsDynamic(bool &hasdynamic) {
235  // calls containsDynamic on its component geometries (only calls if
236  // hasDynamic is false, as if it is true we already found one)
237  if (!hasdynamic) {
238  g->containsDynamic(hasdynamic);
239  }
240  };
241 
242  int getMaxStep() const {
243  return g->getMaxStep();
244  };
245 
246  // Not sure about the following.
247  // If I leave the implementation that way, all transformed copies of a
248  // geometry share the same boolean properties. But that may not be
249  // what the user wants. So, I should implement both options:
250  // all copies share the same properties and the user has the options
251  // to define separate properties for each copy.
252  bool hasBooleanProperty(int ireg, EGS_BPType prop) const {
253  return g->hasBooleanProperty(ireg,prop);
254  };
255  void setBooleanProperty(EGS_BPType prop) {
256  g->setBooleanProperty(prop);
257  };
258  void addBooleanProperty(int bit) {
259  g->addBooleanProperty(bit);
260  };
261  void setBooleanProperty(EGS_BPType prop, int start, int end, int step=1) {
262  g->setBooleanProperty(prop,start,end,step);
263  };
264  void addBooleanProperty(int bit, int start, int end, int step=1) {
265  g->addBooleanProperty(bit,start,end,step);
266  };
267 
268  const string &getType() const {
269  return type;
270  };
271 
272  EGS_Float getRelativeRho(int ireg) const {
273  return g->getRelativeRho(ireg);
274  }
275  void setRelativeRho(int start, int end, EGS_Float rho);
276 
277  void setRelativeRho(EGS_Input *);
278 
279  EGS_Float getBScaling(int ireg) const {
280  return g->getBScaling(ireg);
281  }
282  void setBScaling(int start, int end, EGS_Float bf);
283 
284  void setBScaling(EGS_Input *);
285 
286  virtual void getLabelRegions(const string &str, vector<int> &regs);
287 
288 protected:
289 
296  void setMedia(EGS_Input *inp,int,const int *);
297 
298 };
299 
300 #endif
A class providing affine transformations.
const EGS_RotationMatrix & getRotation() const
Returns the rotation matrix of the affine transformation object.
void rotateInverse(EGS_Vector &v) const
Applies the inverse rotation to the vector v.
void inverseTransform(EGS_Vector &v) const
Applies the inverse transformation to the vector v.
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)
int deref()
Decrease the reference count to this geometry.
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.
bool hasBScaling() const
Does this geometry object have a B field scaling feature?
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.
bool isConvex() const
Is the geometry convex?
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.
bool hasRhoScaling() const
Does this geometry object have a mass density scaling feature?
virtual int medium(int ireg) const
Returns the medium index in region ireg.
int regions() const
Returns the number of local regions in this geometry.
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 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 transformed geometry.
EGS_TransformedGeometry(EGS_BaseGeometry *G, const EGS_AffineTransform &t, const string &Name="")
Construct a geometry that is a copy of the geometry G transformed by t.
string type
The geometry type.
EGS_BaseGeometry * g
The geometry being transformed.
EGS_AffineTransform T
The affine transformation.
A class representing 3D vectors.
Definition: egs_vector.h:57
EGS_BaseGeometry class header file.
EGS_AffineTransform and EGS_RotationMatrix class header file.