My Project
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 
46 public:
51 
56  Quaternion(const Quaternion& other) = default;
57 
63  Quaternion(const C3DDVector& rot);
64 
65 
72  Quaternion(const C3DFMatrix& rot);
73 
80  Quaternion(const C3DDMatrix& rot);
81 
85  Quaternion(double w, double x, double y, double z);
86 
93  friend bool operator == (const Quaternion& a, const Quaternion& b);
94 
96  double norm() const;
97 
99  void normalize();
100 
103 
106 
113 
119  Quaternion& operator -= (const Quaternion& other);
120 
127  Quaternion& operator *= (const Quaternion& other);
128 
133  void print(std::ostream& os) const;
134 
136  double w() const;
137 
139  double x() const;
140 
142  double y() const;
143 
145  double z() const;
146 
148 
149  static const Quaternion _1;
150 
151 private:
152  C3DDVector m_v;
153  double m_w;
154 };
155 
156 bool EXPORT_3D operator == (const Quaternion& a, const Quaternion& b);
157 bool EXPORT_3D operator != (const Quaternion& a, const Quaternion& b);
158 
159 
160 inline double Quaternion::w() const
161 {
162  return m_w;
163 }
164 
165 inline double Quaternion::x() const
166 {
167  return m_v.x;
168 }
169 
170 inline double Quaternion::y() const
171 {
172  return m_v.y;
173 }
174 
175 inline double Quaternion::z() const
176 {
177  return m_v.z;
178 }
179 
180 
181 
182 inline std::ostream& operator << (std::ostream& os, const Quaternion& a)
183 {
184  a.print(os);
185  return os;
186 }
187 
188 EXPORT_3D std::istream& operator >> (std::istream& os, Quaternion& a);
189 
191 
192 #endif
Quaternion::y
double y() const
Definition: quaternion.hh:170
T3DMatrix< float >
operator<<
std::ostream & operator<<(std::ostream &os, const Quaternion &a)
Definition: quaternion.hh:182
Quaternion::z
double z() const
Definition: quaternion.hh:175
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
Quaternion::Quaternion
Quaternion(const C3DFMatrix &rot)
Quaternion::print
void print(std::ostream &os) const
Quaternion::Quaternion
Quaternion(const Quaternion &other)=default
Quaternion::x
double x() const
Definition: quaternion.hh:165
T3DVector::x
T x
vector element
Definition: 3d/vector.hh:52
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
operator!=
bool EXPORT_3D operator!=(const Quaternion &a, const Quaternion &b)
operator==
bool EXPORT_3D operator==(const Quaternion &a, const Quaternion &b)
operator+=
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
Quaternion::Quaternion
Quaternion(const C3DDMatrix &rot)
Quaternion::normalize
void normalize()
normalizes to quaternion
Quaternion::get_euler_angles
C3DDVector get_euler_angles() const
Quaternion::Quaternion
Quaternion()
defines3d.hh
Quaternion::norm
double norm() const
operator>>
EXPORT_3D std::istream & operator>>(std::istream &os, Quaternion &a)
Quaternion::w
double w() const
Definition: quaternion.hh:160
EXPORT_3D
#define EXPORT_3D
Definition: defines3d.hh:45
matrix.hh
Quaternion::Quaternion
Quaternion(const C3DDVector &rot)
Quaternion
a class to implement a quaternion
Definition: quaternion.hh:44
Quaternion::get_rotation_matrix
const C3DDMatrix get_rotation_matrix() const
Quaternion::_1
static const Quaternion _1
Definition: quaternion.hh:149
T3DVector::y
T y
vector element
Definition: 3d/vector.hh:54
Quaternion::inverse
Quaternion inverse() const
T3DVector< double >
Quaternion::Quaternion
Quaternion(double w, double x, double y, double z)
vector.hh
T3DVector::z
T z
vector element
Definition: 3d/vector.hh:56