EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_transformed_source.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ transformed source 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: Reid Townson
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_TRANSFORMED_SOURCE_
38 #define EGS_TRANSFORMED_SOURCE_
39 
40 #include "egs_vector.h"
41 #include "egs_base_source.h"
42 #include "egs_rndm.h"
43 #include "egs_shapes.h"
44 
45 
46 #ifdef WIN32
47 
48  #ifdef BUILD_TRANSFORMED_SOURCE_DLL
49  #define EGS_TRANSFORMED_SOURCE_EXPORT __declspec(dllexport)
50  #else
51  #define EGS_TRANSFORMED_SOURCE_EXPORT __declspec(dllimport)
52  #endif
53  #define EGS_TRANSFORMED_SOURCE_LOCAL
54 
55 #else
56 
57  #ifdef HAVE_VISIBILITY
58  #define EGS_TRANSFORMED_SOURCE_EXPORT __attribute__ ((visibility ("default")))
59  #define EGS_TRANSFORMED_SOURCE_LOCAL __attribute__ ((visibility ("hidden")))
60  #else
61  #define EGS_TRANSFORMED_SOURCE_EXPORT
62  #define EGS_TRANSFORMED_SOURCE_LOCAL
63  #endif
64 
65 #endif
66 
121 class EGS_TRANSFORMED_SOURCE_EXPORT EGS_TransformedSource :
122  public EGS_BaseSource {
123 
124 public:
125 
131  const string &Name="", EGS_ObjectFactory *f=0) :
132  EGS_BaseSource(Name,f), source(Source), T(0) {
133  setUp(t);
134  };
137  void setTransformation(EGS_AffineTransform *t) {
138  if (T) {
139  delete T;
140  T = 0;
141  }
142  if (t) {
143  T = new EGS_AffineTransform(*t);
144  }
145  };
146  const EGS_AffineTransform *getTransform() const {
147  return T;
148  };
150  EGS_Object::deleteObject(source);
151  if (T) {
152  delete T;
153  }
154  };
155 
156  EGS_I64 getNextParticle(EGS_RandomGenerator *rndm,
157  int &q, int &latch, EGS_Float &E, EGS_Float &wt,
158  EGS_Vector &x, EGS_Vector &u) {
159  EGS_I64 c = source->getNextParticle(rndm,q,latch,E,wt,x,u);
160  if (T) {
161  T->rotate(u);
162  T->transform(x);
163  }
164  return c;
165  };
166  EGS_Float getEmax() const {
167  return source->getEmax();
168  };
169  EGS_Float getFluence() const {
170  return source->getFluence();
171  };
172  bool storeState(ostream &data) const {
173  return source->storeState(data);
174  };
175  bool setState(istream &data) {
176  return source->setState(data);
177  };
178  bool addState(istream &data_in) {
179  return source->addState(data_in);
180  };
181  void resetCounter() {
182  source->resetCounter();
183  };
184 
185  bool isValid() const {
186  return (source != 0);
187  };
188 
189  void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun) {
190  source->setSimulationChunk(nstart, nrun);
191  };
192 
193 protected:
194 
195  EGS_BaseSource *source;
197 
198  void setUp(EGS_AffineTransform *t);
199 
200 };
201 
202 #endif
virtual void setSimulationChunk(EGS_I64 nstart, EGS_I64 nrun)
Set the next simulation chunk to start at nstart and to consist of nrun particles.
EGS_BaseSource class header file.
EGS_TransformedSource(EGS_BaseSource *Source, EGS_AffineTransform *t, const string &Name="", EGS_ObjectFactory *f=0)
Construct a transformed source using Source as the source and t as the transformation.
A class providing affine transformations.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
A class representing 3D vectors.
Definition: egs_vector.h:56
virtual bool addState(istream &data_in)
Add data from the stream data_in to the source state.
static void deleteObject(EGS_Object *o)
Delete an object.
virtual void resetCounter()
Reset the source state.
virtual bool storeState(ostream &data_out) const
Store the source state into the stream data_out.
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.
virtual bool setState(istream &data_in)
Set the source state based on data from the stream data_in.
A transformed source.
EGS_BaseShape and shape classes header file.
An object factory.
virtual EGS_Float getFluence() const =0
Return the fluence this source has emitted so far.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
virtual EGS_I64 getNextParticle(EGS_RandomGenerator *rndm, int &q, int &latch, EGS_Float &E, EGS_Float &wt, EGS_Vector &x, EGS_Vector &u)=0
Sample the next source particle from the source probability distribution.
EGS_AffineTransform * T
The affine transformation.
virtual EGS_Float getEmax() const =0
Return the maximum energy of this source.
Base source class. All particle sources must be derived from this class.