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: 2008-11-14 05:09:25 $
00007   Version:   $Revision: 1.55 $
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 
00113   CovariantVector(): BaseArray() {}
00114   CovariantVector(const ValueType& r);
00115 
00118   template< class TVectorValueType >
00119   CovariantVector(const CovariantVector< TVectorValueType, 
00120                         NVectorDimension>& r): BaseArray(r) {}
00121   CovariantVector(const ValueType r[Dimension]): BaseArray(r) {}  
00123 
00125   template< class Tt >
00126   Self & operator= (const Tt & v )
00127     {
00128     BaseArray::operator=(v);
00129     return *this;
00130     }
00132 
00134   CovariantVector& operator= (const Self& r);
00135   CovariantVector& operator= (const ValueType r[NVectorDimension]);
00137 
00139   template< class Tt > inline const Self& operator*=(const Tt &value)
00140     {
00141     for( unsigned int i=0; i<NVectorDimension; i++)
00142       {
00143       (*this)[i] = static_cast< ValueType >((*this)[i] * value);
00144       }
00145     return *this;
00146     }
00148 
00150   template< class Tt > const Self& operator/=(const Tt &value)
00151     {
00152     for( unsigned int i=0; i<NVectorDimension; i++)
00153       {
00154       (*this)[i] = static_cast< ValueType >((*this)[i] / value);
00155       }
00156     return *this;
00157     }
00159 
00161   const Self& operator+=(const Self &vec);
00162 
00164   const Self& operator-=(const Self &vec);
00165 
00168   Self operator-() const;
00169 
00171   Self operator+(const Self &vec) const;
00172 
00174   Self operator-(const Self &vec) const;
00175 
00180   ValueType operator*(const Self &vec) const;
00181 
00184   ValueType operator*(const Vector<T,NVectorDimension> &vec) const;
00185 
00188   inline Self operator*(const ValueType& val) const
00189     {
00190     Self result;
00191     for( unsigned int i=0; i<NVectorDimension; i++) 
00192       {
00193       result[i] = static_cast< ValueType >((*this)[i] * val);
00194       }
00195     return result;
00196     }
00198 
00201   template< class Tt > inline Self operator/(const Tt& val) const
00202     {
00203     Self result;
00204     for( unsigned int i=0; i<NVectorDimension; i++) 
00205       {
00206       result[i] = static_cast< ValueType >((*this)[i] / val);
00207       }
00208     return result;
00209     }
00211 
00213   RealValueType GetNorm( void ) const;
00214 
00216   static unsigned int GetNumberOfComponents() { return NVectorDimension; }
00217 
00219   void Normalize(void);
00220 
00222   RealValueType GetSquaredNorm( void ) const;
00223 
00226   template < typename TCoordRepB >
00227   void CastFrom( const CovariantVector<TCoordRepB,NVectorDimension> & pa )
00228     {
00229     for(unsigned int i=0; i<NVectorDimension; i++ )
00230       {
00231       (*this)[i] = static_cast<T>( pa[i] );
00232       }
00233     }
00235 
00236 };
00237 
00240 template< class T, unsigned int NVectorDimension >
00241 inline
00242 CovariantVector<T,NVectorDimension>
00243 operator*(const T &scalar, const  CovariantVector<T,NVectorDimension> & v)
00244 {
00245   return v * scalar;
00246 }
00247 
00248 ITKCommon_EXPORT void CrossProduct(  CovariantVector<double,3> &,
00249                                      const Vector<double,3> &,
00250                                      const Vector<double,3> &  );
00251 
00252 ITKCommon_EXPORT void CrossProduct(  CovariantVector<float,3> &,
00253                                      const Vector<float,3> &,
00254                                      const Vector<float,3> &  );
00255 
00256 ITKCommon_EXPORT void CrossProduct(  CovariantVector<int,3>,
00257                                      const Vector<int,3> &,
00258                                      const Vector<int,3> &  );
00259 
00260 
00261 } // end namespace itk
00262 
00263 // Define instantiation macro for this template.
00264 #define ITK_TEMPLATE_CovariantVector(_, EXPORT, x, y) namespace itk { \
00265   _(2(class EXPORT CovariantVector< ITK_TEMPLATE_2 x >)) \
00266   namespace Templates { typedef CovariantVector< ITK_TEMPLATE_2 x > \
00267                         CovariantVector##y; } \
00268   }
00269 
00270 #if ITK_TEMPLATE_EXPLICIT
00271 # include "Templates/itkCovariantVector+-.h"
00272 #endif
00273 
00274 #if ITK_TEMPLATE_TXX
00275 #include "itkNumericTraitsCovariantVectorPixel.h"
00276 # include "itkCovariantVector.txx"
00277 #endif
00278 
00279 #endif 
00280 

Generated at Tue Sep 15 02:42:22 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000