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: 2006-04-20 14:54:10 $
00007   Version:   $Revision: 1.65 $
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   Point(const Self& r): BaseArray(r) {}
00079   Point(const ValueType r[PointDimension]): BaseArray(r) {}  
00081 
00083   Point& operator= (const Self& r);
00084   Point& operator= (const ValueType r[NPointDimension]);
00086 
00088   bool
00089   operator==(const Self &pt) const
00090     {
00091     bool same=true;
00092     for (unsigned int i=0; i < PointDimension && same; i++)
00093       { same = ((*this)[i] == pt[i]); }
00094     return same;
00095     }
00097 
00099   bool
00100   operator!=(const Self &pt) const
00101     {
00102     bool same=true;
00103     for (unsigned int i=0; i < PointDimension && same; i++)
00104       { same = ((*this)[i] == pt[i]); }
00105     return !same;
00106     }
00108 
00110   const Self& operator+=(const VectorType &vec);
00111 
00113   const Self& operator-=(const VectorType &vec);
00114 
00116   VectorType operator-(const Self &pnt) const;
00117 
00119   Self operator+(const VectorType &vec) const;
00120 
00122   Self operator-(const VectorType &vec) const;
00123 
00125   VectorType GetVectorFromOrigin() const;
00126 
00128   vnl_vector_ref<TCoordRep> GetVnlVector( void );
00129 
00131   vnl_vector<TCoordRep> GetVnlVector( void ) const;
00132 
00135   vnl_vector_ref<TCoordRep> Get_vnl_vector( void );
00136 
00139   vnl_vector<TCoordRep> Get_vnl_vector( void ) const;
00140 
00152   void SetToMidPoint( const Self &, const Self &  );
00153 
00178   void SetToBarycentricCombination( const Self & A, const Self & B, double alpha   );
00180 
00196   void SetToBarycentricCombination( const Self & A, const Self & B, const Self & C, 
00197                                     double weightA,  double weightB );
00199 
00212   void SetToBarycentricCombination( const Self * P, const double * weights, unsigned int N);
00214 
00215 
00218   template < typename TCoordRepB >
00219   void CastFrom( const Point<TCoordRepB,NPointDimension> & pa )
00220   {
00221     for(unsigned int i=0; i<NPointDimension; i++ )
00222       {
00223       (*this)[i] = static_cast<TCoordRep>( pa[i] );
00224       }
00225   }
00227 
00228 
00232   template < typename TCoordRepB >
00233   RealType SquaredEuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00234   {
00235     RealType sum = NumericTraits< RealType >::Zero;
00236     for(unsigned int i=0; i<NPointDimension; i++ )
00237       {
00238       const RealType component =  static_cast< RealType >( pa[i] );
00239       const ValueType difference = (*this)[i] - component;
00240       sum += difference * difference;
00241       }
00242   return sum;
00243   }
00244 
00245 
00246 
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 
00261 template< class T, unsigned int NPointDimension >  
00262 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00263                                     const Point<T,NPointDimension> & v); 
00264 
00265 template< class T, unsigned int NPointDimension >  
00266 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00267                                     Point<T,NPointDimension> & v); 
00268 
00290 template< class TPointContainer, class TWeightContainer >
00291 ITK_EXPORT class BarycentricCombination  
00292 {
00293 public:
00294 
00296   typedef TPointContainer PointContainerType;
00297   typedef typename PointContainerType::Pointer PointContainerPointer;
00298   typedef typename PointContainerType::Element PointType;
00299   typedef TWeightContainer WeightContainerType;
00300 
00301   BarycentricCombination() {}; 
00302   ~BarycentricCombination() {};
00303 
00304   static PointType Evaluate( 
00305     const PointContainerPointer & points, 
00306     const WeightContainerType & weights );
00307 };
00308 
00309 }  // end namespace itk
00310 
00311 // Define instantiation macro for this template.
00312 #define ITK_TEMPLATE_Point(_, EXPORT, x, y) namespace itk { \
00313   _(2(class EXPORT Point< ITK_TEMPLATE_2 x >)) \
00314   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00315                                       const Point< ITK_TEMPLATE_2 x >&))) \
00316   _(1(EXPORT std::istream& operator>>(std::istream&, \
00317                                       Point< ITK_TEMPLATE_2 x >&))) \
00318   namespace Templates { typedef Point< ITK_TEMPLATE_2 x > Point##y; } \
00319   }
00320 
00321 #if ITK_TEMPLATE_EXPLICIT
00322 # include "Templates/itkPoint+-.h"
00323 #endif
00324 
00325 #if ITK_TEMPLATE_TXX
00326 # include "itkPoint.txx"
00327 #endif
00328 
00329 #endif 
00330 

Generated at Mon Apr 14 13:59:12 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000