EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_shape_collection.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ shape collection 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: Marc Chamberland
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_SHAPE_COLLECTION_
38 #define EGS_SHAPE_COLLECTION_
39 
40 #include "egs_shapes.h"
41 #include "egs_alias_table.h"
42 #include "egs_rndm.h"
43 
44 #ifdef WIN32
45 
46  #ifdef BUILD_SHAPE_COLLECTION_DLL
47  #define EGS_SHAPE_COLLECTION_EXPORT __declspec(dllexport)
48  #else
49  #define EGS_SHAPE_COLLECTION_EXPORT __declspec(dllimport)
50  #endif
51  #define EGS_SHAPE_COLLECTION_LOCAL
52 
53 #else
54 
55  #ifdef HAVE_VISIBILITY
56  #define EGS_SHAPE_COLLECTION_EXPORT __attribute__ ((visibility ("default")))
57  #define EGS_SHAPE_COLLECTION_LOCAL __attribute__ ((visibility ("hidden")))
58  #else
59  #define EGS_SHAPE_COLLECTION_EXPORT
60  #define EGS_SHAPE_COLLECTION_LOCAL
61  #endif
62 
63 #endif
64 
95 class EGS_SHAPE_COLLECTION_EXPORT EGS_ShapeCollection : public EGS_BaseShape {
96 
97 public:
98 
99  EGS_ShapeCollection(const vector<EGS_BaseShape *> &Shapes,
100  const vector<EGS_Float> &Probs, const string &Name="",
101  EGS_ObjectFactory *f=0);
103  if (nshape > 0) {
104  for (int j=0; j<nshape; j++) {
105  EGS_Object::deleteObject(shapes[j]);
106  }
107  delete [] shapes;
108  delete table;
109  }
110  };
111 
113  int j = table->sample(rndm);
114  return shapes[j]->getRandomPoint(rndm);
115  };
116 
117  bool supportsDirectionMethod() const {
118  for (int j=0; j<nshape; j++) {
119  if (!shapes[j]->supportsDirectionMethod()) {
120  return false;
121  }
122  }
123  return true;
124  };
125 
126  EGS_Float area() const {
127  EGS_Float A = 0;
128  for (int j=0; j<nshape; j++) {
129  A += shapes[j]->area();
130  }
131  return A;
132  };
133 
134  void getPointSourceDirection(const EGS_Vector &Xo,
135  EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt) {
136  EGS_Vector xo = T ? Xo*(*T) : Xo;
137  int j = table->sample(rndm);
138  shapes[j]->getPointSourceDirection(xo,rndm,u,wt);
139  if (T) {
140  T->rotate(u);
141  }
142  };
143 
144 protected:
145 
146  int nshape;
147  EGS_BaseShape **shapes;
148  EGS_SimpleAliasTable *table;
149 
150 };
151 
152 #endif
EGS_AliasTable class header file.
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 EGS_Float area() const
Definition: egs_shapes.h:232
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 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.
A shape collection.