ITK  5.3.0
Insight Toolkit
itkVersor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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>
83  GetVnlQuaternion() const;
84 
88  void
89  Set(const VnlQuaternionType &);
90 
108  void
109  Set(T x, T y, T z, T w);
111 
114  Versor();
115 
117  Versor(const Self & v);
118 
120  const Self &
121  operator=(const Self & v);
122 
126  const Self &
127  operator*=(const Self & v);
128 
133  const Self &
134  operator/=(const Self & v);
135 
139  ValueType
140  GetTensor() const;
141 
146  void
147  Normalize();
148 
151  Self
152  GetConjugate() const;
153 
157  Self
158  GetReciprocal() const;
159 
162  Self operator*(const Self & v) const;
163 
165  Self
166  operator/(const Self & v) const;
167 
170  bool
171  operator==(const Self & v) const;
172 
173  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
174 
176  ValueType
177  GetScalar() const;
178 
180  ValueType
181  GetX() const
182  {
183  return m_X;
184  }
185 
187  ValueType
188  GetY() const
189  {
190  return m_Y;
191  }
192 
194  ValueType
195  GetZ() const
196  {
197  return m_Z;
198  }
199 
201  ValueType
202  GetW() const
203  {
204  return m_W;
205  }
206 
208  ValueType
209  GetAngle() const;
210 
213  VectorType
214  GetAxis() const;
215 
220  VectorType
221  GetRight() const;
222 
226  void
227  Set(const VectorType & axis, ValueType angle);
228 
234  void
235  Set(const MatrixType & mat);
236 
242  void
243  Set(const VectorType & axis);
244 
251  void
252  SetRotationAroundX(ValueType angle);
253 
260  void
261  SetRotationAroundY(ValueType angle);
262 
269  void
270  SetRotationAroundZ(ValueType angle);
271 
274  void
275  SetIdentity();
276 
278  VectorType
279  Transform(const VectorType & v) const;
280 
282  CovariantVectorType
283  Transform(const CovariantVectorType & v) const;
284 
286  PointType
287  Transform(const PointType & v) const;
288 
290  VnlVectorType
291  Transform(const VnlVectorType & v) const;
292 
294  MatrixType
295  GetMatrix() const;
296 
298  Self
299  SquareRoot() const;
300 
304  Self
305  Exponential(ValueType exponent) const;
306 
307 private:
309  static inline ValueType
310  Epsilon(double *)
311  {
312  return 1e-10;
313  }
314  static inline ValueType
315  Epsilon(float *)
316  {
317  return 1e-7;
318  }
319  static inline ValueType
321  {
322  return Epsilon((ValueType *)nullptr);
323  }
325 
328 
331 
334 
337 };
338 
339 template <typename T>
340 std::ostream &
341 operator<<(std::ostream & os, const Versor<T> & v)
342 {
343  os << "[ ";
344  os << v.GetX() << ", " << v.GetY() << ", ";
345  os << v.GetZ() << ", " << v.GetW() << " ]";
346  return os;
347 }
348 
349 template <typename T>
350 std::istream &
351 operator>>(std::istream & is, Versor<T> & v);
352 } // end namespace itk
353 
354 #ifndef ITK_MANUAL_INSTANTIATION
355 # include "itkVersor.hxx"
356 #endif
357 
358 #endif
itk::Versor::GetW
ValueType GetW() const
Definition: itkVersor.h:202
itk::Versor::GetZ
ValueType GetZ() const
Definition: itkVersor.h:195
itk::Versor::GetY
ValueType GetY() const
Definition: itkVersor.h:188
itkMatrix.h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itk::Versor< TParametersValueType >::VnlQuaternionType
vnl_quaternion< TParametersValueType > VnlQuaternionType
Definition: itkVersor.h:76
itk::Versor::Epsilon
static ValueType Epsilon()
Definition: itkVersor.h:320
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::Versor::m_W
ValueType m_W
Definition: itkVersor.h:336
itk::Versor::m_X
ValueType m_X
Definition: itkVersor.h:327
itk::Vector< TParametersValueType, 3 >
itk::Versor
A templated class holding a unit quaternion.
Definition: itkVersor.h:50
itk::Versor::m_Y
ValueType m_Y
Definition: itkVersor.h:330
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &vct)
itk::Versor< TParametersValueType >::ValueType
TParametersValueType ValueType
Definition: itkVersor.h:58
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:536
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:51
itk::operator*
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
Definition: itkCovariantVector.h:275
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::Versor::Epsilon
static ValueType Epsilon(double *)
Definition: itkVersor.h:310
itk::Versor::GetX
ValueType GetX() const
Definition: itkVersor.h:181
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Versor::Epsilon
static ValueType Epsilon(float *)
Definition: itkVersor.h:315
itk::Versor::m_Z
ValueType m_Z
Definition: itkVersor.h:333
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
itk::Versor< TParametersValueType >::VnlVectorType
vnl_vector_fixed< TParametersValueType, 3 > VnlVectorType
Definition: itkVersor.h:73
itk::Versor< TParametersValueType >::RealType
typename NumericTraits< ValueType >::RealType RealType
Definition: itkVersor.h:61