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 
45 #include "egs_base_geometry.h"
46 
47 #ifdef WIN32
48 
49  #ifdef BUILD_SPHERES_DLL
50  #define EGS_SPHERES_EXPORT __declspec(dllexport)
51  #else
52  #define EGS_SPHERES_EXPORT __declspec(dllimport)
53  #endif
54  #define EGS_SPHERES_LOCAL
55 
56 #else
57 
58  #ifdef HAVE_VISIBILITY
59  #define EGS_SPHERES_EXPORT __attribute__ ((visibility ("default")))
60  #define EGS_SPHERES_LOCAL __attribute__ ((visibility ("hidden")))
61  #else
62  #define EGS_SPHERES_EXPORT
63  #define EGS_SPHERES_LOCAL
64  #endif
65 
66 #endif
67 
139 class EGS_SPHERES_EXPORT EGS_cSpheres : public EGS_BaseGeometry {
140 
141 public:
142 
143  // construct some CONCENTRIC spheres
144  EGS_cSpheres(int ns, const EGS_Float *radius, const EGS_Vector &position,
145  const string &Name = "");
146 
147  // destruct spheres from memory
148  ~EGS_cSpheres() {
149  if (nreg) {
150  delete [] R2;
151  delete [] R;
152  }
153  }
154 
155  enum DIRS {RDIR};
156 
157  // method to determine which spheres we are in(between)
158  int inside(const EGS_Vector &x);
159 
160  bool isInside(const EGS_Vector &x);
161  int isWhere(const EGS_Vector &x);
162 
163  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x,
164  const EGS_Vector &u);
165  // howfar is particle trajectory from sphere boundry
166  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u,
167  EGS_Float &t, int *newmed=0, EGS_Vector *normal=0);
168 
169  // hownear - closest perpendicular distance to sphere surface
170  EGS_Float hownear(int ireg, const EGS_Vector &x);
171 
172  int getMaxStep() const {
173  return 2*nreg;
174  };
175 
176  const string &getType() const {
177  return type;
178  };
179 
180  void printInfo() const;
181 
183  EGS_Float getBound(int idir, int ind);
184 
186  int getNRegDir(int dir);
187 
189  EGS_Float getVolume(int ireg);
190 
191 private:
192 
193  EGS_Float *R2; // radius^2
194  EGS_Float *R; // radius
195  EGS_Vector xo; // for concentric spheres, all centres coincide
196  static string type;
197 
198  std::vector<EGS_Float> rbounds;
199  std::vector<EGS_Float> vol;
200 };
201 
202 
203 
209 class EGS_SPHERES_EXPORT EGS_cSphericalShell : public EGS_BaseGeometry {
210 
211 public:
212 
213  EGS_cSphericalShell(int ns, const EGS_Float *radius, const EGS_Vector &position, const string &Name = "");
214 
215  // destruct spheres from memory
217  if (nreg) {
218  delete [] R2;
219  delete [] R;
220  }
221  }
222 
223  enum DIRS {RDIR};
224 
225  // method to determine which spheres we are in(between)
226  int inside(const EGS_Vector &x);
227 
228  bool isInside(const EGS_Vector &x);
229  int isWhere(const EGS_Vector &x);
230 
231  EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u);
232 
233  // howfar is particle trajectory from sphere boundry
234  int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0);
235 
236  // hownear - closest perpendicular distance to sphere surface
237  EGS_Float hownear(int ireg, const EGS_Vector &x);
238 
239  int getMaxStep() const {
240  return 2*(nreg+1);
241  };
242 
243  const string &getType() const {
244  return type;
245  };
246 
247  void printInfo() const;
248 
249  EGS_Float getBound(int idir, int ind);
250 
251  int getNRegDir(int dir);
252 
253  EGS_Float getVolume(int ireg);
254 
255 private:
256 
257  EGS_Float *R2; // radius^2
258  EGS_Float *R; // radius
259  EGS_Vector xo; // for concentric spheres, all centres coincide
260  static string type;
261 
262  std::vector<EGS_Float> vol;
263 };
264 
265 
266 #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:139
Implements a spherical shell geometry with a hollow centre.
Definition: egs_spheres.h:209
EGS_BaseGeometry class header file.