EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_spheres.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ spheres 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: Reid Townson
27 # Randle Taylor
28 #
29 ###############################################################################
30 */
31 
32 
38 #ifndef EGS_CSPHERES_
39 #define EGS_CSPHERES_
40 
41 #include <vector>
42 
43 #include "egs_base_geometry.h"
44 
45 #ifdef WIN32
46 
47  #ifdef BUILD_SPHERES_DLL
48  #define EGS_SPHERES_EXPORT __declspec(dllexport)
49  #else
50  #define EGS_SPHERES_EXPORT __declspec(dllimport)
51  #endif
52  #define EGS_SPHERES_LOCAL
53 
54 #else
55 
56  #ifdef HAVE_VISIBILITY
57  #define EGS_SPHERES_EXPORT __attribute__ ((visibility ("default")))
58  #define EGS_SPHERES_LOCAL __attribute__ ((visibility ("hidden")))
59  #else
60  #define EGS_SPHERES_EXPORT
61  #define EGS_SPHERES_LOCAL
62  #endif
63 
64 #endif
65 
137 class EGS_SPHERES_EXPORT EGS_cSpheres : public EGS_BaseGeometry {
138 
139 public:
140 
141  // construct some CONCENTRIC spheres
142  EGS_cSpheres(int ns, const EGS_Float *radius, const EGS_Vector &position,
143  const string &Name = "");
144 
145  // destruct spheres from memory
146  ~EGS_cSpheres() {
147  if (nreg) {
148  delete [] R2;
149  delete [] R;
150  }
151  }
152 
153  enum DIRS {RDIR};
154 
155  // method to determine which spheres we are in(between)
156  int inside(const EGS_Vector &x);
157 
158  bool isInside(const EGS_Vector &x);
159  int isWhere(const EGS_Vector &x);
160 
161  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x,
162  const EGS_Vector &u);
163  // howfar is particle trajectory from sphere boundry
164  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
165  EGS_Float &t, int *newmed=0, EGS_Vector *normal=0);
166 
167  // hownear - closest perpendicular distance to sphere surface
168  EGS_Float hownear(int ireg, const EGS_Vector &x);
169 
170  int getMaxStep() const {
171  return 2*nreg;
172  };
173 
174  const string &getType() const {
175  return type;
176  };
177 
178  void printInfo() const;
179 
181  EGS_Float getBound(int idir, int ind);
182 
184  int getNRegDir(int dir);
185 
187  EGS_Float getVolume(int ireg);
188 
189 private:
190 
191  EGS_Float *R2; // radius^2
192  EGS_Float *R; // radius
193  EGS_Vector xo; // for concentric spheres, all centres coincide
194  static string type;
195 
196  std::vector<EGS_Float> rbounds;
197  std::vector<EGS_Float> vol;
198 };
199 
200 
201 
207 class EGS_SPHERES_EXPORT EGS_cSphericalShell : public EGS_BaseGeometry {
208 
209 public:
210 
211  EGS_cSphericalShell(int ns, const EGS_Float *radius, const EGS_Vector &position, const string &Name = "");
212 
213  // destruct spheres from memory
215  if (nreg) {
216  delete [] R2;
217  delete [] R;
218  }
219  }
220 
221  enum DIRS {RDIR};
222 
223  // method to determine which spheres we are in(between)
224  int inside(const EGS_Vector &x);
225 
226  bool isInside(const EGS_Vector &x);
227  int isWhere(const EGS_Vector &x);
228 
229  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u);
230 
231  // howfar is particle trajectory from sphere boundry
232  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0);
233 
234  // hownear - closest perpendicular distance to sphere surface
235  EGS_Float hownear(int ireg, const EGS_Vector &x);
236 
237  int getMaxStep() const {
238  return 2*(nreg+1);
239  };
240 
241  const string &getType() const {
242  return type;
243  };
244 
245  void printInfo() const;
246 
247  EGS_Float getBound(int idir, int ind);
248 
249  int getNRegDir(int dir);
250 
251  EGS_Float getVolume(int ireg);
252 
253 private:
254 
255  EGS_Float *R2; // radius^2
256  EGS_Float *R; // radius
257  EGS_Vector xo; // for concentric spheres, all centres coincide
258  static string type;
259 
260  std::vector<EGS_Float> vol;
261 };
262 
263 
264 #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 int getNRegDir(int idir)
virtual void printInfo() const
Print information about this geometry.
virtual EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u)
virtual int getMaxStep() const
Returns the maximum number of steps through the geometry.
A class representing 3D vectors.
Definition: egs_vector.h:56
virtual EGS_Float getVolume(int ireg)
Calculates the volume of region ireg.
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.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual EGS_Float getBound(int idir, int ind)
Returns region boundaries in direction determined by idir.
virtual int inside(const EGS_Vector &x)=0
Returns the region index, if inside, or -1 if outside (obsolete)
Implements a spherical shell geometry with a hollow centre.
Definition: egs_spheres.h:207
virtual EGS_Float hownear(int ireg, const EGS_Vector &x)=0
Calculate the distance to a boundary for position x in any direction.
A set of concentric spheres.
Definition: egs_spheres.h:137
EGS_BaseGeometry class header file.
int nreg
Number of local regions in this geometry.