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
46public:
51
56 Quaternion(const Quaternion& other) = default;
57
64
65
73
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
151private:
152 C3DDVector m_v;
153 double m_w;
154};
155
158
159
160inline double Quaternion::w() const
161{
162 return m_w;
163}
164
165inline double Quaternion::x() const
166{
167 return m_v.x;
168}
169
170inline double Quaternion::y() const
171{
172 return m_v.y;
173}
174
175inline double Quaternion::z() const
176{
177 return m_v.z;
178}
179
180
181
182inline std::ostream& operator << (std::ostream& os, const Quaternion& a)
183{
184 a.print(os);
185 return os;
186}
187
188EXPORT_3D std::istream& operator >> (std::istream& os, Quaternion& a);
189
191
192#endif
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
a class to implement a quaternion
Definition: quaternion.hh:44
Quaternion(const Quaternion &other)=default
double norm() const
double x() const
Definition: quaternion.hh:165
const C3DDMatrix get_rotation_matrix() const
Quaternion(const C3DFMatrix &rot)
Quaternion inverse() const
Quaternion(double w, double x, double y, double z)
void normalize()
normalizes to quaternion
double z() const
Definition: quaternion.hh:175
double w() const
Definition: quaternion.hh:160
static const Quaternion _1
Definition: quaternion.hh:149
void print(std::ostream &os) const
Quaternion(const C3DDMatrix &rot)
C3DDVector get_euler_angles() const
double y() const
Definition: quaternion.hh:170
Quaternion(const C3DDVector &rot)
T y
vector element
Definition: 3d/vector.hh:54
T z
vector element
Definition: 3d/vector.hh:56
T x
vector element
Definition: 3d/vector.hh:52
#define EXPORT_3D
Definition: defines3d.hh:45
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
bool EXPORT_3D operator==(const Quaternion &a, const Quaternion &b)
bool EXPORT_3D operator!=(const Quaternion &a, const Quaternion &b)
EXPORT_3D std::istream & operator>>(std::istream &os, Quaternion &a)
std::ostream & operator<<(std::ostream &os, const Quaternion &a)
Definition: quaternion.hh:182