EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_box.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ box 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 #
30 ###############################################################################
31 */
32 
33 
39 #include "egs_box.h"
40 #include "egs_input.h"
41 #include "egs_base_geometry.h"
42 
43 void EGS_Box::printInfo() const {
45  egsInformation(" box size = %g %g %g\n",ax,ay,az);
46  egsInformation("=======================================================\n");
47 }
48 
49 static string EGS_BOX_LOCAL typeStr("egs_box");
50 string EGS_Box::type(typeStr);
51 
52 static char EGS_BOX_LOCAL ebox_message1[] = "createGeometry(box): %s\n";
53 static char EGS_BOX_LOCAL ebox_message2[] = "null input?";
54 static char EGS_BOX_LOCAL ebox_message3[] = "wrong/missing 'box size' input?";
55 static char EGS_BOX_LOCAL ebox_message4[] =
56  "expecting 1 or 3 float inputs for 'box size'";
57 static char EGS_BOX_LOCAL ebox_key1[] = "box size";
58 
59 static bool EGS_BOX_LOCAL inputSet = false;
60 
61 struct EGS_BOX_LOCAL InputOptions {
62  vector<EGS_Float> boxSize;
63 };
64 InputOptions inp;
65 
66 // Process inputs from the egsinp file
67 EGS_BOX_LOCAL int processInputs(EGS_Input *input) {
68  int err = input->getInput(ebox_key1,inp.boxSize);
69  if (err && geomBlockInput->getSingleInput(ebox_key1)->getRequired()) {
70  egsWarning(ebox_message1,ebox_message3);
71  return 0;
72  }
73 
74  return 1;
75 }
76 
77 extern "C" {
78 
79  static void setInputs() {
80  inputSet = true;
81 
82  setBaseGeometryInputs();
83 
84  geomBlockInput->getSingleInput("library")->setValues(vector<string>(1, typeStr));
85 
86  // Format: name, isRequired, description, vector string of allowed values
87  geomBlockInput->addSingleInput("box size", true, "1 number defining the side-length of a cube, or 3 numbers defining the x, y, and z side-lengths.");
88  }
89 
90  EGS_BOX_EXPORT string getExample() {
91  string example {
92  R"(
93  :start geometry:
94  library = EGS_Box
95  name = my_box
96  box size = 1 2 3
97  :start media input:
98  media = water
99  :stop media input:
100  :stop geometry:
101 )"};
102  return example;
103  }
104 
105  EGS_BOX_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
106  if(!inputSet) {
107  setInputs();
108  }
109  return geomBlockInput;
110  }
111 
112  EGS_BOX_EXPORT EGS_BaseGeometry *createGeometry(EGS_Input *input) {
113  if (!input) {
114  egsWarning(ebox_message1,ebox_message2);
115  return 0;
116  }
117 
118  if(!processInputs(input)) {
119  egsWarning("Failed to process the inputs for %s.\n", typeStr.c_str());
120  return 0;
121  }
122 
123  vector<EGS_Float> s;
124  s = inp.boxSize;
125 
127  EGS_Box *result;
128  if (s.size() == 1) {
129  result = new EGS_Box(s[0],t);
130  }
131  else if (s.size() == 3) {
132  result = new EGS_Box(s[0],s[1],s[2],t);
133  }
134  else {
135  egsWarning(ebox_message1,ebox_message4);
136  if (t) {
137  delete t;
138  }
139  return 0;
140  }
141  if (t) {
142  delete t;
143  }
144  result->setName(input);
145  result->setBoundaryTolerance(input);
146  result->setMedia(input);
147  result->setLabels(input);
148  return result;
149  }
150 }
A class providing affine transformations.
static EGS_AffineTransform * getTransformation(EGS_Input *inp)
Constructs an affine transformation object from the input pointed to by inp and returns a pointer to ...
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.
virtual void printInfo() const
Print information about this geometry.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
A box geometry.
Definition: egs_box.h:104
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
EGS_BaseGeometry class header file.
A box geometry: header.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
Definition: egs_glib.cpp:84
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.