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: Hannah Gallop
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_gaussian_shape.h"
38 #include "egs_input.h"
39 #include "egs_functions.h"
40 
41 static bool EGS_GAUSSIAN_SHAPE_LOCAL inputSet = false;
42 static shared_ptr<EGS_BlockInput> EGS_GAUSSIAN_SHAPE_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>("shape");
43 
44 extern "C" {
45 
46  static void setInputs() {
47  inputSet = true;
48 
49  shapeBlockInput->addSingleInput("library", true, "The type of shape, loaded by shared library in egs++/dso.", {"egs_gaussian_shape"});
50  shapeBlockInput->addSingleInput("sigma", true, "1 or 2 or 3 inputs, the sigma for Gaussian spread along x, y and z, respectively.");
51 
52  auto shapePtr = shapeBlockInput->addBlockInput("shape");
53  setShapeInputs(shapePtr);
54  }
55 
56  EGS_GAUSSIAN_SHAPE_EXPORT string getExample() {
57  string example;
58  example = {
59  R"(
60  # Example of egs_gaussian_shape
61  #:start shape:
62  library = egs_gaussian_shape
63  :start shape:
64  definition of the shape to be smeared
65  :stop shape:
66  sigma = 1, 2 or 3 inputs
67  :stop shape:
68 )"};
69  return example;
70  }
71 
72  EGS_GAUSSIAN_SHAPE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
73  if(!inputSet) {
74  setInputs();
75  }
76  return shapeBlockInput;
77  }
78 
79  EGS_GAUSSIAN_SHAPE_EXPORT EGS_BaseShape *createShape(EGS_Input *input,
80  EGS_ObjectFactory *f) {
81  if (!input) {
82  egsWarning("createShape(circle): null input?\n");
83  return 0;
84  }
85  vector<EGS_Float> sigma;
86  int err = input->getInput("sigma",sigma);
87  if (err) {
88  egsWarning("createShape(gaussian shape): no 'sigma' input\n");
89  return 0;
90  }
91  EGS_Input *ishape = input->takeInputItem("shape",false);
92  EGS_BaseShape *shape = 0;
93  if (ishape) {
94  shape = EGS_BaseShape::createShape(ishape);
95  delete ishape;
96  }
97  if (!shape) {
98  string shape_name;
99  int err = input->getInput("shape name",shape_name);
100  if (err) {
101  egsWarning("createShape(gaussian shape): no inline shape definition"
102  " and no 'shape name' keyword\n");
103  return 0;
104  }
105  shape = EGS_BaseShape::getShape(shape_name);
106  if (!shape) {
107  egsWarning("createShape(gaussian shape): no shape named %s "
108  "exists\n",shape_name.c_str());
109  return 0;
110  }
111  }
113  if (sigma.size() == 1) {
114  s = new EGS_GaussianShape(shape,sigma[0],0,0,"",f);
115  }
116  else if (sigma.size() == 2) {
117  s = new EGS_GaussianShape(shape,sigma[0],sigma[1],0,"",f);
118  }
119  else {
120  s = new EGS_GaussianShape(shape,sigma[0],sigma[1],sigma[2],"",f);
121  }
122  s->setName(input);
123  s->setTransformation(input);
124  return s;
125  }
126 
127 }
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition: egs_shapes.h:145
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
Definition: egs_shapes.cpp:64
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
Definition: egs_shapes.cpp:51
void setTransformation(EGS_Input *inp)
Set the transformation attached to this shape.
Definition: egs_shapes.cpp:69
A Gaussian shape.
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:229
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:341
An object factory.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
Global egspp functions header file.
A shape smeared by a Gaussian.
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.