ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkVersor_h 00019 #define __itkVersor_h 00020 00021 #include "itkMatrix.h" 00022 #include "vnl/vnl_quaternion.h" 00023 #include "vnl/vnl_vector_fixed.h" 00024 00025 namespace itk 00026 { 00049 template< class T > 00050 class Versor 00051 { 00052 public: 00054 typedef Versor Self; 00055 00058 typedef T ValueType; 00059 00061 typedef typename NumericTraits< ValueType >::RealType RealType; 00062 00064 typedef Vector< T, 3 > VectorType; 00065 00067 typedef Point< T, 3 > PointType; 00068 00070 typedef CovariantVector< T, 3 > CovariantVectorType; 00071 00073 typedef vnl_vector_fixed< T, 3 > VnlVectorType; 00074 00076 typedef vnl_quaternion< T > VnlQuaternionType; 00077 00079 typedef Matrix< T, 3, 3 > MatrixType; 00080 00082 vnl_quaternion< T > GetVnlQuaternion(void) const; 00083 00087 void Set(const VnlQuaternionType &); 00088 00106 void Set(T x, T y, T z, T w); 00108 00111 Versor(); 00112 00114 Versor(const Self & v); 00115 00117 const Self & operator=(const Self & v); 00118 00122 const Self & operator*=(const Self & v); 00123 00128 const Self & operator/=(const Self & v); 00129 00133 ValueType GetTensor(void) const; 00134 00139 void Normalize(void); 00140 00143 Self GetConjugate(void) const; 00144 00148 Self GetReciprocal(void) const; 00149 00152 Self operator *(const Self & vec) const; 00153 00155 Self operator/(const Self & vec) const; 00156 00159 bool operator==(const Self & vec) const; 00160 00163 bool operator!=(const Self & vec) const; 00164 00166 ValueType GetScalar(void) const; 00167 00169 ValueType GetX(void) const { return m_X; } 00170 00172 ValueType GetY(void) const { return m_Y; } 00173 00175 ValueType GetZ(void) const { return m_Z; } 00176 00178 ValueType GetW(void) const { return m_W; } 00179 00181 ValueType GetAngle(void) const; 00182 00185 VectorType GetAxis(void) const; 00186 00191 VectorType GetRight(void) const; 00192 00196 void Set(const VectorType & axis, ValueType angle); 00197 00203 void Set(const MatrixType & m); 00204 00210 void Set(const VectorType & axis); 00211 00218 void SetRotationAroundX(ValueType angle); 00219 00226 void SetRotationAroundY(ValueType angle); 00227 00234 void SetRotationAroundZ(ValueType angle); 00235 00238 void SetIdentity(); 00239 00241 VectorType Transform(const VectorType & v) const; 00242 00244 CovariantVectorType Transform(const CovariantVectorType & v) const; 00245 00247 PointType Transform(const PointType & v) const; 00248 00250 VnlVectorType Transform(const VnlVectorType & v) const; 00251 00253 MatrixType GetMatrix(void) const; 00254 00256 Self SquareRoot(void) const; 00257 00261 Self Exponential(ValueType exponent) const; 00262 00263 private: 00265 ValueType m_X; 00266 00268 ValueType m_Y; 00269 00271 ValueType m_Z; 00272 00274 ValueType m_W; 00275 }; 00276 00277 template< class T > 00278 ITK_EXPORT std::ostream & operator<<(std::ostream & os, 00279 const Versor< T > & v) 00280 { 00281 os << "[ "; 00282 os << v.GetX() << ", " << v.GetY() << ", "; 00283 os << v.GetZ() << ", " << v.GetW() << " ]"; 00284 return os; 00285 } 00286 00287 template< class T > 00288 ITK_EXPORT std::istream & operator>>(std::istream & is, 00289 Versor< T > & v); 00290 } // end namespace itk 00291 00292 // Define instantiation macro for this template. 00293 #define ITK_TEMPLATE_Versor(_, EXPORT, TypeX, TypeY) \ 00294 namespace itk \ 00295 { \ 00296 _( 1 ( class EXPORT Versor< ITK_TEMPLATE_1 TypeX > ) ) \ 00297 namespace Templates \ 00298 { \ 00299 typedef Versor< ITK_TEMPLATE_1 TypeX > Versor##TypeY; \ 00300 } \ 00301 } 00302 00303 #if ITK_TEMPLATE_EXPLICIT 00304 #include "Templates/itkVersor+-.h" 00305 #endif 00306 00307 #if ITK_TEMPLATE_TXX 00308 #include "itkVersor.hxx" 00309 #endif 00310 00311 #endif 00312