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: 2003/09/10 14:29:28 $
00007   Version:   $Revision: 1.59 $
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 "vnl/vnl_vector_ref.h"
00022 #include "itkIndent.h"
00023 
00024 namespace itk
00025 {
00026 
00055 template<class T, unsigned int NVectorDimension=3>
00056 class Vector : public FixedArray<T,NVectorDimension>
00057 {
00058 public:
00060   typedef Vector  Self;
00061   typedef FixedArray<T,NVectorDimension>  Superclass;
00062   
00065   typedef T ValueType;
00066 
00068   itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
00069 
00071   typedef Self VectorType;
00072 
00074   typedef T ComponentType;
00075 
00077   typedef FixedArray<T, NVectorDimension>                BaseArray;
00078     
00080   static unsigned int GetVectorDimension() 
00081     { return NVectorDimension; }  
00082 
00084   void Set_vnl_vector( const vnl_vector<T> & );
00085 
00087   vnl_vector_ref<T> Get_vnl_vector( void );
00088 
00090   vnl_vector<T> Get_vnl_vector( void ) const;
00091 
00093   Vector(): BaseArray() { }
00094   Vector(const ValueType& r);
00095   
00097   Vector(const Self& r): BaseArray(r) {}
00098   Vector(const ValueType r[Dimension]): BaseArray(r) {}  
00099     
00101   Vector& operator= (const Self& r);
00102   Vector& operator= (const ValueType r[Dimension]);
00103     
00105   const Self& operator*=(const ValueType &value);
00106 
00108   const Self& operator/=(const ValueType &value);
00109 
00111   const Self& operator+=(const Self &vec);
00112 
00114   const Self& operator-=(const Self &vec);
00115 
00118   Self operator-() const;
00119 
00121   Self operator+(const Self &vec) const;
00122 
00124   Self operator-(const Self &vec) const;
00125 
00128   ValueType operator*(const Self &vec) const;
00129 
00132   Self operator*(const ValueType& val) const;
00133 
00136   Self operator/(const ValueType& val) const;
00137 
00142   bool operator==(const Self& v) const
00143     { return Superclass::operator==(v); }
00144   bool operator!=(const Self& v) const
00145     { return !operator==(v); }
00146    
00148   ValueType GetNorm( void ) const;
00149 
00151   ValueType GetSquaredNorm( void ) const; 
00152 
00154   static int GetNumberOfComponents(){ return NVectorDimension;}
00155   
00157   void Normalize(void);
00158 
00159   void SetNthComponent(int c, const ComponentType& v)  
00160     {  this->operator[](c) = v; }
00161   
00164   template < typename TCoordRepB >
00165   void CastFrom( const Vector<TCoordRepB,NVectorDimension> & pa )
00166   {
00167     for(unsigned int i=0; i<NVectorDimension; i++ )
00168       {
00169       (*this)[i] = static_cast<T>( pa[i] );
00170       }
00171   }
00172 
00173 };
00174 
00175 template< class T, unsigned int NVectorDimension >  
00176 ITKCommon_EXPORT std::ostream& operator<<(std::ostream& os, 
00177                                     const Vector<T,NVectorDimension> & v); 
00178 
00179 template< class T, unsigned int NVectorDimension >  
00180 ITKCommon_EXPORT std::istream& operator>>(std::istream& is, 
00181                                     Vector<T,NVectorDimension> & v); 
00182 
00183 ITKCommon_EXPORT Vector<double,3> CrossProduct( const Vector<double,3> &,
00184                                           const Vector<double,3> &  );
00185 
00186 ITKCommon_EXPORT Vector<float,3> CrossProduct( const Vector<float,3> &,
00187                                          const Vector<float,3> &  );
00188 
00189 ITKCommon_EXPORT Vector<int,3> CrossProduct( const Vector<int,3> &,
00190                                        const Vector<int,3> &  );
00191 
00192 } // end namespace itk
00193   
00194 
00195 #ifndef ITK_MANUAL_INSTANTIATION
00196 #include "itkVector.txx"
00197 #endif
00198 
00199 
00200 #endif 

Generated at Sun Jan 25 13:19:47 2004 for ITK by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-2000