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 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_cylinders.h"
38 #include "egs_input.h"
39 
40 extern "C" {
41 
42  EGS_CYLINDERS_EXPORT EGS_BaseGeometry *createGeometry(EGS_Input *input) {
43  // check for valid input
44  if (!input) {
45  egsWarning("createGeometry(cylinders): null input?\n");
46  return 0;
47  }
48  string type;
49  int err = input->getInput("type",type);
50  if (err) {
51  egsWarning("createGeometry(cylinders): missing type key\n");
52  return 0;
53  }
54 
55  // point on cylinder axis
56  EGS_Vector xo;
57  vector<EGS_Float> Xo;
58  err = input->getInput("midpoint",Xo);
59  if (!err && Xo.size() == 3) {
60  xo = EGS_Vector(Xo[0],Xo[1],Xo[2]);
61  }
62 
63  // cylinder radii
64  vector<EGS_Float> radii;
65  err = input->getInput("radii",radii);
66  if (err) {
67  egsWarning("createGeometry(cylinders): wrong/missing 'radii' input\n");
68  return 0;
69  }
70  EGS_Float *r=new EGS_Float [radii.size()];
71  for (int i=0; i<radii.size(); i++) {
72  r[i]=radii[i];
73  }
74 
75  // select geometry
77  if (type == "EGS_XCylinders") {
78  g = new EGS_CylindersX(radii.size(),r,xo,"",EGS_XProjector("EGS_XCylinders"));
79  }
80  else if (type == "EGS_YCylinders") {
81  g = new EGS_CylindersY(radii.size(),r,xo,"",EGS_YProjector("EGS_YCylinders"));
82  }
83  else if (type == "EGS_ZCylinders") {
84  g = new EGS_CylindersZ(radii.size(),r,xo,"",EGS_ZProjector("EGS_ZCylinders"));
85  }
86  else {
87  vector<EGS_Float> a;
88  err = input->getInput("axis",a);
89  if (err || a.size() != 3) {
90  egsWarning("createGeometry(cylinders): missing/wrong axis input\n");
91  return 0;
92  }
93  egsWarning("got axis (%g,%g,%g)\n",a[0],a[1],a[2]);
94  g = new EGS_Cylinders(radii.size(),r,xo,"",
95  EGS_Projector(EGS_Vector(a[0],a[1],a[2]),""));
96  }
97  g->setName(input);
98  g->setBoundaryTolerance(input);
99  g->setMedia(input);
100  g->setLabels(input);
101  return g;
102  }
103 
104 }
EGS_Input class header file.
A class representing 3D vectors.
Definition: egs_vector.h:56
int setLabels(EGS_Input *input)
Set the labels from an input block.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
Definition: egs_glib.cpp:57
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
A projector into any plane.
A set of concentric cylinders.
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
A projector into the z-plane.
A projector into the y-plane.
A projector into the x-plane.
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:338
A set of concentric cylinders: header.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.