00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 Vector(const Self& r): BaseArray(r) {}
00114 Vector(const ValueType r[Dimension]): BaseArray(r) {}
00115
00117 Vector& operator= (const Self& r);
00118 Vector& operator= (const ValueType r[Dimension]);
00119
00121 const Self& operator*=(const ValueType &value);
00122
00124 const Self& operator/=(const ValueType &value);
00125
00127 const Self& operator+=(const Self &vec);
00128
00130 const Self& operator-=(const Self &vec);
00131
00134 Self operator-() const;
00135
00137 Self operator+(const Self &vec) const;
00138
00140 Self operator-(const Self &vec) const;
00141
00144 ValueType operator*(const Self &vec) const;
00145
00148 Self operator*(const ValueType& val) const;
00149
00152 Self operator/(const ValueType& val) const;
00153
00158 bool operator==(const Self& v) const
00159 { return Superclass::operator==(v); }
00160 bool operator!=(const Self& v) const
00161 { return !operator==(v); }
00162
00164 RealValueType GetNorm( void ) const;
00165
00167 RealValueType GetSquaredNorm( void ) const;
00168
00170 static int GetNumberOfComponents(){ return NVectorDimension;}
00171
00173 void Normalize(void);
00174
00175 void SetNthComponent(int c, const ComponentType& v)
00176 { this->operator[](c) = v; }
00177
00180 template < typename TCoordRepB >
00181 void CastFrom( const Vector<TCoordRepB,NVectorDimension> & pa )
00182 {
00183 for(unsigned int i=0; i<NVectorDimension; i++ )
00184 {
00185 (*this)[i] = static_cast<T>( pa[i] );
00186 }
00187 }
00188
00189 };
00190
00191 template< class T, unsigned int NVectorDimension >
00192 ITKCommon_EXPORT std::ostream& operator<<(std::ostream& os,
00193 const Vector<T,NVectorDimension> & v);
00194
00195 template< class T, unsigned int NVectorDimension >
00196 ITKCommon_EXPORT std::istream& operator>>(std::istream& is,
00197 Vector<T,NVectorDimension> & v);
00198
00199 ITKCommon_EXPORT Vector<double,3> CrossProduct( const Vector<double,3> &,
00200 const Vector<double,3> & );
00201
00202 ITKCommon_EXPORT Vector<float,3> CrossProduct( const Vector<float,3> &,
00203 const Vector<float,3> & );
00204
00205 ITKCommon_EXPORT Vector<int,3> CrossProduct( const Vector<int,3> &,
00206 const Vector<int,3> & );
00207
00208 }
00209
00210
00211 #ifndef ITK_MANUAL_INSTANTIATION
00212 #include "itkVector.txx"
00213 #endif
00214
00215
00216 #endif