EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_circle.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ circle 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: Reid Townson
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_circle.h"
38 #include "egs_input.h"
39 #include "egs_functions.h"
40 
41 static string EGS_CIRCLE_LOCAL typeStr("egs_circle");
42 static bool EGS_CIRCLE_LOCAL inputSet = false;
43 static shared_ptr<EGS_BlockInput> EGS_CIRCLE_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>("shape");
44 
45 extern "C" {
46 
47  static void setInputs() {
48  inputSet = true;
49 
50  setShapeInputs(shapeBlockInput);
51  shapeBlockInput->getSingleInput("library")->setValues({typeStr});
52 
53  shapeBlockInput->addSingleInput("radius", false, "The radius of the circle.");
54  shapeBlockInput->addSingleInput("midpoint", false, "The x, y midpoint of the circle, which is in the x-y plane located at z=0. Use an EGS_AffineTransform block to translate or rotate the shape.");
55  shapeBlockInput->addSingleInput("inner radius", false, "The inner radius, to define a ring. Points will only be sampled within the ring between the 'inner radius' and 'radius'.");
56  }
57 
58  EGS_CIRCLE_EXPORT string getExample() {
59  string example {
60  R"(
61  :start shape:
62  library = egs_circle
63  radius = the circle radius
64  midpoint = Ox, Oy (optional)
65  inner radius = the inner radius (optional)
66  :stop shape:
67 )"};
68  return example;
69  }
70 
71  EGS_CIRCLE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
72  if(!inputSet) {
73  setInputs();
74  }
75  return shapeBlockInput;
76  }
77 
78  EGS_CIRCLE_EXPORT EGS_BaseShape *createShape(EGS_Input *input,
79  EGS_ObjectFactory *f) {
80  if (!input) {
81  egsWarning("createShape(circle): null input?\n");
82  return 0;
83  }
84  EGS_Float radius;
85  int err = input->getInput("radius",radius);
86  if (err) {
87  egsWarning("createShape(circle): no 'radius' input\n");
88  return 0;
89  }
90  EGS_Float Ro;
91  err = input->getInput("inner radius",Ro);
92  if (err) {
93  Ro = 0;
94  }
95  vector<EGS_Float> pos;
96  err = input->getInput("midpoint",pos);
97  if (err) {
98  pos.clear();
99  pos.push_back(0);
100  pos.push_back(0);
101  }
102  else {
103  if (pos.size() != 2) {
104  egsWarning("createShape(circle): 2 instead of %d inputs expected"
105  " for keyword 'midpoint'. Reseting midpoint to (0,0)\n",
106  pos.size());
107  pos.clear();
108  pos.push_back(0);
109  pos.push_back(0);
110  }
111  }
112  EGS_CircleShape *shape = new EGS_CircleShape(pos[0],pos[1],radius,Ro,"",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
A circle shape.
Definition: egs_circle.h:87
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.
A circular shape.
Global egspp functions header file.
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.