00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkPoint_h
00018 #define __itkPoint_h
00019
00020 #include "itkVector.h"
00021 #include "vnl/vnl_vector_ref.h"
00022 #include "itkIndent.h"
00023
00024 namespace itk
00025 {
00041 template<class TCoordRep, unsigned int NPointDimension=3>
00042 class Point : public FixedArray< TCoordRep, NPointDimension >
00043 {
00044 public:
00046 typedef Point Self;
00047 typedef FixedArray<TCoordRep,NPointDimension> Superclass;
00048
00051 typedef TCoordRep ValueType;
00052 typedef TCoordRep CoordRepType;
00053
00054 typedef typename NumericTraits< ValueType >::RealType RealType;
00055
00057 itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
00058
00060 typedef FixedArray<TCoordRep, NPointDimension> BaseArray;
00061 typedef typename BaseArray::Iterator Iterator;
00062 typedef typename BaseArray::ConstIterator ConstIterator;
00063
00065 static unsigned int GetPointDimension()
00066 { return NPointDimension; }
00067
00069 typedef Vector< ValueType, NPointDimension > VectorType;
00070
00072 Point() {}
00073
00075 Point(const Self& r): BaseArray(r) {}
00076 Point(const ValueType r[PointDimension]): BaseArray(r) {}
00077
00079 Point& operator= (const Self& r);
00080 Point& operator= (const ValueType r[NPointDimension]);
00081
00083 bool
00084 operator==(const Self &pt) const
00085 {
00086 bool same=true;
00087 for (unsigned int i=0; i < PointDimension && same; i++)
00088 { same = ((*this)[i] == pt[i]); }
00089 return same;
00090 }
00091
00093 bool
00094 operator!=(const Self &pt) const
00095 {
00096 bool same=true;
00097 for (unsigned int i=0; i < PointDimension && same; i++)
00098 { same = ((*this)[i] == pt[i]); }
00099 return !same;
00100 }
00101
00103 const Self& operator+=(const VectorType &vec);
00104
00106 const Self& operator-=(const VectorType &vec);
00107
00109 VectorType operator-(const Self &pnt) const;
00110
00112 Self operator+(const VectorType &vec) const;
00113
00115 Self operator-(const VectorType &vec) const;
00116
00118 VectorType GetVectorFromOrigin() const;
00119
00121 vnl_vector_ref<TCoordRep> GetVnlVector( void );
00122
00124 vnl_vector<TCoordRep> GetVnlVector( void ) const;
00125
00128 vnl_vector_ref<TCoordRep> Get_vnl_vector( void );
00129
00132 vnl_vector<TCoordRep> Get_vnl_vector( void ) const;
00133
00145 void SetToMidPoint( const Self &, const Self & );
00146
00171 void SetToBarycentricCombination( const Self & A, const Self & B, double alpha );
00172
00188 void SetToBarycentricCombination( const Self & A, const Self & B, const Self & C,
00189 double weightA, double weightB );
00190
00203 void SetToBarycentricCombination( const Self * P, const double * weights, unsigned int N);
00204
00205
00208 template < typename TCoordRepB >
00209 void CastFrom( const Point<TCoordRepB,NPointDimension> & pa )
00210 {
00211 for(unsigned int i=0; i<NPointDimension; i++ )
00212 {
00213 (*this)[i] = static_cast<TCoordRep>( pa[i] );
00214 }
00215 }
00216
00217
00221 template < typename TCoordRepB >
00222 RealType SquaredEuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00223 {
00224 RealType sum = NumericTraits< RealType >::Zero;
00225 for(unsigned int i=0; i<NPointDimension; i++ )
00226 {
00227 const RealType component = static_cast< RealType >( pa[i] );
00228 const ValueType difference = (*this)[i] - component;
00229 sum += difference * difference;
00230 }
00231 return sum;
00232 }
00233
00234
00235
00238 template < typename TCoordRepB >
00239 RealType EuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00240 {
00241 const double distance = sqrt(
00242 static_cast<double>( this->SquaredEuclideanDistanceTo( pa ) ) ) ;
00243 return static_cast<RealType>( distance );
00244 }
00245
00246
00247 };
00248
00249 template< class T, unsigned int NPointDimension >
00250 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
00251 const Point<T,NPointDimension> & v);
00252
00253 template< class T, unsigned int NPointDimension >
00254 ITK_EXPORT std::istream& operator>>(std::istream& is,
00255 Point<T,NPointDimension> & v);
00256
00278 template< class TPointContainer, class TWeightContainer >
00279 ITK_EXPORT class BarycentricCombination
00280 {
00281 public:
00283 typedef TPointContainer PointContainerType;
00284 typedef typename PointContainerType::Pointer PointContainerPointer;
00285 typedef typename PointContainerType::Element PointType;
00286 typedef TWeightContainer WeightContainerType;
00287
00288 BarycentricCombination() {};
00289 ~BarycentricCombination() {};
00290
00291 static PointType Evaluate(
00292 const PointContainerPointer & points,
00293 const WeightContainerType & weights );
00294 };
00295
00296 #ifdef ITK_EXPLICIT_INSTANTIATION
00297 extern template class Point<float ,2>;
00298 extern template class Point<double ,2>;
00299 extern template class Point<float ,3>;
00300 extern template class Point<double ,3>;
00301 #endif
00302
00303 }
00304
00305 #ifndef ITK_MANUAL_INSTANTIATION
00306 #include "itkPoint.txx"
00307 #endif
00308
00309
00310 #endif