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 #
30 ###############################################################################
31 */
32 
33 
39 #ifndef EGS_GTRANSFORMED_
40 #define EGS_GTRANSFORMED_
41 
42 #include "egs_base_geometry.h"
43 #include "egs_transformations.h"
44 
45 #ifdef WIN32
46 
47  #ifdef BUILD_GTRANSFORMED_DLL
48  #define EGS_GTRANSFORMED_EXPORT __declspec(dllexport)
49  #else
50  #define EGS_GTRANSFORMED_EXPORT __declspec(dllimport)
51  #endif
52  #define EGS_GTRANSFORMED_LOCAL
53 
54 #else
55 
56  #ifdef HAVE_VISIBILITY
57  #define EGS_GTRANSFORMED_EXPORT __attribute__ ((visibility ("default")))
58  #define EGS_GTRANSFORMED_LOCAL __attribute__ ((visibility ("hidden")))
59  #else
60  #define EGS_GTRANSFORMED_EXPORT
61  #define EGS_GTRANSFORMED_LOCAL
62  #endif
63 
64 #endif
65 
131 class EGS_GTRANSFORMED_EXPORT EGS_TransformedGeometry :
132  public EGS_BaseGeometry {
133 
134 protected:
135 
138  string type;
139 
140 public:
141 
146  const string &Name = "") : EGS_BaseGeometry(Name), g(G), T(t) {
147  type = g->getType();
148  type += "T";
149  nreg = g->regions();
150  is_convex = g->isConvex();
151  has_rho_scaling = g->hasRhoScaling();
152  has_B_scaling = g->hasBScaling();
153  };
154 
156  if (!g->deref()) {
157  delete g;
158  }
159  };
160 
161  void setTransformation(const EGS_AffineTransform &t) {
162  T = t;
163  };
164 
165  int computeIntersections(int ireg, int n, const EGS_Vector &x,
166  const EGS_Vector &u, EGS_GeometryIntersections *isections) {
167  EGS_Vector xt(x), ut(u);
168  T.inverseTransform(xt);
169  T.rotateInverse(ut);
170  return g->computeIntersections(ireg,n,xt,ut,isections);
171  //return g->computeIntersections(ireg,n,x*T,u*T.getRotation(),isections);
172  };
173  bool isRealRegion(int ireg) const {
174  return g->isRealRegion(ireg);
175  };
176  bool isInside(const EGS_Vector &x) {
177  EGS_Vector xt(x);
178  T.inverseTransform(xt);
179  return g->isInside(xt);
180  //return g->isInside(x*T);
181  };
182  int isWhere(const EGS_Vector &x) {
183  EGS_Vector xt(x);
184  T.inverseTransform(xt);
185  return g->isWhere(xt);
186  //return g->isWhere(x*T);
187  };
188  int inside(const EGS_Vector &x) {
189  return isWhere(x);
190  };
191 
192  int medium(int ireg) const {
193  return g->medium(ireg);
194  };
195 
196  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x,
197  const EGS_Vector &u) {
198  return ireg >= 0 ? g->howfarToOutside(ireg,x*T,u*T.getRotation()) : 0;
199  };
200  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
201  EGS_Float &t, int *newmed=0, EGS_Vector *normal=0) {
202  EGS_Vector xt(x), ut(u);
203  T.inverseTransform(xt);
204  T.rotateInverse(ut);
205  int inew = g->howfar(ireg,xt,ut,t,newmed,normal);
206  //int inew = g->howfar(ireg,x*T,u*T.getRotation(),t,newmed,normal);
207  if (inew != ireg && normal) {
208  *normal = T.getRotation()*(*normal);
209  }
210  return inew;
211  };
212 
213  EGS_Float hownear(int ireg, const EGS_Vector &x) {
214  EGS_Vector xt(x);
215  T.inverseTransform(xt);
216  return g->hownear(ireg,xt);
217  //return g->hownear(ireg,x*T);
218  };
219 
220  int getMaxStep() const {
221  return g->getMaxStep();
222  };
223 
224  // Not sure about the following.
225  // If I leave the implementation that way, all transformed copies of a
226  // geometry share the same boolean properties. But that may not be
227  // what the user wants. So, I should implement both options:
228  // all copies share the same properties and the user has the options
229  // to define separate properties for each copy.
230  bool hasBooleanProperty(int ireg, EGS_BPType prop) const {
231  return g->hasBooleanProperty(ireg,prop);
232  };
233  void setBooleanProperty(EGS_BPType prop) {
234  g->setBooleanProperty(prop);
235  };
236  void addBooleanProperty(int bit) {
237  g->addBooleanProperty(bit);
238  };
239  void setBooleanProperty(EGS_BPType prop, int start, int end, int step=1) {
240  g->setBooleanProperty(prop,start,end,step);
241  };
242  void addBooleanProperty(int bit, int start, int end, int step=1) {
243  g->addBooleanProperty(bit,start,end,step);
244  };
245 
246  const string &getType() const {
247  return type;
248  };
249 
250  EGS_Float getRelativeRho(int ireg) const {
251  return g->getRelativeRho(ireg);
252  }
253  void setRelativeRho(int start, int end, EGS_Float rho);
254 
255  void setRelativeRho(EGS_Input *);
256 
257  EGS_Float getBScaling(int ireg) const {
258  return g->getBScaling(ireg);
259  }
260  void setBScaling(int start, int end, EGS_Float bf);
261 
262  void setBScaling(EGS_Input *);
263 
264  virtual void getLabelRegions(const string &str, vector<int> &regs);
265 
266 protected:
267 
274  void setMedia(EGS_Input *inp,int,const int *);
275 
276 };
277 
278 #endif
virtual const string & getType() const =0
Get the geometry type.
virtual bool isInside(const EGS_Vector &x)=0
Is the position x inside the geometry?
virtual bool hasBooleanProperty(int ireg, EGS_BPType prop) const
Is the boolean property prop set for region ireg ?
virtual int medium(int ireg) const
Returns the medium index in region ireg.
EGS_BaseGeometry * g
The geometry being transformed.
virtual EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u)
A class providing affine transformations.
virtual int getMaxStep() const
Returns the maximum number of steps through the geometry.
A class representing 3D vectors.
Definition: egs_vector.h:56
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.
virtual int isWhere(const EGS_Vector &x)=0
In which region is poisition x?
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.
string type
The geometry type.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual void setRelativeRho(int start, int end, EGS_Float rho)
Set the relative mass density in regions.
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.
A transformed geometry.
virtual void getLabelRegions(const string &str, vector< int > &regs)
Get the list of all regions labeled with str.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
virtual int inside(const EGS_Vector &x)=0
Returns the region index, if inside, or -1 if outside (obsolete)
virtual int computeIntersections(int ireg, int n, const EGS_Vector &x, const EGS_Vector &u, EGS_GeometryIntersections *isections)
Calculates intersection distances to region boundaries.
EGS_AffineTransform and EGS_RotationMatrix class header file.
virtual EGS_Float hownear(int ireg, const EGS_Vector &x)=0
Calculate the distance to a boundary for position x in any direction.
virtual EGS_Float getRelativeRho(int ireg) const
Get the relative mass density in region ireg.
EGS_AffineTransform T
The affine transformation.
virtual bool isRealRegion(int ireg) const
Returnes true if ireg is a real region, false otherwise.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_BaseGeometry class header file.
virtual void addBooleanProperty(int bit)
Add a boolean property for the entire geometry by setting the bit&#39;th bit.
virtual void setBooleanProperty(EGS_BPType prop)
Set the boolean properties of the entire geometry to prop.