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