ITK  5.0.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 ITK_TEMPLATE_EXPORT Versor
51 {
52 public:
54  using Self = Versor;
55 
58  using ValueType = T;
59 
62 
65 
68 
71 
73  using VnlVectorType = vnl_vector_fixed< T, 3 >;
74 
76  using VnlQuaternionType = vnl_quaternion< T >;
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() const { return m_X; }
170 
172  ValueType GetY() const { return m_Y; }
173 
175  ValueType GetZ() const { return m_Z; }
176 
178  ValueType GetW() 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 
244  CovariantVectorType Transform(const CovariantVectorType & v) const;
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 *)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:49
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:485
ValueType m_X
Definition: itkVersor.h:280
Define numeric traits for std::vector.
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
static ValueType Epsilon(float *)
Definition: itkVersor.h:269
TParametersValueType ValueType
Definition: itkVersor.h:58
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:188
ValueType m_Y
Definition: itkVersor.h:283
typename NumericTraits< ValueType >::RealType RealType
Definition: itkVersor.h:61
ValueType GetY() const
Definition: itkVersor.h:172
ValueType GetX() const
Definition: itkVersor.h:169
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:492
static ValueType Epsilon()
Definition: itkVersor.h:273
ValueType m_W
Definition: itkVersor.h:289
A templated class holding a unit quaternion.
Definition: itkVersor.h:50
ValueType m_Z
Definition: itkVersor.h:286
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
vnl_quaternion< TParametersValueType > VnlQuaternionType
Definition: itkVersor.h:76
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
ValueType GetW() const
Definition: itkVersor.h:178
A templated class holding a n-Dimensional covariant vector.
ValueType GetZ() const
Definition: itkVersor.h:175
static ValueType Epsilon(double *)
Definition: itkVersor.h:265
vnl_vector_fixed< TParametersValueType, 3 > VnlVectorType
Definition: itkVersor.h:73