EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_voxelized_shape.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ voxelized shape 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, 2009
25 #
26 # Contributors: Frederic Tessier
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_VOXELIZED_SHAPE_
38 #define EGS_VOXELIZED_SHAPE_
39 
40 #include "egs_shapes.h"
41 #include "egs_rndm.h"
42 #include "egs_math.h"
43 #include "egs_alias_table.h"
44 
45 #ifdef WIN32
46 
47  #ifdef BUILD_VOXELIZED_SHAPE_DLL
48  #define EGS_VOXELIZED_SHAPE_EXPORT __declspec(dllexport)
49  #else
50  #define EGS_VOXELIZED_SHAPE_EXPORT __declspec(dllimport)
51  #endif
52  #define EGS_VOXELIZED_SHAPE_LOCAL
53 
54 #else
55 
56  #ifdef HAVE_VISIBILITY
57  #define EGS_VOXELIZED_SHAPE_EXPORT __attribute__ ((visibility ("default")))
58  #define EGS_VOXELIZED_SHAPE_LOCAL __attribute__ ((visibility ("hidden")))
59  #else
60  #define EGS_VOXELIZED_SHAPE_EXPORT
61  #define EGS_VOXELIZED_SHAPE_LOCAL
62  #endif
63 
64 #endif
65 
97 class EGS_VOXELIZED_SHAPE_EXPORT EGS_VoxelizedShape : public EGS_BaseShape {
98 
99 public:
100 
106  EGS_VoxelizedShape(int file_format, const char *fname,const string &Name="",
107  EGS_ObjectFactory *f=0);
109  void EGS_VoxelizedShapeFormat0(const char *fname,const string &Name="",
110  EGS_ObjectFactory *f=0);
112  int bin = prob->sample(rndm);
113  int voxel = type == 0 ? bin : map[bin];
114  int iz = voxel/nxy;
115  voxel -= iz*nxy;
116  int iy = voxel/nx;
117  int ix = voxel - iy*nx;
118  EGS_Float eta_x = rndm->getUniform(),
119  eta_y = rndm->getUniform(),
120  eta_z = rndm->getUniform();
121  return EGS_Vector(xpos[ix]*(1-eta_x) + xpos[ix+1]*eta_x,
122  ypos[iy]*(1-eta_y) + ypos[iy+1]*eta_y,
123  zpos[iz]*(1-eta_z) + zpos[iz+1]*eta_z);
124  };
125 
126  bool isValid() const {
127  return (type == 0 || type == 1);
128  };
129 
130 protected:
131 
132  EGS_SimpleAliasTable *prob;
133  EGS_Float *xpos;
134  EGS_Float *ypos;
135  EGS_Float *zpos;
136  int *map;
137  int nx, ny, nz, nxy, nreg;
138  int type;
139 };
140 
141 #endif
int nx
! Voxel map (for type=1)
EGS_AliasTable class header file.
A class representing 3D vectors.
Definition: egs_vector.h:56
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition: egs_shapes.h:112
virtual EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Sample and return a random 3D vector.
Definition: egs_shapes.h:149
Base random number generator class. All random number generators should be derived from this class...
Definition: egs_rndm.h:67
EGS_RandomGenerator class header file.
A &quot;voxelized shape&quot;.
A class for sampling random bins from a given probability distribution using the alias table techniqu...
EGS_BaseShape and shape classes header file.
An object factory.
EGS_Float * xpos
! The alias table for randomly picking voxels
Attempts to fix broken math header files.
EGS_Float * zpos
! The y-positions of the grid
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
Definition: egs_rndm.h:103
int * map
! The z-positions of the grid
EGS_Float * ypos
! The x-positions of the grid