ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkVersor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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< class T >
50 class Versor
51 {
52 public:
54  typedef Versor Self;
55 
58  typedef T ValueType;
59 
62 
65 
68 
71 
73  typedef vnl_vector_fixed< T, 3 > VnlVectorType;
74 
76  typedef vnl_quaternion< T > VnlQuaternionType;
77 
80 
82  vnl_quaternion< T > GetVnlQuaternion(void) const;
83 
87  void Set(const VnlQuaternionType &);
88 
106  void Set(T x, T y, T z, T w);
108 
111  Versor();
112 
114  Versor(const Self & v);
115 
117  const Self & operator=(const Self & v);
118 
122  const Self & operator*=(const Self & v);
123 
128  const Self & operator/=(const Self & v);
129 
133  ValueType GetTensor(void) const;
134 
139  void Normalize(void);
140 
143  Self GetConjugate(void) const;
144 
148  Self GetReciprocal(void) const;
149 
152  Self operator *(const Self & vec) const;
153 
155  Self operator/(const Self & vec) const;
156 
159  bool operator==(const Self & vec) const;
160 
163  bool operator!=(const Self & vec) const;
164 
166  ValueType GetScalar(void) const;
167 
169  ValueType GetX(void) const { return m_X; }
170 
172  ValueType GetY(void) const { return m_Y; }
173 
175  ValueType GetZ(void) const { return m_Z; }
176 
178  ValueType GetW(void) const { return m_W; }
179 
181  ValueType GetAngle(void) const;
182 
185  VectorType GetAxis(void) const;
186 
191  VectorType GetRight(void) const;
192 
196  void Set(const VectorType & axis, ValueType angle);
197 
203  void Set(const MatrixType & m);
204 
210  void Set(const VectorType & axis);
211 
218  void SetRotationAroundX(ValueType angle);
219 
226  void SetRotationAroundY(ValueType angle);
227 
234  void SetRotationAroundZ(ValueType angle);
235 
238  void SetIdentity();
239 
241  VectorType Transform(const VectorType & v) const;
242 
245 
247  PointType Transform(const PointType & v) const;
248 
250  VnlVectorType Transform(const VnlVectorType & v) const;
251 
253  MatrixType GetMatrix(void) const;
254 
256  Self SquareRoot(void) const;
257 
261  Self Exponential(ValueType exponent) const;
262 
263 private:
266 
269 
272 
275 };
276 
277 template< class T >
278 ITK_EXPORT std::ostream & operator<<(std::ostream & os,
279  const Versor< T > & v)
280 {
281  os << "[ ";
282  os << v.GetX() << ", " << v.GetY() << ", ";
283  os << v.GetZ() << ", " << v.GetW() << " ]";
284  return os;
285 }
286 
287 template< class T >
288 ITK_EXPORT std::istream & operator>>(std::istream & is,
289  Versor< T > & v);
290 } // end namespace itk
291 
292 #ifndef ITK_MANUAL_INSTANTIATION
293 #include "itkVersor.hxx"
294 #endif
295 
296 #endif
297