ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkVersor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkVersor_h
19 #define itkVersor_h
20 
21 #include "itkMatrix.h"
22 #include "vnl/vnl_quaternion.h"
23 #include "vnl/vnl_vector_fixed.h"
24 
25 namespace itk
26 {
49 template< typename T >
50 class Versor
51 {
52 public:
54  typedef Versor Self;
55 
58  typedef T ValueType;
59 
62 
65 
68 
71 
73  typedef vnl_vector_fixed< T, 3 > VnlVectorType;
74 
76  typedef vnl_quaternion< T > VnlQuaternionType;
77 
80 
82  vnl_quaternion< T > GetVnlQuaternion() const;
83 
87  void Set(const VnlQuaternionType &);
88 
106  void Set(T x, T y, T z, T w);
108 
111  Versor();
112 
114  Versor(const Self & v);
115 
117  const Self & operator=(const Self & v);
118 
122  const Self & operator*=(const Self & v);
123 
128  const Self & operator/=(const Self & v);
129 
133  ValueType GetTensor() const;
134 
139  void Normalize();
140 
143  Self GetConjugate() const;
144 
148  Self GetReciprocal() const;
149 
152  Self operator *(const Self & vec) const;
153 
155  Self operator/(const Self & vec) const;
156 
159  bool operator==(const Self & vec) const;
160 
163  bool operator!=(const Self & vec) const;
164 
166  ValueType GetScalar() const;
167 
169  ValueType GetX(void) const { return m_X; }
170 
172  ValueType GetY(void) const { return m_Y; }
173 
175  ValueType GetZ(void) const { return m_Z; }
176 
178  ValueType GetW(void) const { return m_W; }
179 
181  ValueType GetAngle() const;
182 
185  VectorType GetAxis() const;
186 
191  VectorType GetRight() const;
192 
196  void Set(const VectorType & axis, ValueType angle);
197 
203  void Set(const MatrixType & m);
204 
210  void Set(const VectorType & axis);
211 
218  void SetRotationAroundX(ValueType angle);
219 
226  void SetRotationAroundY(ValueType angle);
227 
234  void SetRotationAroundZ(ValueType angle);
235 
238  void SetIdentity();
239 
241  VectorType Transform(const VectorType & v) const;
242 
245 
247  PointType Transform(const PointType & v) const;
248 
250  VnlVectorType Transform(const VnlVectorType & v) const;
251 
253  MatrixType GetMatrix() const;
254 
256  Self SquareRoot() const;
257 
261  Self Exponential(ValueType exponent) const;
262 
263 private:
265  static inline ValueType Epsilon(double *)
266  {
267  return 1e-10;
268  }
269  static inline ValueType Epsilon(float *)
270  {
271  return 1e-7;
272  }
273  static inline ValueType Epsilon()
274  {
275  return Epsilon((ValueType *)ITK_NULLPTR);
276  }
278 
281 
284 
287 
290 };
291 
292 template< typename T >
293 std::ostream & operator<<(std::ostream & os,
294  const Versor< T > & v)
295 {
296  os << "[ ";
297  os << v.GetX() << ", " << v.GetY() << ", ";
298  os << v.GetZ() << ", " << v.GetW() << " ]";
299  return os;
300 }
301 
302 template< typename T >
303 std::istream & operator>>(std::istream & is,
304  Versor< T > & v);
305 } // end namespace itk
306 
307 #ifndef ITK_MANUAL_INSTANTIATION
308 #include "itkVersor.hxx"
309 #endif
310 
311 #endif
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:46
MatrixType GetMatrix() const
Self SquareRoot() const
vnl_quaternion< T > VnlQuaternionType
Definition: itkVersor.h:76
ValueType GetAngle() const
ValueType m_X
Definition: itkVersor.h:280
VectorType GetAxis() const
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
VectorType Transform(const VectorType &v) const
static ValueType Epsilon(float *)
Definition: itkVersor.h:269
bool operator!=(const Self &vec) const
const Self & operator/=(const Self &v)
Vector< T, 3 > VectorType
Definition: itkVersor.h:64
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:184
ValueType m_Y
Definition: itkVersor.h:283
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
void Set(const VnlQuaternionType &)
void SetRotationAroundY(ValueType angle)
Point< T, 3 > PointType
Definition: itkVersor.h:67
vnl_quaternion< T > GetVnlQuaternion() const
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
static ValueType Epsilon()
Definition: itkVersor.h:273
ValueType m_W
Definition: itkVersor.h:289
CovariantVector< T, 3 > CovariantVectorType
Definition: itkVersor.h:70
const Self & operator*=(const Self &v)
Self operator/(const Self &vec) const
void Normalize()
A templated class holding a unit quaternion.
Definition: itkVersor.h:50
ValueType m_Z
Definition: itkVersor.h:286
void SetIdentity()
VectorType GetRight() const
ValueType GetX(void) const
Definition: itkVersor.h:169
ValueType GetTensor() const
Self GetReciprocal() const
vnl_vector_fixed< T, 3 > VnlVectorType
Definition: itkVersor.h:73
ValueType GetZ(void) const
Definition: itkVersor.h:175
NumericTraits< ValueType >::RealType RealType
Definition: itkVersor.h:61
Matrix< T, 3, 3 > MatrixType
Definition: itkVersor.h:79
ValueType GetY(void) const
Definition: itkVersor.h:172
void SetRotationAroundZ(ValueType angle)
Self operator*(const Self &vec) const
Versor Self
Definition: itkVersor.h:54
const Self & operator=(const Self &v)
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
ValueType GetW(void) const
Definition: itkVersor.h:178
A templated class holding a n-Dimensional covariant vector.
ValueType GetScalar() const
bool operator==(const Self &vec) const
static ValueType Epsilon(double *)
Definition: itkVersor.h:265
void SetRotationAroundX(ValueType angle)
Self GetConjugate() const
Self Exponential(ValueType exponent) const