EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_gtransformed.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ gtransformed 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 # Ernesto Mainegra-Hing
28 # Hubert Ho
29 # Marc Chamberland
30 # Hannah Gallop
31 #
32 ###############################################################################
33 */
34 
35 
42 #include "egs_gtransformed.h"
43 #include "egs_input.h"
44 #include "egs_functions.h"
45 
46 static bool EGS_GTRANSFORMED_LOCAL inputSet = false;
47 
49  egsWarning("EGS_TransformedGeometry::setMedia: don't use this method. Use the\n"
50  " setMedia() methods of the geometry objects that make up this geometry\n");
51 }
52 
53 void EGS_TransformedGeometry::setRelativeRho(int start, int end, EGS_Float rho) {
54  setRelativeRho(0);
55 }
56 
57 void EGS_TransformedGeometry::setRelativeRho(EGS_Input *) {
58  egsWarning("EGS_TransformedGeometry::setRelativeRho(): don't use this "
59  "method. Use the \n setRelativeRho() methods of the underlying "
60  "geometry\n");
61 }
62 
63 void EGS_TransformedGeometry::setBScaling(int start, int end, EGS_Float rho) {
64  setBScaling(0);
65 }
66 
67 void EGS_TransformedGeometry::setBScaling(EGS_Input *) {
68  egsWarning("EGS_TransformedGeometry::setBScaling(): don't use this "
69  "method. Use the \n setBScaling() methods of the underlying "
70  "geometry\n");
71 }
72 
73 extern "C" {
74 
75  static void setInputs() {
76  inputSet = true;
77 
78  setBaseGeometryInputs(false);
79 
80  geomBlockInput->getSingleInput("library")->setValues({"egs_gtransformed"});
81 
82  // Format: name, isRequired, description, vector string of allowed values
83  geomBlockInput->addSingleInput("my geometry", true, "The name of a previously defined geometry");
84 
85  addTransformationBlock(geomBlockInput);
86  }
87 
88  EGS_GTRANSFORMED_EXPORT string getExample() {
89  string example;
90  example = {
91  R"(
92  # Example of egs_gtransformed
93  #:start geometry:
94  name = my_gtransform
95  library = egs_gtransformed
96  my geometry = geom
97  # geometry geom must be defined before this one
98  :start transformation:
99  translation = 0 0.5 0
100  rotation = 0.05 0 -1
101  :stop transformation:
102  :stop geometry:
103 )"};
104  return example;
105  }
106 
107  EGS_GTRANSFORMED_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
108  if(!inputSet) {
109  setInputs();
110  }
111  return geomBlockInput;
112  }
113 
114  EGS_GTRANSFORMED_EXPORT EGS_BaseGeometry *createGeometry(EGS_Input *input) {
115  EGS_BaseGeometry *g = 0;
116  EGS_Input *ij = input->takeInputItem("geometry",false);
117  if (ij) {
119  delete ij;
120  if (!g) {
121  egsWarning("createGeometry(gtransformed): got a null pointer"
122  " as a geometry?\n");
123  return 0;
124  }
125  }
126  if (!g) {
127  string gname;
128  int err = input->getInput("my geometry",gname);
129  if (err) {
130  egsWarning(
131  "createGeometry(gtransformed): my geometry must be defined\n"
132  " either inline or using 'my geometry = some_name'\n");
133  return 0;
134  }
136  if (!g) {
137  egsWarning("createGeometry(gtransformed): no geometry named %s"
138  " is defined\n",gname.c_str());
139  return 0;
140  }
141  }
142  g->ref();
144  EGS_BaseGeometry *result;
145  if (!t) {
146  egsWarning("createGeometry(gtransformed): null transformation."
147  " I hope you know what you are doing\n");
149  }
150  else {
151  if (t->isI()) egsWarning("createGeometry(gtransformed): "
152  "unity transformation. I hope you know what you are doing\n");
153  result = new EGS_TransformedGeometry(g,*t);
154  delete t;
155  }
156  result->setName(input);
157  result->setBoundaryTolerance(input);
158  result->setLabels(input);
159  return result;
160 
161  }
162 
163  int EGS_TransformedGeometry::getGlobalRegionOffset(const string geomName) {
164  return g->getGlobalRegionOffset(geomName);
165  }
166 
167  void EGS_TransformedGeometry::getLabelRegions(const string &str, vector<int> &regs, bool sanitize) {
168 
169  // label defined in the geometry being transformed
170  g->getLabelRegions(str, regs, sanitize);
171 
172  // label defined in self (transformation input block)
173  EGS_BaseGeometry::getLabelRegions(str, regs, sanitize);
174 
175  }
176 
177 
178 }
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 ...
bool isI() const
Returns true if the object is a unity transformation, false otherwise.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual int getGlobalRegionOffset(const string geomName)
Get the global region number for the first region in the geometry.
static EGS_BaseGeometry * createSingleGeometry(EGS_Input *inp)
Create a single geometry from the input 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.
int ref()
Increase the reference count to this geometry.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
virtual void getLabelRegions(const string &str, vector< int > &regs, bool sanitize=true)
Get the list of all regions labeled with str.
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition: egs_input.h:182
EGS_Input * takeInputItem(const string &key, bool self=true)
Get the property named key.
Definition: egs_input.cpp:229
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 transformed geometry.
void setMedia(EGS_Input *inp, int, const int *)
Don't define media in the transformed geometry definition.
EGS_BaseGeometry * g
The geometry being transformed.
Global egspp functions header file.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
Definition: egs_glib.cpp:84
A transformed geometry: header.
EGS_Input class header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.