EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_extended_shape.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ extended 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_extended_shape.h"
38 #include "egs_input.h"
39 #include "egs_functions.h"
40 
41 static bool EGS_EXTENDED_SHAPE_LOCAL inputSet = false;
42 static shared_ptr<EGS_BlockInput> EGS_EXTENDED_SHAPE_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>("shape");
43 
44 extern "C" {
45 
46  static void setInputs() {
47  inputSet = true;
48  shapeBlockInput->addSingleInput("library", true, "The type of shape, loaded by shared library in egs++/dso.", {"egs_extended_shape"});
49  shapeBlockInput->addSingleInput("extension", true, "Adds delta z to the z-component of the position vector (z1, z2)");
50 
51  auto shapePtr = shapeBlockInput->addBlockInput("shape");
52  setShapeInputs(shapePtr);
53  }
54 
55  EGS_EXTENDED_SHAPE_EXPORT string getExample() {
56  string example;
57  example = {
58  R"(
59  # Example of egs_extended_shape
60  #:start shape:
61  library = egs_extended_shape
62  :start shape:
63  definition of the shape to be 'extended'
64  :stop shape:
65  extension = z1 z2
66 )"};
67  return example;
68  }
69 
70  EGS_EXTENDED_SHAPE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
71  if(!inputSet) {
72  setInputs();
73  }
74  return shapeBlockInput;
75  }
76 
77  EGS_EXTENDED_SHAPE_EXPORT EGS_BaseShape *createShape(EGS_Input *input,
78  EGS_ObjectFactory *f) {
79  if (!input) {
80  egsWarning("createShape(extended shape): null input?\n");
81  return 0;
82  }
83  vector<EGS_Float> h;
84  int err = input->getInput("extension",h);
85  if (err || h.size() != 2) {
86  egsWarning("createShape(extended shape): wrong/missing "
87  "'extension' input\n");
88  return 0;
89  }
90  EGS_Input *ishape = input->takeInputItem("shape",false);
91  EGS_BaseShape *shape=0;;
92  if (ishape) {
93  shape = EGS_BaseShape::createShape(ishape);
94  delete ishape;
95  }
96  if (!shape) {
97  string shape_name;
98  int err = input->getInput("shape name",shape_name);
99  if (err) {
100  egsWarning("createShape(extended shape): no inline shape definition"
101  " and no 'shape name' keyword\n");
102  return 0;
103  }
104  shape = EGS_BaseShape::getShape(shape_name);
105  if (!shape) {
106  egsWarning("createShape(extended shape): no shape named %s "
107  "exists\n",shape_name.c_str());
108  return 0;
109  }
110  }
111  EGS_ExtendedShape *s = new EGS_ExtendedShape(shape,h[0],h[1],"",f);
112  s->setName(input);
113  s->setTransformation(input);
114  return s;
115  }
116 
117 }
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
An extended 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.
An extended shape.
Global egspp functions header file.
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.