EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_ellipse.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ ellipse 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_ellipse.h"
38 #include "egs_input.h"
39 #include "egs_functions.h"
40 
41 static bool EGS_ELLIPSE_LOCAL inputSet = false;
42 static shared_ptr<EGS_BlockInput> EGS_ELLIPSE_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>("shape");
43 
44 extern "C" {
45 
46  static void setInputs() {
47  inputSet = true;
48 
49  setShapeInputs(shapeBlockInput);
50  shapeBlockInput->getSingleInput("library")->setValues({"egs_ellipse"});
51 
52  shapeBlockInput->addSingleInput("halfaxis", true, "The two half axis of the ellipse.");
53  shapeBlockInput->addSingleInput("midpoint", false, "The midpoint of the ellipse, (x, y). Defaults to '0 0'.");
54  }
55 
56  EGS_ELLIPSE_EXPORT string getExample() {
57  string example;
58  example = {
59  R"(
60  # Example fo egs_ellipse
61  #:start shape:
62  library = egs_ellipse
63  halfway = the two half axis of the ellipse
64  midpoint = Ox, Oy (optional)
65  :stop shape:
66 )"};
67  return example;
68  }
69 
70  EGS_ELLIPSE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
71  if(!inputSet) {
72  setInputs();
73  }
74  return shapeBlockInput;
75  }
76 
77  EGS_ELLIPSE_EXPORT EGS_BaseShape *createShape(EGS_Input *input,
78  EGS_ObjectFactory *f) {
79  if (!input) {
80  egsWarning("createShape(ellipse): null input?\n");
81  return 0;
82  }
83  vector<EGS_Float> axis;
84  int err = input->getInput("halfaxis",axis);
85  if (err) {
86  egsWarning("createShape(ellipse): no 'halfaxis' input\n");
87  return 0;
88  }
89  if (axis.size() != 2) {
90  egsWarning("createShape(ellipse): 2 instead of %d inputs expected"
91  " for keyword 'halfaxis'.\n",axis.size());
92  return 0;
93  }
94  vector<EGS_Float> pos;
95  err = input->getInput("midpoint",pos);
96  if (err) {
97  pos.clear();
98  pos.push_back(0);
99  pos.push_back(0);
100  }
101  else {
102  if (pos.size() != 2) {
103  egsWarning("createShape(ellipse): 2 instead of %d inputs expected"
104  " for keyword 'midpoint'. Reseting midpoint to (0,0)\n",
105  pos.size());
106  pos.clear();
107  pos.push_back(0);
108  pos.push_back(0);
109  }
110  }
111  EGS_EllipseShape *shape = new EGS_EllipseShape(pos[0],pos[1],
112  axis[0],axis[1],"",f);
113  shape->setName(input);
114  shape->setTransformation(input);
115  return shape;
116  }
117 
118 }
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition: egs_shapes.h:145
void setTransformation(EGS_Input *inp)
Set the transformation attached to this shape.
Definition: egs_shapes.cpp:69
An elliptical shape.
Definition: egs_ellipse.h:86
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
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 elliptical shape.
Global egspp functions header file.
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.