Xmipp  v3.23.11-Nereus
euler.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Roberto Marabini (roberto@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 /* Follows graphics gems iv and IMATHEULER ideas */
26 #ifndef _EULER_HH
27 #define _EULER_HH
28 
29 #include <stdio.h>
30 #include <math.h>
31 #include <stdlib.h>
32 #include <core/matrix1d.h>
33 #include <core/matrix2d.h>
35 
39 class Euler
40 {
41 public:
42 
43  typedef enum
44  {
45  //
46  // All 24 possible orderings
47  //
48 
49  XYZ = 0x0101, // "usual" orderings
50  XZY = 0x0001,
51  YZX = 0x1101,
52  YXZ = 0x1001,
53  ZXY = 0x2101,
54  ZYX = 0x2001,
55 
56  XZX = 0x0011, // first axis repeated
57  XYX = 0x0111,
58  YXY = 0x1011,
59  YZY = 0x1111,
60  ZYZ = 0x2011,
61  ZXZ = 0x2111,
62 
63  XYZr = 0x2000, // relative orderings -- not common
64  XZYr = 0x2100,
65  YZXr = 0x1000,
66  YXZr = 0x1100,
67  ZXYr = 0x0000,
68  ZYXr = 0x0100,
69 
70  XZXr = 0x2110, // relative first axis repeated
71  XYXr = 0x2010,
72  YXYr = 0x1110,
73  YZYr = 0x1010,
74  ZYZr = 0x0110,
75  ZXZr = 0x0010,
76  // ||||
77  // VVVV
78  //Legend:ABCD
79  // A -> Initial Axis (0==x, 1==y, 2==z)
80  // B -> Parity Even (1==true)
81  // C -> Initial Repeated (1==true)
82  // D -> Frame Static (1==true)
83  //
84 
85  Legal = XYZ | XZY | YZX | YXZ | ZXY | ZYX |
86  XZX | XYX | YXY | YZY | ZYZ | ZXZ |
87  XYZr| XZYr| YZXr| YXZr| ZXYr| ZYXr|
88  XZXr| XYXr| YXYr| YZYr| ZYZr| ZXZr,
89 
90  // Min = 0x0000,
91  // Max = 0x2111,
93  } eulerOrder;
94 
95  enum Axis { axisX = 0, axisY = 1, axisZ = 2 };
96 
98 
99  //----------------------------------------------------------------
100  // Constructors -- all default to ZYZ non-relative
101  // (where there is no argument to specify it)
102  //----------------------------------------------------------------
103  Euler();
104  void init(void);
105  Euler(const Euler&);
106  Euler(eulerOrder p);
107  Euler(const Matrix1D<double> &v,
108  eulerOrder o = eulerDefault,
109  InputLayout l = IJKLayout);
110  Euler(double i, double j,
111  double k, eulerOrder o = eulerDefault, InputLayout l = IJKLayout);
112  Euler(const Euler &euler, eulerOrder newp);
113  Euler(const Matrix2D<double> &, eulerOrder o = eulerDefault);
114  //Euler(const Matrix44<T> &, Order o = Default);
115 
116  //---------------------------------
117  // Algebraic functions/ Operators
118  //---------------------------------
119 
120  const Euler& operator= (const Euler&);
121  const Euler& operator= (const Matrix1D<double>&);
122 
123  //--------------------------------------------------------
124  // Set the euler value
125  // This does NOT convert the angles, but setXYZVector()
126  // does reorder the input vector.
127  //--------------------------------------------------------
128 
129  static bool legal(eulerOrder);
130 
131  void setXYZVector(const Matrix1D<double> &);
132 
133  eulerOrder order() const;
134  void setOrder(eulerOrder);
135 
136  void set(Axis initial,
137  bool relative,
138  bool parityEven,
139  bool firstRepeats);
140 
141  //---------------------------------------------------------
142  // Conversions, toXYZVector() reorders the angles so that
143  // the X rotation comes first, followed by the Y and Z
144  // in cases like XYX ordering, the repeated angle will be
145  // in the "z" component
146  //---------------------------------------------------------
147 
148  void extract(const Matrix2D<double>&);
149  //void extract(const Matrix44<T>&);
150  //void extract(const Quat<T>&);
151 
152  void toMatrix(Matrix2D<double>& M) const;
153  //Matrix1D<double> toMatrix33() const;
154  //Matrix44<T> toMatrix44() const;
156  void toXYZVector(Matrix1D<double> &v) const;
157 
158  //---------------------------------------------------
159  // Use this function to unpack angles from ijk form
160  //---------------------------------------------------
161 
162  void angleOrder(int &i, int &j, int &k) const;
163 
164  //---------------------------------------------------
165  // Use this function to determine mapping from xyz to ijk
166  // - reshuffles the xyz to match the order
167  //---------------------------------------------------
168 
169  void angleMapping(int &i, int &j, int &k) const;
170 
171  //----------------------------------------------------------------------
172  //
173  // Utility methods for getting continuous rotations. None of these
174  // methods change the orientation given by its inputs (or at least
175  // that is the intent).
176  //
177  // angleMod() converts an angle to its equivalent in [-PI, PI]
178  //
179  // simpleXYZRotation() adjusts xyzRot so that its components differ
180  // from targetXyzRot by no more than +-PI
181  //
182  // nearestRotation() adjusts xyzRot so that its components differ
183  // from targetXyzRot by as little as possible.
184  // Note that xyz here really means ijk, because
185  // the order must be provided.
186  //
187  // makeNear() adjusts "this" Euler so that its components differ
188  // from target by as little as possible. This method
189  // might not make sense for Eulers with different order
190  // and it probably doesn't work for repeated axis and
191  // relative orderings (TODO).
192  //
193  //-----------------------------------------------------------------------
194 
195  static double angleMod (double angle);
196  static void simpleXYZRotation (Matrix1D<double> &xyzRot,
197  const Matrix1D<double> &targetXyzRot);
198  static void nearestRotation (Matrix1D<double> &xyzRot,
199  const Matrix1D<double> &targetXyzRot,
200  eulerOrder order = XYZ);
201 
202  void makeNear (const Euler &target);
203 
204  bool frameStatic() const
205  {
206  return _frameStatic;
207  }
208  bool initialRepeated() const
209  {
210  return _initialRepeated;
211  }
212  bool parityEven() const
213  {
214  return _parityEven;
215  }
217  {
218  return _initialAxis;
219  }
220 
222  double x;
223  double y;
224  double z;
225 
226  void eulerRotate (Matrix2D <double> &M, const Matrix1D <double> &r);
227 
228 protected:
229 
230 bool _frameStatic :
231  1; // relative or static rotations
232 bool _initialRepeated :
233  1; // init axis repeated as last
234 bool _parityEven :
235  1; // "parity of axis permutation"
237  2; // First axis of rotation
238 };
239 constexpr int eulerOrderNumber = 24;
241  {
246  };
247 
249 #endif
double z
Definition: euler.h:224
void extract(const Matrix2D< double > &)
Definition: euler.cpp:156
bool _frameStatic
Definition: euler.h:231
Axis _initialAxis
Definition: euler.h:237
Euler::eulerOrder eulerOrderList[eulerOrderNumber]
Definition: euler.h:240
eulerOrder
Definition: euler.h:43
void toMatrix(Matrix2D< double > &M) const
Definition: euler.cpp:250
void angleOrder(int &i, int &j, int &k) const
Definition: euler.cpp:28
void init(void)
Definition: euler.cpp:72
static double angleMod(double angle)
Definition: euler.cpp:396
Euler()
Definition: euler.cpp:80
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
bool _parityEven
Definition: euler.h:235
constexpr int eulerOrderNumber
Definition: euler.h:239
eulerOrder order() const
Definition: euler.cpp:320
void angleMapping(int &i, int &j, int &k) const
Definition: euler.cpp:36
const Euler & operator=(const Euler &)
Definition: euler.cpp:355
void setXYZVector(const Matrix1D< double > &)
Definition: euler.cpp:49
bool parityEven() const
Definition: euler.h:212
Definition: euler.h:39
InputLayout
Definition: euler.h:97
double x
Definition: euler.h:222
static void nearestRotation(Matrix1D< double > &xyzRot, const Matrix1D< double > &targetXyzRot, eulerOrder order=XYZ)
Definition: euler.cpp:419
#define j
Axis
Definition: euler.h:95
bool initialRepeated() const
Definition: euler.h:208
static bool legal(eulerOrder)
Definition: euler.cpp:315
bool frameStatic() const
Definition: euler.h:204
void eulerRotate(Matrix2D< double > &M, const Matrix1D< double > &r)
Definition: euler.cpp:464
void makeNear(const Euler &target)
Definition: euler.cpp:450
Matrix1D< double > vec3
Definition: euler.h:221
bool _initialRepeated
Definition: euler.h:233
Axis initialAxis() const
Definition: euler.h:216
static void simpleXYZRotation(Matrix1D< double > &xyzRot, const Matrix1D< double > &targetXyzRot)
Definition: euler.cpp:409
void toXYZVector(Matrix1D< double > &v) const
Definition: euler.cpp:61
void setOrder(eulerOrder)
Definition: euler.cpp:335
double y
Definition: euler.h:223