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 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 }
00216
00217
00218 #ifndef ITK_MANUAL_INSTANTIATION
00219 #include "itkVector.txx"
00220 #endif
00221
00222
00223 #endif