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

itkVector.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVector.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/08/08 21:36:18 $
00007   Version:   $Revision: 1.69 $
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 __itkVector_h
00018 #define __itkVector_h
00019 
00020 #include "itkFixedArray.h"
00021 #include "itkNumericTraits.h"
00022 #include "vnl/vnl_vector_ref.h"
00023 #include "itkIndent.h"
00024 
00025 
00026 namespace itk
00027 {
00028 
00057 template<class T, unsigned int NVectorDimension=3>
00058 class Vector : public FixedArray<T,NVectorDimension>
00059 {
00060 public:
00062   typedef Vector  Self;
00063   typedef FixedArray<T,NVectorDimension>  Superclass;
00064 
00067   typedef T ValueType;
00068   typedef typename NumericTraits< ValueType >::RealType   RealValueType;
00069 
00071   itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
00072 
00074   typedef Self VectorType;
00075 
00077   typedef T ComponentType;
00078 
00080   typedef FixedArray<T, NVectorDimension>                BaseArray;
00081     
00083   static unsigned int GetVectorDimension() 
00084     { return NVectorDimension; }  
00085 
00087   void SetVnlVector( const vnl_vector<T> & );
00088 
00090   vnl_vector_ref<T> GetVnlVector( void );
00091 
00093   vnl_vector<T> GetVnlVector( void ) const;
00094 
00095 
00098   void Set_vnl_vector( const vnl_vector<T> & );
00099 
00102   vnl_vector_ref<T> Get_vnl_vector( void );
00103 
00106   vnl_vector<T> Get_vnl_vector( void ) const;
00107 
00109   Vector(): BaseArray() { }
00110   Vector(const ValueType& r);
00111   
00113   template< class TVectorValueType >
00114   Vector(const Vector< TVectorValueType, NVectorDimension>& r): BaseArray(r) {}
00115   Vector(const ValueType r[Dimension]): BaseArray(r) {}  
00116     
00118   template< class TVectorValueType >
00119   Vector& operator= (const Vector< TVectorValueType, NVectorDimension> & r)
00120     {
00121     BaseArray::operator=(r);
00122     return *this;
00123     }
00124  
00125   Vector& operator= (const ValueType r[NVectorDimension]);
00126     
00128   const Self& operator*=(const ValueType &value);
00129 
00131   const Self& operator/=(const ValueType &value);
00132 
00134   const Self& operator+=(const Self &vec);
00135 
00137   const Self& operator-=(const Self &vec);
00138 
00141   Self operator-() const;
00142 
00144   Self operator+(const Self &vec) const;
00145 
00147   Self operator-(const Self &vec) const;
00148 
00151   ValueType operator*(const Self &vec) const;
00152 
00155   Self operator*(const ValueType& val) const;
00156 
00159   Self operator/(const ValueType& val) const;
00160 
00165   bool operator==(const Self& v) const
00166     { return Superclass::operator==(v); }
00167   bool operator!=(const Self& v) const
00168     { return !operator==(v); }
00169    
00171   RealValueType GetNorm( void ) const;
00172 
00174   RealValueType GetSquaredNorm( void ) const; 
00175 
00177   static unsigned int GetNumberOfComponents(){ return NVectorDimension;}
00178   
00180   void Normalize(void);
00181 
00182   void SetNthComponent(int c, const ComponentType& v)  
00183     {  this->operator[](c) = v; }
00184   
00187   template < typename TCoordRepB >
00188   void CastFrom( const Vector<TCoordRepB,NVectorDimension> & pa )
00189   {
00190     for(unsigned int i=0; i<NVectorDimension; i++ )
00191       {
00192       (*this)[i] = static_cast<T>( pa[i] );
00193       }
00194   }
00195 
00196 };
00197 
00198 template< class T, unsigned int NVectorDimension >  
00199 std::ostream& operator<<(std::ostream& os, 
00200                                     const Vector<T,NVectorDimension> & v); 
00201 
00202 template< class T, unsigned int NVectorDimension >  
00203 std::istream& operator>>(std::istream& is, 
00204                                     Vector<T,NVectorDimension> & v); 
00205 
00206 ITKCommon_EXPORT Vector<double,3> CrossProduct( const Vector<double,3> &,
00207                                           const Vector<double,3> &  );
00208 
00209 ITKCommon_EXPORT Vector<float,3> CrossProduct( const Vector<float,3> &,
00210                                          const Vector<float,3> &  );
00211 
00212 ITKCommon_EXPORT Vector<int,3> CrossProduct( const Vector<int,3> &,
00213                                        const Vector<int,3> &  );
00214 
00215 } // end namespace itk
00216   
00217 
00218 #ifndef ITK_MANUAL_INSTANTIATION
00219 #include "itkVector.txx"
00220 #endif
00221 
00222 
00223 #endif 

Generated at Thu May 25 00:11:07 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000