ITK  5.4.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  * https://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);
114  Versor() = default;
115 
117  Versor(const Self & v);
118 
120  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 
227  void
228  Set(const VectorType & axis, ValueType angle);
229 
235  void
236  Set(const MatrixType & mat);
237 
243  void
244  Set(const VectorType & axis);
245 
252  void
253  SetRotationAroundX(ValueType angle);
254 
261  void
262  SetRotationAroundY(ValueType angle);
263 
270  void
271  SetRotationAroundZ(ValueType angle);
272 
275  void
276  SetIdentity();
277 
279  VectorType
280  Transform(const VectorType & v) const;
281 
286  CovariantVectorType
287  Transform(const CovariantVectorType & v) const;
288 
290  PointType
291  Transform(const PointType & v) const;
292 
294  VnlVectorType
295  Transform(const VnlVectorType & v) const;
296 
298  MatrixType
299  GetMatrix() const;
300 
302  Self
303  SquareRoot() const;
304 
308  Self
309  Exponential(ValueType exponent) const;
310 
311 private:
313  static inline ValueType
314  Epsilon(double *)
315  {
316  return 1e-10;
317  }
318  static inline ValueType
319  Epsilon(float *)
320  {
321  return 1e-7;
322  }
323  static inline ValueType
325  {
326  return Epsilon((ValueType *)nullptr);
327  }
331  ValueType m_X{};
332 
334  ValueType m_Y{};
335 
337  ValueType m_Z{};
338 
341 };
342 
343 template <typename T>
344 std::ostream &
345 operator<<(std::ostream & os, const Versor<T> & v)
346 {
347  os << "[ ";
348  os << v.GetX() << ", " << v.GetY() << ", ";
349  os << v.GetZ() << ", " << v.GetW() << " ]";
350  return os;
351 }
352 
353 template <typename T>
354 std::istream &
355 operator>>(std::istream & is, Versor<T> & v);
356 } // end namespace itk
357 
358 #ifndef ITK_MANUAL_INSTANTIATION
359 # include "itkVersor.hxx"
360 #endif
361 
362 #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::operator*
CovariantVector< T, VVectorDimension > operator*(const T &scalar, const CovariantVector< T, VVectorDimension > &v)
Definition: itkCovariantVector.h:268
itk::Versor< TParametersValueType >::VnlQuaternionType
vnl_quaternion< TParametersValueType > VnlQuaternionType
Definition: itkVersor.h:76
itk::Versor::Epsilon
static ValueType Epsilon()
Definition: itkVersor.h:324
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::Vector< TParametersValueType, 3 >
itk::Versor
A templated class holding a unit quaternion.
Definition: itkVersor.h:50
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:157
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:545
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:52
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:314
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:319
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
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:85
itk::Transform
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:83
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::Versor< TParametersValueType >::VnlVectorType
vnl_vector_fixed< TParametersValueType, 3 > VnlVectorType
Definition: itkVersor.h:73
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
itk::Versor< TParametersValueType >::RealType
typename NumericTraits< ValueType >::RealType RealType
Definition: itkVersor.h:61