Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkPoint.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkPoint.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-03-03 15:07:54 $
00007   Version:   $Revision: 1.68 $
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 __itkPoint_h
00018 #define __itkPoint_h
00019 
00020 #include "itkFixedArray.h"
00021 
00022 #include "itkNumericTraits.h"
00023 #include "itkVector.h"
00024 
00025 #include <vnl/vnl_vector_ref.h>
00026 
00027 namespace itk
00028 {
00044 template<class TCoordRep, unsigned int NPointDimension=3>
00045 class Point : public FixedArray< TCoordRep, NPointDimension >
00046 {
00047 public:
00049   typedef Point                                  Self;
00050   typedef FixedArray<TCoordRep,NPointDimension>  Superclass;
00051 
00054   typedef TCoordRep ValueType;
00055   typedef TCoordRep CoordRepType;
00056 
00057   typedef typename NumericTraits< ValueType >::RealType      RealType;
00058   
00060   itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
00061 
00063   typedef FixedArray<TCoordRep, NPointDimension>    BaseArray;
00064   typedef typename BaseArray::Iterator              Iterator;
00065   typedef typename BaseArray::ConstIterator         ConstIterator;
00066 
00068   static unsigned int GetPointDimension() 
00069     { return NPointDimension; }
00070 
00072   typedef Vector< ValueType, NPointDimension >   VectorType;
00073 
00075   Point() {}
00076 
00078   template< class TPointValueType >
00079   Point(const Point< TPointValueType, NPointDimension>& r): BaseArray(r) {}
00080   Point(const ValueType r[PointDimension]): BaseArray(r) {}  
00082 
00084   Point& operator= (const Self& r);
00085   Point& operator= (const ValueType r[NPointDimension]);
00087 
00089   bool
00090   operator==(const Self &pt) const
00091     {
00092     bool same=true;
00093     for (unsigned int i=0; i < PointDimension && same; i++)
00094       { same = ((*this)[i] == pt[i]); }
00095     return same;
00096     }
00098 
00100   bool
00101   operator!=(const Self &pt) const
00102     {
00103     bool same=true;
00104     for (unsigned int i=0; i < PointDimension && same; i++)
00105       { same = ((*this)[i] == pt[i]); }
00106     return !same;
00107     }
00109 
00111   const Self& operator+=(const VectorType &vec);
00112 
00114   const Self& operator-=(const VectorType &vec);
00115 
00117   VectorType operator-(const Self &pnt) const;
00118 
00120   Self operator+(const VectorType &vec) const;
00121 
00123   Self operator-(const VectorType &vec) const;
00124 
00126   VectorType GetVectorFromOrigin() const;
00127 
00129   vnl_vector_ref<TCoordRep> GetVnlVector( void );
00130 
00132   vnl_vector<TCoordRep> GetVnlVector( void ) const;
00133 
00136   vnl_vector_ref<TCoordRep> Get_vnl_vector( void );
00137 
00140   vnl_vector<TCoordRep> Get_vnl_vector( void ) const;
00141 
00153   void SetToMidPoint( const Self &, const Self &  );
00154 
00179   void SetToBarycentricCombination( const Self & A, const Self & B, double alpha   );
00181 
00197   void SetToBarycentricCombination( const Self & A, const Self & B, const Self & C, 
00198                                     double weightA,  double weightB );
00200 
00213   void SetToBarycentricCombination( const Self * P, const double * weights, unsigned int N);
00215 
00216 
00219   template < typename TCoordRepB >
00220   void CastFrom( const Point<TCoordRepB,NPointDimension> & pa )
00221     {
00222     for(unsigned int i=0; i<NPointDimension; i++ )
00223       {
00224       (*this)[i] = static_cast<TCoordRep>( pa[i] );
00225       }
00226     }
00228 
00233   template < typename TCoordRepB >
00234   RealType SquaredEuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00235     {
00236     RealType sum = NumericTraits< RealType >::Zero;
00237     for(unsigned int i=0; i<NPointDimension; i++ )
00238       {
00239       const RealType component =  static_cast< RealType >( pa[i] );
00240       const ValueType difference = (*this)[i] - component;
00241       sum += difference * difference;
00242       }
00243     return sum;
00244     }
00245 
00249   template < typename TCoordRepB >
00250   RealType EuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00251     {
00252     const double distance = vcl_sqrt(
00253       static_cast<double>( this->SquaredEuclideanDistanceTo( pa ) ) );
00254     return static_cast<RealType>( distance );
00255     }
00257 
00258 };
00259 
00260 template< class T, unsigned int NPointDimension >  
00261 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00262                                     const Point<T,NPointDimension> & v); 
00263 
00264 template< class T, unsigned int NPointDimension >  
00265 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00266                                     Point<T,NPointDimension> & v); 
00267 
00290 template< class TPointContainer, class TWeightContainer >
00291 ITK_EXPORT class BarycentricCombination  
00292 {
00293 public:
00295   typedef TPointContainer                      PointContainerType;
00296   typedef typename PointContainerType::Pointer PointContainerPointer;
00297   typedef typename PointContainerType::Element PointType;
00298   typedef TWeightContainer                     WeightContainerType;
00299 
00300   BarycentricCombination() {}; 
00301   ~BarycentricCombination() {};
00302 
00303   static PointType Evaluate( 
00304     const PointContainerPointer & points, 
00305     const WeightContainerType & weights );
00306 };
00307 
00308 }  // end namespace itk
00309 
00310 // Define instantiation macro for this template.
00311 #define ITK_TEMPLATE_Point(_, EXPORT, x, y) namespace itk { \
00312   _(2(class EXPORT Point< ITK_TEMPLATE_2 x >)) \
00313   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00314                                       const Point< ITK_TEMPLATE_2 x >&))) \
00315   _(1(EXPORT std::istream& operator>>(std::istream&, \
00316                                       Point< ITK_TEMPLATE_2 x >&))) \
00317   namespace Templates { typedef Point< ITK_TEMPLATE_2 x > Point##y; } \
00318   }
00319 
00320 #if ITK_TEMPLATE_EXPLICIT
00321 # include "Templates/itkPoint+-.h"
00322 #endif
00323 
00324 #if ITK_TEMPLATE_TXX
00325 # include "itkPoint.txx"
00326 #endif
00327 
00328 #endif 
00329 

Generated at Thu May 28 11:09:04 2009 for ITK by doxygen 1.5.5 written by Dimitri van Heesch, © 1997-2000