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
154  operator*(const Self & v) const;
155 
157  Self
158  operator/(const Self & v) const;
159 
162  bool
163  operator==(const Self & v) const;
164 
165  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
166 
168  ValueType
169  GetScalar() const;
170 
172  ValueType
173  GetX() const
174  {
175  return m_X;
176  }
177 
179  ValueType
180  GetY() const
181  {
182  return m_Y;
183  }
184 
186  ValueType
187  GetZ() const
188  {
189  return m_Z;
190  }
191 
193  ValueType
194  GetW() const
195  {
196  return m_W;
197  }
198 
200  ValueType
201  GetAngle() const;
202 
205  VectorType
206  GetAxis() const;
207 
212  VectorType
213  GetRight() const;
214 
219  void
220  Set(const VectorType & axis, ValueType angle);
221 
227  void
228  Set(const MatrixType & mat);
229 
235  void
236  Set(const VectorType & axis);
237 
244  void
245  SetRotationAroundX(ValueType angle);
246 
253  void
254  SetRotationAroundY(ValueType angle);
255 
262  void
263  SetRotationAroundZ(ValueType angle);
264 
267  void
268  SetIdentity();
269 
271  VectorType
272  Transform(const VectorType & v) const;
273 
278  CovariantVectorType
279  Transform(const CovariantVectorType & v) const;
280 
282  PointType
283  Transform(const PointType & v) const;
284 
286  VnlVectorType
287  Transform(const VnlVectorType & v) const;
288 
290  MatrixType
291  GetMatrix() const;
292 
294  Self
295  SquareRoot() const;
296 
300  Self
301  Exponential(ValueType exponent) const;
302 
303 private:
305  static inline ValueType
306  Epsilon(double *)
307  {
308  return 1e-10;
309  }
310  static inline ValueType
311  Epsilon(float *)
312  {
313  return 1e-7;
314  }
315  static inline ValueType
317  {
318  return Epsilon((ValueType *)nullptr);
319  }
323  ValueType m_X{};
324 
326  ValueType m_Y{};
327 
329  ValueType m_Z{};
330 
333 };
334 
335 template <typename T>
336 std::ostream &
337 operator<<(std::ostream & os, const Versor<T> & v)
338 {
339  os << "[ ";
340  os << v.GetX() << ", " << v.GetY() << ", ";
341  os << v.GetZ() << ", " << v.GetW() << " ]";
342  return os;
343 }
344 
345 template <typename T>
346 std::istream &
347 operator>>(std::istream & is, Versor<T> & v);
348 } // end namespace itk
349 
350 #ifndef ITK_MANUAL_INSTANTIATION
351 # include "itkVersor.hxx"
352 #endif
353 
354 #endif
itk::Versor::GetW
ValueType GetW() const
Definition: itkVersor.h:194
itk::Versor::GetZ
ValueType GetZ() const
Definition: itkVersor.h:187
itk::Versor::GetY
ValueType GetY() const
Definition: itkVersor.h:180
itkMatrix.h
itk::operator*
CovariantVector< T, VVectorDimension > operator*(const T &scalar, const CovariantVector< T, VVectorDimension > &v)
Definition: itkCovariantVector.h:272
itk::Versor< TParametersValueType >::VnlQuaternionType
vnl_quaternion< TParametersValueType > VnlQuaternionType
Definition: itkVersor.h:78
itk::Versor::Epsilon
static ValueType Epsilon()
Definition: itkVersor.h:316
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::operator<<
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
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:552
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:306
itk::Versor::GetX
ValueType GetX() const
Definition: itkVersor.h:173
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Versor::Epsilon
static ValueType Epsilon(float *)
Definition: itkVersor.h:311
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