EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_transformations.cpp
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ transformations
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:
27 #
28 ###############################################################################
29 */
30 
31 
37 #include "egs_transformations.h"
38 #include "egs_input.h"
39 
40 #include <vector>
41 using std::vector;
42 
44  if (!i) {
45  return 0;
46  }
47  EGS_Input *input;
48  bool delete_it = false;
49  if (i->isA("transformation")) {
50  input = i;
51  }
52  else {
53  input = i->takeInputItem("transformation");
54  if (!input) {
55  return 0;
56  }
57  delete_it = true;
58  }
59  EGS_Vector t;
60  vector<EGS_Float> tmp;
61  int err = input->getInput("translation",tmp);
62  if (!err && tmp.size() == 3) {
63  t = EGS_Vector(tmp[0],tmp[1],tmp[2]);
64  }
65  EGS_AffineTransform *result;
66  err = input->getInput("rotation vector",tmp);
67  if (!err && tmp.size() == 3)
68  result = new EGS_AffineTransform(
69  EGS_RotationMatrix(EGS_Vector(tmp[0],tmp[1],tmp[2])),t);
70  else {
71  err = input->getInput("rotation",tmp);
72  if (!err) {
73  if (tmp.size() == 2) result = new EGS_AffineTransform(
74  EGS_RotationMatrix(tmp[0],tmp[1]),t);
75  else if (tmp.size() == 3) result = new EGS_AffineTransform(
76  EGS_RotationMatrix(tmp[0],tmp[1],tmp[2]),t);
77  else if (tmp.size() == 4) {
78  EGS_Vector tmp1(tmp[0],tmp[1],tmp[2]);
79  EGS_RotationMatrix R1(tmp1);
81  EGS_RotationMatrix Rtot = R1.inverse()*R2*R1;
82  result = new EGS_AffineTransform(Rtot,t);
83  }
84  else if (tmp.size() == 9) {
85  EGS_RotationMatrix R(tmp[0],tmp[1],tmp[2],
86  tmp[3],tmp[4],tmp[5],
87  tmp[6],tmp[7],tmp[8]);
88  if (!R.isRotation())
89  egsWarning("getTransformation: the rotation specified by\n"
90  " %g %g %g\n %g %g %g\n %g %g %g\n"
91  " is not a rotation\n",tmp[0],tmp[1],tmp[2],
92  tmp[3],tmp[4],tmp[5],tmp[6],tmp[7],tmp[8]);
93  result = new EGS_AffineTransform(R,t);
94  }
95  else {
96  result = new EGS_AffineTransform(EGS_RotationMatrix(),t);
97  }
98  }
99  else {
100  result = new EGS_AffineTransform(EGS_RotationMatrix(),t);
101  }
102  }
103  if (delete_it) {
104  delete input;
105  }
106  return result;
107 }
bool isA(const string &key) const
Definition: egs_input.cpp:278
A class providing affine transformations.
A class for vector rotations.
EGS_Input class header file.
A class representing 3D vectors.
Definition: egs_vector.h:56
EGS_AffineTransform()
Constructs a unit affine transformation.
static EGS_RotationMatrix rotZ(EGS_Float cphi, EGS_Float sphi)
Returns a rotation around the z-axis by the angle with cphi, sphi = .
EGS_RotationMatrix inverse() const
Returns the inverse matrix.
bool isRotation() const
Is this object a real rotation matrix?
EGS_AffineTransform and EGS_RotationMatrix class header file.
static EGS_AffineTransform * getTransformation(EGS_Input *inp)
Constructs an affine transformation object from the input pointed to by inp and returns a pointer to ...
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:226
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
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.