EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_cylinders.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ cylinder geometry
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: Frederic Tessier
27 # Marc Chamberland
28 # Reid Townson
29 # Hannah Gallop
30 #
31 ###############################################################################
32 */
33 
34 
40 #include "egs_cylinders.h"
41 #include "egs_input.h"
42 
43 static bool EGS_CYLINDERS_LOCAL inputSet = false;
44 
45 extern "C" {
46 
47  static void setInputs() {
48  inputSet = true;
49 
50  setBaseGeometryInputs();
51 
52  geomBlockInput->getSingleInput("library")->setValues({"egs_cylinders"});
53 
54  // Format: name, isRequired, description, vector string of allowd values
55  auto typePtr = geomBlockInput->addSingleInput("type", true, "The type of cylinder.", {"EGS_XCylinders", "EGS_YCylinders", "EGS_ZCylinders", "EGS_Cylinders"});
56 
57  geomBlockInput->addSingleInput("radii", true, "A list of cylinder radii, must be in increasing order");
58  geomBlockInput->addSingleInput("midpoint", false, "The position of the midpoint of the cylinder (x, y, z)");
59 
60  // EGS_Cylinders
61  auto inpPtr = geomBlockInput->addSingleInput("axis", true, "The unit vector defining the axis along the length of the cylinder.");
62  inpPtr->addDependency(typePtr, "EGS_Cylinders");
63  }
64 
65  EGS_CYLINDERS_EXPORT string getExample() {
66  string example;
67  example = {
68  R"(
69  # Examples of the egs_cylinders to follow
70 
71  # EGS_XCylinder example
72  #:start geometry:
73  library = egs_cylinders
74  type = EGS_XCylinders
75  name = my_xcylinders
76  radii = 1 2 3
77  midpoint = 0
78  :start media input:
79  media = water air water
80  set medium = 1 1
81  set medium = 2 2
82  :stop media input:
83  :stop geometry:
84 
85  # EGS_Cylinder example
86  #:start geometry:
87  library = egs_cylinders
88  type = EGS_Cylinders
89  name = my_cylinder
90  radii = 7
91  axis = 4 3 2
92  midpoint = 0 0 0
93  :start media input:
94  media = water
95  :stop media input:
96  :stop geometry:
97 )"};
98  return example;
99  }
100 
101  EGS_CYLINDERS_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
102  if(!inputSet) {
103  setInputs();
104  }
105  return geomBlockInput;
106  }
107 
108  EGS_CYLINDERS_EXPORT EGS_BaseGeometry *createGeometry(EGS_Input *input) {
109  // check for valid input
110  if (!input) {
111  egsWarning("createGeometry(cylinders): null input?\n");
112  return 0;
113  }
114  string type;
115  int err = input->getInput("type",type);
116  if (err) {
117  egsWarning("createGeometry(cylinders): missing type key\n");
118  return 0;
119  }
120 
121  // point on cylinder axis
122  EGS_Vector xo;
123  vector<EGS_Float> Xo;
124  err = input->getInput("midpoint",Xo);
125  if (!err && Xo.size() == 3) {
126  xo = EGS_Vector(Xo[0],Xo[1],Xo[2]);
127  }
128 
129  // cylinder radii
130  vector<EGS_Float> radii;
131  err = input->getInput("radii",radii);
132  if (err) {
133  egsWarning("createGeometry(cylinders): wrong/missing 'radii' input\n");
134  return 0;
135  }
136  EGS_Float *r=new EGS_Float [radii.size()];
137  for (int i=0; i<radii.size(); i++) {
138  r[i]=radii[i];
139  }
140 
141  // select geometry
142  EGS_BaseGeometry *g;
143  if (type == "EGS_XCylinders") {
144  g = new EGS_CylindersX(radii.size(),r,xo,"",EGS_XProjector("EGS_XCylinders"));
145  }
146  else if (type == "EGS_YCylinders") {
147  g = new EGS_CylindersY(radii.size(),r,xo,"",EGS_YProjector("EGS_YCylinders"));
148  }
149  else if (type == "EGS_ZCylinders") {
150  g = new EGS_CylindersZ(radii.size(),r,xo,"",EGS_ZProjector("EGS_ZCylinders"));
151  }
152  else {
153  vector<EGS_Float> a;
154  err = input->getInput("axis",a);
155  if (err || a.size() != 3) {
156  egsWarning("createGeometry(cylinders): missing/wrong axis input\n");
157  return 0;
158  }
159  egsWarning("got axis (%g,%g,%g)\n",a[0],a[1],a[2]);
160  g = new EGS_Cylinders(radii.size(),r,xo,"",
161  EGS_Projector(EGS_Vector(a[0],a[1],a[2]),""));
162  }
163  g->setName(input);
164  g->setBoundaryTolerance(input);
165  g->setMedia(input);
166  g->setLabels(input);
167  return g;
168  }
169 
170 }
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
int setLabels(EGS_Input *input)
Set the labels from an input block.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
A set of concentric cylinders.
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
A projector into any plane.
A class representing 3D vectors.
Definition: egs_vector.h:57
A projector into the x-plane.
A projector into the y-plane.
A projector into the z-plane.
A set of concentric cylinders: header.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
Definition: egs_glib.cpp:84
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.