quaternion.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_3d_quaternion_hh
22 #define mia_3d_quaternion_hh
23 
24 #include <mia/3d/defines3d.hh>
25 #include <mia/3d/matrix.hh>
26 #include <mia/3d/vector.hh>
27 
28 #include <ostream>
29 #include <cmath>
30 
32 
33 
44 
45 public:
49  Quaternion();
50 
55  Quaternion(const Quaternion& other) = default;
56 
62  Quaternion(const C3DDVector& rot);
63 
64 
71  Quaternion(const C3DFMatrix& rot);
72 
79  Quaternion(const C3DDMatrix& rot);
80 
84  Quaternion(double w, double x, double y, double z);
85 
92  friend bool operator == (const Quaternion& a, const Quaternion& b);
93 
95  double norm() const;
96 
98  void normalize();
99 
101  Quaternion inverse() const;
102 
104  C3DDVector get_euler_angles() const;
105 
111  Quaternion& operator += (const Quaternion& other);
112 
118  Quaternion& operator -= (const Quaternion& other);
119 
126  Quaternion& operator *= (const Quaternion& other);
127 
132  void print(std::ostream& os) const;
133 
135  double w() const;
136 
138  double x() const;
139 
141  double y() const;
142 
144  double z() const;
145 
146  const C3DDMatrix get_rotation_matrix() const;
147 
148  static const Quaternion _1;
149 
150 private:
151  C3DDVector m_v;
152  double m_w;
153 };
154 
155 bool EXPORT_3D operator == (const Quaternion& a, const Quaternion& b);
156 bool EXPORT_3D operator != (const Quaternion& a, const Quaternion& b);
157 
158 
159 inline double Quaternion::w() const
160 {
161  return m_w;
162 }
163 
164 inline double Quaternion::x() const
165 {
166  return m_v.x;
167 }
168 
169 inline double Quaternion::y() const
170 {
171  return m_v.y;
172 }
173 
174 inline double Quaternion::z() const
175 {
176  return m_v.z;
177 }
178 
179 
180 
181 inline std::ostream& operator << (std::ostream& os, const Quaternion& a)
182 {
183  a.print(os);
184  return os;
185 }
186 
187 EXPORT_3D std::istream& operator >> (std::istream& os, Quaternion& a);
188 
190 
191 #endif
a class to implement a quaternion
Definition: quaternion.hh:43
bool EXPORT_3D operator!=(const Quaternion &a, const Quaternion &b)
EXPORT_3D std::istream & operator>>(std::istream &os, Quaternion &a)
std::shared_ptr< Image > normalize(const Image &image)
a normalizer for image intensities
Definition: normalize.hh:131
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
#define EXPORT_3D
Definition: defines3d.hh:44
static const Quaternion _1
Definition: quaternion.hh:148
double z() const
Definition: quaternion.hh:174
double y() const
Definition: quaternion.hh:169
std::ostream & operator<<(std::ostream &os, const Quaternion &a)
Definition: quaternion.hh:181
void print(std::ostream &os) const
double w() const
Definition: quaternion.hh:159
bool EXPORT_3D operator==(const Quaternion &a, const Quaternion &b)
double x() const
Definition: quaternion.hh:164
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36