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: 2006/04/21 00:09:52 $
00007   Version:   $Revision: 1.44 $
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  public:
00068   typedef CovariantVector  Self;
00069   typedef FixedArray<T,NVectorDimension>  Superclass;
00070 
00073   typedef T ValueType;
00074   typedef typename NumericTraits< ValueType >::RealType   RealValueType;
00075 
00077   itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
00078 
00080   typedef Self CovariantVectorType;
00081 
00083   typedef FixedArray<T, NVectorDimension>                BaseArray;
00084 
00086   static unsigned int GetCovariantVectorDimension() 
00087     { return NVectorDimension; }  
00088 
00090   void SetVnlVector( const vnl_vector<T> & );
00091 
00093   vnl_vector_ref<T> GetVnlVector( void );
00094 
00096   vnl_vector<T> GetVnlVector( void ) const;
00097 
00098 
00101   void Set_vnl_vector( const vnl_vector<T> & );
00102 
00105   vnl_vector_ref<T> Get_vnl_vector( void );
00106 
00109   vnl_vector<T> Get_vnl_vector( void ) const;
00110 
00111 
00113   CovariantVector(): BaseArray() {}
00114   CovariantVector(const ValueType& r);
00115 
00117   CovariantVector(const Self& r): BaseArray(r) {}
00118   CovariantVector(const ValueType r[Dimension]): BaseArray(r) {}  
00120 
00122   template< class Tt >
00123   Self & operator= (const Tt & v )
00124     {
00125     BaseArray::operator=(v);
00126     return *this;
00127     }
00129 
00131   CovariantVector& operator= (const Self& r);
00132   CovariantVector& operator= (const ValueType r[NVectorDimension]);
00134 
00136   template< class Tt > inline const Self& operator*=(const Tt &value)
00137     {
00138     for( unsigned int i=0; i<NVectorDimension; i++)
00139       {
00140       (*this)[i] = static_cast< ValueType >((*this)[i] * value);
00141       }
00142     return *this;
00143     }
00145 
00147   template< class Tt > const Self& operator/=(const Tt &value)
00148     {
00149     for( unsigned int i=0; i<NVectorDimension; i++)
00150       {
00151       (*this)[i] = static_cast< ValueType >((*this)[i] / value);
00152       }
00153     return *this;
00154     }
00156 
00158   const Self& operator+=(const Self &vec);
00159 
00161   const Self& operator-=(const Self &vec);
00162 
00164   Self operator-() const;
00165 
00167   Self operator+(const Self &vec) const;
00168 
00170   Self operator-(const Self &vec) const;
00171 
00175   ValueType operator*(const Self &vec) const;
00176 
00179   ValueType operator*(const Vector<T,NVectorDimension> &vec) const;
00180 
00183   inline Self operator*(const ValueType& val) const
00184     {
00185     Self result;
00186     for( unsigned int i=0; i<NVectorDimension; i++) 
00187       {
00188       result[i] = static_cast< ValueType >((*this)[i] * val);
00189       }
00190     return result;
00191     }
00193 
00196   template< class Tt > inline Self operator/(const Tt& val) const
00197     {
00198     Self result;
00199     for( unsigned int i=0; i<NVectorDimension; i++) 
00200       {
00201       result[i] = static_cast< ValueType >((*this)[i] / val);
00202       }
00203     return result;
00204     }
00206 
00208   RealValueType GetNorm( void ) const;
00209 
00211   static unsigned int GetNumberOfComponents() { return NVectorDimension; }
00212 
00214   void Normalize(void);
00215 
00217   RealValueType GetSquaredNorm( void ) const;
00218 
00221   template < typename TCoordRepB >
00222   void CastFrom( const CovariantVector<TCoordRepB,NVectorDimension> & pa )
00223   {
00224     for(unsigned int i=0; i<NVectorDimension; i++ )
00225       {
00226       (*this)[i] = static_cast<T>( pa[i] );
00227       }
00228   }
00230 
00231 };
00232 
00235 template< class T, unsigned int NVectorDimension >
00236 inline
00237 CovariantVector<T,NVectorDimension>
00238 operator*(const T &scalar, const  CovariantVector<T,NVectorDimension> & v)
00239 {
00240   return v * scalar;
00241 }
00242 
00243 ITKCommon_EXPORT void CrossProduct(  CovariantVector<double,3> &,
00244                                      const Vector<double,3> &,
00245                                      const Vector<double,3> &  );
00246 
00247 ITKCommon_EXPORT void CrossProduct(  CovariantVector<float,3> &,
00248                                      const Vector<float,3> &,
00249                                      const Vector<float,3> &  );
00250 
00251 ITKCommon_EXPORT void CrossProduct(  CovariantVector<int,3>,
00252                                      const Vector<int,3> &,
00253                                      const Vector<int,3> &  );
00254 
00255 
00256 } // end namespace itk
00257   
00258 #include "itkNumericTraitsCovariantVectorPixel.h"
00259 
00260 #ifndef ITK_MANUAL_INSTANTIATION
00261 #include "itkCovariantVector.txx"
00262 #endif
00263 
00264 
00265 #endif 
00266 

Generated at Sat Sep 2 20:18:08 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000