EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_gaussian_shape.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ guassian 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_GAUSSIAN_SHAPE_
38 #define EGS_GAUSSIAN_SHAPE_
39 
40 #include "egs_shapes.h"
41 #include "egs_rndm.h"
42 
43 #ifdef WIN32
44 
45  #ifdef BUILD_GAUSSIAN_SHAPE_DLL
46  #define EGS_GAUSSIAN_SHAPE_EXPORT __declspec(dllexport)
47  #else
48  #define EGS_GAUSSIAN_SHAPE_EXPORT __declspec(dllimport)
49  #endif
50  #define EGS_GAUSSIAN_SHAPE_LOCAL
51 
52 #else
53 
54  #ifdef HAVE_VISIBILITY
55  #define EGS_GAUSSIAN_SHAPE_EXPORT __attribute__ ((visibility ("default")))
56  #define EGS_GAUSSIAN_SHAPE_LOCAL __attribute__ ((visibility ("hidden")))
57  #else
58  #define EGS_GAUSSIAN_SHAPE_EXPORT
59  #define EGS_GAUSSIAN_SHAPE_LOCAL
60  #endif
61 
62 #endif
63 
88 class EGS_GAUSSIAN_SHAPE_EXPORT EGS_GaussianShape : public EGS_BaseShape {
89 
90 public:
91 
92  EGS_GaussianShape(EGS_BaseShape *Shape, EGS_Float sx, EGS_Float sy,
93  EGS_Float sz, const string &Name="",EGS_ObjectFactory *f=0) :
94  EGS_BaseShape(Name,f), shape(Shape), sig_x(sx), sig_y(sy), sig_z(sz) {
95  if (shape) {
96  shape->ref();
97  otype = shape->getObjectType();
98  otype += "with Gaussian ditribution";
99  if (sig_x < 0) {
100  sig_x = -sig_x*0.4246609;
101  }
102  if (sig_y < 0) {
103  sig_y = -sig_y*0.4246609;
104  }
105  if (sig_z < 0) {
106  sig_z = -sig_z*0.4246609;
107  }
108  }
109  else {
110  otype = "Invalid GaussianShape";
111  }
112  };
113  ~EGS_GaussianShape() {
115  };
117  EGS_Vector v(shape->getPoint(rndm));
118  if (sig_x > 0) {
119  v.x += sig_x*rndm->getGaussian();
120  }
121  if (sig_y > 0) {
122  v.y += sig_y*rndm->getGaussian();
123  }
124  if (sig_z > 0) {
125  v.z += sig_z*rndm->getGaussian();
126  }
127  return v;
128  };
129  bool supportsDirectionMethod() const {
130  return true;
131  };
132  void getPointSourceDirection(const EGS_Vector &Xo,
133  EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt) {
134  EGS_Vector xo = T ? Xo*(*T) : Xo;
135  EGS_Vector x = getPoint(rndm);
136  u = x - xo;
137  EGS_Float d2i = 1/u.length2(), di = sqrt(d2i);
138  u *= di;
139  wt = 1; //wt = A*fabs(u.z)*d2i;
140  if (T) {
141  T->rotate(u);
142  }
143  };
144 
145 protected:
146 
147  EGS_BaseShape *shape;
148  EGS_Float sig_x, sig_y, sig_z;
149 
150 };
151 
152 #endif
A class representing 3D vectors.
Definition: egs_vector.h:56
static void deleteObject(EGS_Object *o)
Delete an object.
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
virtual bool supportsDirectionMethod() const
Definition: egs_shapes.h:204
EGS_RandomGenerator class header file.
virtual void getPointSourceDirection(const EGS_Vector &xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Definition: egs_shapes.h:220
A Gaussian shape.
EGS_BaseShape and shape classes header file.
An object factory.
EGS_Float getGaussian()
Returns a Gaussian distributed random number with mean zero and standard deviation 1...
Definition: egs_rndm.h:161
EGS_BaseShape(const string &Name="", EGS_ObjectFactory *f=0)
Construct a shape named Name.
Definition: egs_shapes.h:117
EGS_Float x
x-component
Definition: egs_vector.h:60