ITK  6.0.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 {
51 template <typename T>
52 class ITK_TEMPLATE_EXPORT Versor
53 {
54 public:
56  using Self = Versor;
57 
60  using ValueType = T;
61 
64 
67 
70 
73 
75  using VnlVectorType = vnl_vector_fixed<T, 3>;
76 
78  using VnlQuaternionType = vnl_quaternion<T>;
79 
82 
84  vnl_quaternion<T>
85  GetVnlQuaternion() const;
86 
90  void
91  Set(const VnlQuaternionType &);
92 
110  void
111  Set(T x, T y, T z, T w);
117  const Self &
118  operator*=(const Self & v);
119 
124  const Self &
125  operator/=(const Self & v);
126 
130  ValueType
131  GetTensor() const;
132 
137  void
138  Normalize();
139 
142  Self
143  GetConjugate() const;
144 
148  Self
149  GetReciprocal() const;
150 
153  Self operator*(const Self & v) const;
154 
156  Self
157  operator/(const Self & v) const;
158 
161  bool
162  operator==(const Self & v) const;
163 
164  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
165 
167  ValueType
168  GetScalar() const;
169 
171  ValueType
172  GetX() const
173  {
174  return m_X;
175  }
176 
178  ValueType
179  GetY() const
180  {
181  return m_Y;
182  }
183 
185  ValueType
186  GetZ() const
187  {
188  return m_Z;
189  }
190 
192  ValueType
193  GetW() const
194  {
195  return m_W;
196  }
197 
199  ValueType
200  GetAngle() const;
201 
204  VectorType
205  GetAxis() const;
206 
211  VectorType
212  GetRight() const;
213 
218  void
219  Set(const VectorType & axis, ValueType angle);
220 
226  void
227  Set(const MatrixType & mat);
228 
234  void
235  Set(const VectorType & axis);
236 
243  void
244  SetRotationAroundX(ValueType angle);
245 
252  void
253  SetRotationAroundY(ValueType angle);
254 
261  void
262  SetRotationAroundZ(ValueType angle);
263 
266  void
267  SetIdentity();
268 
270  VectorType
271  Transform(const VectorType & v) const;
272 
277  CovariantVectorType
278  Transform(const CovariantVectorType & v) const;
279 
281  PointType
282  Transform(const PointType & v) const;
283 
285  VnlVectorType
286  Transform(const VnlVectorType & v) const;
287 
289  MatrixType
290  GetMatrix() const;
291 
293  Self
294  SquareRoot() const;
295 
299  Self
300  Exponential(ValueType exponent) const;
301 
302 private:
304  static inline ValueType
305  Epsilon(double *)
306  {
307  return 1e-10;
308  }
309  static inline ValueType
310  Epsilon(float *)
311  {
312  return 1e-7;
313  }
314  static inline ValueType
316  {
317  return Epsilon((ValueType *)nullptr);
318  }
322  ValueType m_X{};
323 
325  ValueType m_Y{};
326 
328  ValueType m_Z{};
329 
332 };
333 
334 template <typename T>
335 std::ostream &
336 operator<<(std::ostream & os, const Versor<T> & v)
337 {
338  os << "[ ";
339  os << v.GetX() << ", " << v.GetY() << ", ";
340  os << v.GetZ() << ", " << v.GetW() << " ]";
341  return os;
342 }
343 
344 template <typename T>
345 std::istream &
346 operator>>(std::istream & is, Versor<T> & v);
347 } // end namespace itk
348 
349 #ifndef ITK_MANUAL_INSTANTIATION
350 # include "itkVersor.hxx"
351 #endif
352 
353 #endif
itk::Versor::GetW
ValueType GetW() const
Definition: itkVersor.h:193
itk::Versor::GetZ
ValueType GetZ() const
Definition: itkVersor.h:186
itk::Versor::GetY
ValueType GetY() const
Definition: itkVersor.h:179
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:78
itk::Versor::Epsilon
static ValueType Epsilon()
Definition: itkVersor.h:315
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:52
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:158
itk::Versor< TParametersValueType >::ValueType
TParametersValueType ValueType
Definition: itkVersor.h:60
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:543
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:305
itk::Versor::GetX
ValueType GetX() const
Definition: itkVersor.h:172
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:310
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:86
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:75
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
itk::Versor< TParametersValueType >::RealType
typename NumericTraits< ValueType >::RealType RealType
Definition: itkVersor.h:63