ITK  5.2.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 
175  bool
176  operator!=(const Self & v) const;
177 
179  ValueType
180  GetScalar() const;
181 
183  ValueType
184  GetX() const
185  {
186  return m_X;
187  }
188 
190  ValueType
191  GetY() const
192  {
193  return m_Y;
194  }
195 
197  ValueType
198  GetZ() const
199  {
200  return m_Z;
201  }
202 
204  ValueType
205  GetW() const
206  {
207  return m_W;
208  }
209 
211  ValueType
212  GetAngle() const;
213 
216  VectorType
217  GetAxis() const;
218 
223  VectorType
224  GetRight() const;
225 
229  void
230  Set(const VectorType & axis, ValueType angle);
231 
237  void
238  Set(const MatrixType & mat);
239 
245  void
246  Set(const VectorType & axis);
247 
254  void
255  SetRotationAroundX(ValueType angle);
256 
263  void
264  SetRotationAroundY(ValueType angle);
265 
272  void
273  SetRotationAroundZ(ValueType angle);
274 
277  void
278  SetIdentity();
279 
281  VectorType
282  Transform(const VectorType & v) const;
283 
285  CovariantVectorType
286  Transform(const CovariantVectorType & v) const;
287 
289  PointType
290  Transform(const PointType & v) const;
291 
293  VnlVectorType
294  Transform(const VnlVectorType & v) const;
295 
297  MatrixType
298  GetMatrix() const;
299 
301  Self
302  SquareRoot() const;
303 
307  Self
308  Exponential(ValueType exponent) const;
309 
310 private:
312  static inline ValueType
313  Epsilon(double *)
314  {
315  return 1e-10;
316  }
317  static inline ValueType
318  Epsilon(float *)
319  {
320  return 1e-7;
321  }
322  static inline ValueType
324  {
325  return Epsilon((ValueType *)nullptr);
326  }
328 
331 
334 
337 
340 };
341 
342 template <typename T>
343 std::ostream &
344 operator<<(std::ostream & os, const Versor<T> & v)
345 {
346  os << "[ ";
347  os << v.GetX() << ", " << v.GetY() << ", ";
348  os << v.GetZ() << ", " << v.GetW() << " ]";
349  return os;
350 }
351 
352 template <typename T>
353 std::istream &
354 operator>>(std::istream & is, Versor<T> & v);
355 } // end namespace itk
356 
357 #ifndef ITK_MANUAL_INSTANTIATION
358 # include "itkVersor.hxx"
359 #endif
360 
361 #endif
itk::Versor::GetW
ValueType GetW() const
Definition: itkVersor.h:205
itk::Versor::GetZ
ValueType GetZ() const
Definition: itkVersor.h:198
itk::Versor::GetY
ValueType GetY() const
Definition: itkVersor.h:191
itkMatrix.h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
itk::Versor< TParametersValueType >::VnlQuaternionType
vnl_quaternion< TParametersValueType > VnlQuaternionType
Definition: itkVersor.h:76
itk::Versor::Epsilon
static ValueType Epsilon()
Definition: itkVersor.h:323
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:339
itk::Versor::m_X
ValueType m_X
Definition: itkVersor.h:330
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:333
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:532
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:313
itk::Versor::GetX
ValueType GetX() const
Definition: itkVersor.h:184
itk::operator!=
bool operator!=(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:539
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:318
itk::Versor::m_Z
ValueType m_Z
Definition: itkVersor.h:336
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:82
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