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-2014 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 <ostream>
25 #include <mia/3d/defines3d.hh>
26 #include <mia/3d/matrix.hh>
27 #include <mia/3d/vector.hh>
28 
30 
41 
42 public:
46  Quaternion();
47 
52  Quaternion(const Quaternion& other) = default;
53 
59  Quaternion(const C3DDVector& rot);
60 
61 
68  Quaternion(const C3DFMatrix& rot);
69 
76  Quaternion(const C3DDMatrix& rot);
77 
81  Quaternion(double w, double x, double y, double z);
82 
89  friend bool operator == (const Quaternion& a, const Quaternion& b);
90 
92  double norm() const;
93 
95  void normalize();
96 
98  Quaternion inverse() const;
99 
101  C3DDVector get_euler_angles() const;
102 
108  Quaternion& operator += (const Quaternion& other);
109 
115  Quaternion& operator -= (const Quaternion& other);
116 
123  Quaternion& operator *= (const Quaternion& other);
124 
129  void print(std::ostream& os) const;
130 
132  double w() const;
133 
135  double x() const;
136 
138  double y() const;
139 
141  double z() const;
142 
143  const C3DDMatrix get_rotation_matrix() const;
144 
145  static const Quaternion _1;
146 
147 private:
148  C3DDVector m_v;
149  double m_w;
150 };
151 
152 bool EXPORT_3D operator == (const Quaternion& a, const Quaternion& b);
153 bool EXPORT_3D operator != (const Quaternion& a, const Quaternion& b);
154 
155 
156 
157 
158 inline double Quaternion::w() const
159 {
160  return m_w;
161 }
162 
163 inline double Quaternion::x() const
164 {
165  return m_v.x;
166 }
167 
168 inline double Quaternion::y() const
169 {
170  return m_v.y;
171 }
172 
173 inline double Quaternion::z() const
174 {
175  return m_v.z;
176 }
177 
178 
179 
180 inline std::ostream& operator << (std::ostream& os, const Quaternion& a)
181 {
182  a.print(os);
183  return os;
184 }
185 
186 EXPORT_3D std::istream& operator >> (std::istream& os, Quaternion& a);
187 
189 
190 #endif
a class to implement a quaternion
Definition: quaternion.hh:40
bool EXPORT_3D operator!=(const Quaternion &a, const Quaternion &b)
EXPORT_3D std::istream & operator>>(std::istream &os, Quaternion &a)
double z() const
Definition: quaternion.hh:173
T z
vector element
Definition: 3d/vector.hh:55
void print(std::ostream &os) const
double w() const
Definition: quaternion.hh:158
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:43
EXPORT_2D C2DFVectorfield & operator+=(C2DFVectorfield &a, const C2DFVectorfield &b)
#define EXPORT_3D
Definition: defines3d.hh:44
static const Quaternion _1
Definition: quaternion.hh:145
double x() const
Definition: quaternion.hh:163
T y
vector element
Definition: 3d/vector.hh:53
double y() const
Definition: quaternion.hh:168
CCmdOptionFlags operator-=(CCmdOptionFlags &lhs, CCmdOptionFlags rhs)
std::ostream & operator<<(std::ostream &os, const Quaternion &a)
Definition: quaternion.hh:180
bool EXPORT_3D operator==(const Quaternion &a, const Quaternion &b)
T x
vector element
Definition: 3d/vector.hh:51
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46