EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_gaussian_shape.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ guassian shape
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 #include "egs_gaussian_shape.h"
38 #include "egs_input.h"
39 #include "egs_functions.h"
40 
41 extern "C" {
42 
43  EGS_GAUSSIAN_SHAPE_EXPORT EGS_BaseShape *createShape(EGS_Input *input,
44  EGS_ObjectFactory *f) {
45  if (!input) {
46  egsWarning("createShape(circle): null input?\n");
47  return 0;
48  }
49  vector<EGS_Float> sigma;
50  int err = input->getInput("sigma",sigma);
51  if (err) {
52  egsWarning("createShape(gaussian shape): no 'sigma' input\n");
53  return 0;
54  }
55  EGS_Input *ishape = input->takeInputItem("shape",false);
56  EGS_BaseShape *shape = 0;
57  if (ishape) {
58  shape = EGS_BaseShape::createShape(ishape);
59  delete ishape;
60  }
61  if (!shape) {
62  string shape_name;
63  int err = input->getInput("shape name",shape_name);
64  if (err) {
65  egsWarning("createShape(gaussian shape): no inline shape definition"
66  " and no 'shape name' keyword\n");
67  return 0;
68  }
69  shape = EGS_BaseShape::getShape(shape_name);
70  if (!shape) {
71  egsWarning("createShape(gaussian shape): no shape named %s "
72  "exists\n",shape_name.c_str());
73  return 0;
74  }
75  }
77  if (sigma.size() == 1) {
78  s = new EGS_GaussianShape(shape,sigma[0],0,0,"",f);
79  }
80  else if (sigma.size() == 2) {
81  s = new EGS_GaussianShape(shape,sigma[0],sigma[1],0,"",f);
82  }
83  else {
84  s = new EGS_GaussianShape(shape,sigma[0],sigma[1],sigma[2],"",f);
85  }
86  s->setName(input);
87  s->setTransformation(input);
88  return s;
89  }
90 
91 }
void setTransformation(EGS_Input *inp)
Set the transformation attached to this shape.
Definition: egs_shapes.cpp:68
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
Definition: egs_shapes.cpp:51
EGS_Input class header file.
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
Definition: egs_shapes.cpp:63
A shape smeared by a Gaussian.
Global egspp functions header file.
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition: egs_shapes.h:112
A Gaussian shape.
An object factory.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_Input * takeInputItem(const string &key, bool self=true)
Get the property named key.
Definition: egs_input.cpp:226
int getInput(const string &key, vector< string > &values) const
Assign values to an array of strings from an input identified by key.
Definition: egs_input.cpp:338
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.