EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_polygon_shape.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ polygon 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, 2005
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_POLYGON_SHAPE_
38 #define EGS_POLYGON_SHAPE_
39 
40 #include "egs_shapes.h"
41 #include "egs_rndm.h"
42 #include "egs_alias_table.h"
43 
44 #ifdef WIN32
45 
46  #ifdef BUILD_POLYGON_SHAPE_DLL
47  #define EGS_POLYGON_SHAPE_EXPORT __declspec(dllexport)
48  #else
49  #define EGS_POLYGON_SHAPE_EXPORT __declspec(dllimport)
50  #endif
51  #define EGS_POLYGON_SHAPE_LOCAL
52 
53 #else
54 
55  #ifdef HAVE_VISIBILITY
56  #define EGS_POLYGON_SHAPE_EXPORT __attribute__ ((visibility ("default")))
57  #define EGS_POLYGON_SHAPE_LOCAL __attribute__ ((visibility ("hidden")))
58  #else
59  #define EGS_POLYGON_SHAPE_EXPORT
60  #define EGS_POLYGON_SHAPE_LOCAL
61  #endif
62 
63 #endif
64 
73 class EGS_POLYGON_SHAPE_EXPORT EGS_TriangleShape : public EGS_SurfaceShape {
74 
75 public:
76 
77  EGS_TriangleShape(const vector<EGS_Float> &points, const string &Name="",
78  EGS_ObjectFactory *f=0);
79  EGS_TriangleShape(const EGS_Float *points, const string &Name="",
80  EGS_ObjectFactory *f=0);
81  ~EGS_TriangleShape() {};
83  EGS_Float eta_a = sqrt(rndm->getUniform());
84  EGS_Float eta_b = eta_a*rndm->getUniform();
85  eta_a = 1 - eta_a;
86  return EGS_Vector(xo + ax*eta_a + bx*eta_b,
87  yo + ay*eta_a + by*eta_b,
88  0);
89  };
90 
91 protected:
92 
93  EGS_Float xo, yo, ax, ay, bx, by;
94 
95 };
96 
97 
117 class EGS_POLYGON_SHAPE_EXPORT EGS_PolygonShape : public EGS_SurfaceShape {
118 
119 public:
120 
121  EGS_PolygonShape(const vector<EGS_Float> &points, const string &Name="",
122  EGS_ObjectFactory *f=0);
123  ~EGS_PolygonShape() {
124  if (n > 0) {
125  for (int j=0; j<n-2; j++) {
126  delete triangle[j];
127  }
128  delete [] triangle;
129  delete table;
130  }
131  };
133  int j = table->sampleBin(rndm);
134  return triangle[j]->getPoint(rndm);
135  };
136 
137 protected:
138 
139  int n; // number of triangles
140  EGS_TriangleShape **triangle;
141  EGS_AliasTable *table;
142 
143 };
144 
145 #endif
A surface shape.
Definition: egs_shapes.h:252
EGS_AliasTable class header file.
A class for sampling random values from a given probability distribution using the alias table techni...
A class representing 3D vectors.
Definition: egs_vector.h:56
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.
EGS_BaseShape and shape classes header file.
An object factory.
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
Definition: egs_rndm.h:103
A triangular shape.
A polygon shape.