EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_rectangle.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ rectangle 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: Frederic Tessier
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_RECTANGLE_
38 #define EGS_RECTANGLE_
39 
40 #include "egs_shapes.h"
41 #include "egs_rndm.h"
42 
43 #ifdef WIN32
44 
45  #ifdef BUILD_RECTANGLE_DLL
46  #define EGS_RECTANGLE_EXPORT __declspec(dllexport)
47  #else
48  #define EGS_RECTANGLE_EXPORT __declspec(dllimport)
49  #endif
50  #define EGS_RECTANGLE_LOCAL
51 
52 #else
53 
54  #ifdef HAVE_VISIBILITY
55  #define EGS_RECTANGLE_EXPORT __attribute__ ((visibility ("default")))
56  #define EGS_RECTANGLE_LOCAL __attribute__ ((visibility ("hidden")))
57  #else
58  #define EGS_RECTANGLE_EXPORT
59  #define EGS_RECTANGLE_LOCAL
60  #endif
61 
62 #endif
63 
87 class EGS_RECTANGLE_EXPORT EGS_RectangleShape : public EGS_SurfaceShape {
88 
89 public:
90 
91  EGS_RectangleShape(EGS_Float Xmin, EGS_Float Xmax, EGS_Float Ymin,
92  EGS_Float Ymax, const string &Name="",EGS_ObjectFactory *f=0) :
93  EGS_SurfaceShape(Name,f), xmin(Xmin), xmax(Xmax), ymin(Ymin),
94  ymax(Ymax) {
95  EGS_Float tmp;
96  if (xmin > xmax) {
97  tmp = xmax;
98  xmax = xmin;
99  xmin = tmp;
100  }
101  if (ymin > ymax) {
102  tmp = ymax;
103  ymax = ymin;
104  ymin = tmp;
105  }
106  dx = xmax - xmin;
107  dy = ymax - ymin;
108  otype = "rectangle";
109  A = dx*dy;
110  };
111  ~EGS_RectangleShape() {};
113  return EGS_Vector(xmin + dx*rndm->getUniform(),
114  ymin + dy*rndm->getUniform(),
115  0);
116  };
117 
118 protected:
119 
120  EGS_Float xmin, xmax, ymin, ymax, dx, dy;
121 };
122 
130 class EGS_RECTANGLE_EXPORT EGS_RectangularRing : public EGS_SurfaceShape {
131 
132 public:
133 
134  EGS_RectangularRing(EGS_Float Xmin, EGS_Float Xmax, EGS_Float Ymin,
135  EGS_Float Ymax, EGS_Float Xmin_i, EGS_Float Xmax_i, EGS_Float Ymin_i,
136  EGS_Float Ymax_i, const string &Name="",EGS_ObjectFactory *f=0);
138  bool isValid() const {
139  return valid;
140  };
142  EGS_Float eta = rndm->getUniform();
143  int j=0;
144  while (eta > p[j]) {
145  j++;
146  }
147  return r[j]->getPoint(rndm);
148  };
149 
150 protected:
151 
152  EGS_RectangleShape *r[4];
153  EGS_Float p[4];
154  bool valid;
155 
156 };
157 
158 #endif
A surface shape.
Definition: egs_shapes.h:252
EGS_SurfaceShape(const string &Name="", EGS_ObjectFactory *f=0)
Construct a surface shape named Name.
Definition: egs_shapes.h:257
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.
A &quot;rectangular ring&quot;.
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
Definition: egs_rndm.h:103
A rectangular shape.
Definition: egs_rectangle.h:87