Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkCovariantVector.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkCovariantVector.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/02/08 20:42:48 $
00007   Version:   $Revision: 1.52 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkCovariantVector_h
00018 #define __itkCovariantVector_h
00019 
00020 
00021 #include "itkFixedArray.h"
00022 #include "vnl/vnl_vector_ref.h"
00023 #include "itkIndent.h"
00024 #include "itkVector.h"
00025 
00026 
00027 namespace itk
00028 {
00029 
00063 template<class T, unsigned int NVectorDimension=3>
00064 class ITK_EXPORT CovariantVector : public FixedArray<T,NVectorDimension>
00065 {
00066 
00067 public:
00069   typedef CovariantVector                 Self;
00070   typedef FixedArray<T,NVectorDimension>  Superclass;
00071 
00074   typedef T                                              ValueType;
00075   typedef typename NumericTraits< ValueType >::RealType  RealValueType;
00076 
00078   itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
00079 
00081   typedef Self CovariantVectorType;
00082 
00084   typedef FixedArray<T, NVectorDimension>                BaseArray;
00085 
00087   static unsigned int GetCovariantVectorDimension() 
00088     { return NVectorDimension; }  
00089 
00091   void SetVnlVector( const vnl_vector<T> & );
00092 
00094   vnl_vector_ref<T> GetVnlVector( void );
00095 
00097   vnl_vector<T> GetVnlVector( void ) const;
00098 
00099 
00102   void Set_vnl_vector( const vnl_vector<T> & );
00103 
00106   vnl_vector_ref<T> Get_vnl_vector( void );
00107 
00110   vnl_vector<T> Get_vnl_vector( void ) const;
00111 
00112 
00114   CovariantVector(): BaseArray() {}
00115   CovariantVector(const ValueType& r);
00116 
00118   CovariantVector(const Self& r): BaseArray(r) {}
00119   CovariantVector(const ValueType r[Dimension]): BaseArray(r) {}  
00121 
00123   template< class Tt >
00124   Self & operator= (const Tt & v )
00125     {
00126     BaseArray::operator=(v);
00127     return *this;
00128     }
00130 
00132   CovariantVector& operator= (const Self& r);
00133   CovariantVector& operator= (const ValueType r[NVectorDimension]);
00135 
00137   template< class Tt > inline const Self& operator*=(const Tt &value)
00138     {
00139     for( unsigned int i=0; i<NVectorDimension; i++)
00140       {
00141       (*this)[i] = static_cast< ValueType >((*this)[i] * value);
00142       }
00143     return *this;
00144     }
00146 
00148   template< class Tt > const Self& operator/=(const Tt &value)
00149     {
00150     for( unsigned int i=0; i<NVectorDimension; i++)
00151       {
00152       (*this)[i] = static_cast< ValueType >((*this)[i] / value);
00153       }
00154     return *this;
00155     }
00157 
00159   const Self& operator+=(const Self &vec);
00160 
00162   const Self& operator-=(const Self &vec);
00163 
00166   Self operator-() const;
00167 
00169   Self operator+(const Self &vec) const;
00170 
00172   Self operator-(const Self &vec) const;
00173 
00178   ValueType operator*(const Self &vec) const;
00179 
00182   ValueType operator*(const Vector<T,NVectorDimension> &vec) const;
00183 
00186   inline Self operator*(const ValueType& val) const
00187     {
00188     Self result;
00189     for( unsigned int i=0; i<NVectorDimension; i++) 
00190       {
00191       result[i] = static_cast< ValueType >((*this)[i] * val);
00192       }
00193     return result;
00194     }
00196 
00199   template< class Tt > inline Self operator/(const Tt& val) const
00200     {
00201     Self result;
00202     for( unsigned int i=0; i<NVectorDimension; i++) 
00203       {
00204       result[i] = static_cast< ValueType >((*this)[i] / val);
00205       }
00206     return result;
00207     }
00209 
00211   RealValueType GetNorm( void ) const;
00212 
00214   static unsigned int GetNumberOfComponents() { return NVectorDimension; }
00215 
00217   void Normalize(void);
00218 
00220   RealValueType GetSquaredNorm( void ) const;
00221 
00224   template < typename TCoordRepB >
00225   void CastFrom( const CovariantVector<TCoordRepB,NVectorDimension> & pa )
00226     {
00227     for(unsigned int i=0; i<NVectorDimension; i++ )
00228       {
00229       (*this)[i] = static_cast<T>( pa[i] );
00230       }
00231     }
00233 
00234 };
00235 
00238 template< class T, unsigned int NVectorDimension >
00239 inline
00240 CovariantVector<T,NVectorDimension>
00241 operator*(const T &scalar, const  CovariantVector<T,NVectorDimension> & v)
00242 {
00243   return v * scalar;
00244 }
00245 
00246 ITKCommon_EXPORT void CrossProduct(  CovariantVector<double,3> &,
00247                                      const Vector<double,3> &,
00248                                      const Vector<double,3> &  );
00249 
00250 ITKCommon_EXPORT void CrossProduct(  CovariantVector<float,3> &,
00251                                      const Vector<float,3> &,
00252                                      const Vector<float,3> &  );
00253 
00254 ITKCommon_EXPORT void CrossProduct(  CovariantVector<int,3>,
00255                                      const Vector<int,3> &,
00256                                      const Vector<int,3> &  );
00257 
00258 
00259 } // end namespace itk
00260 
00261 // Define instantiation macro for this template.
00262 #define ITK_TEMPLATE_CovariantVector(_, EXPORT, x, y) namespace itk { \
00263   _(2(class EXPORT CovariantVector< ITK_TEMPLATE_2 x >)) \
00264   namespace Templates { typedef CovariantVector< ITK_TEMPLATE_2 x > \
00265                         CovariantVector##y; } \
00266   }
00267 
00268 #if ITK_TEMPLATE_EXPLICIT
00269 # include "Templates/itkCovariantVector+-.h"
00270 #endif
00271 
00272 #if ITK_TEMPLATE_TXX
00273 #include "itkNumericTraitsCovariantVectorPixel.h"
00274 # include "itkCovariantVector.txx"
00275 #endif
00276 
00277 #endif 
00278 

Generated at Wed Nov 5 21:00:22 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000