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: 2010-03-24 21:51:55 $
00007   Version:   $Revision: 1.70 $
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 
00181   void SetToBarycentricCombination( const Self & A, const Self & B, double alpha   );
00183 
00199   void SetToBarycentricCombination( const Self & A, const Self & B, const Self & C, 
00200                                     double weightA,  double weightB );
00202 
00215   void SetToBarycentricCombination( const Self * P, const double * weights, unsigned int N);
00217 
00218 
00221   template < typename TCoordRepB >
00222   void CastFrom( const Point<TCoordRepB,NPointDimension> & pa )
00223     {
00224     for(unsigned int i=0; i<NPointDimension; i++ )
00225       {
00226       (*this)[i] = static_cast<TCoordRep>( pa[i] );
00227       }
00228     }
00230 
00235   template < typename TCoordRepB >
00236   RealType SquaredEuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00237     {
00238     RealType sum = NumericTraits< RealType >::Zero;
00239     for(unsigned int i=0; i<NPointDimension; i++ )
00240       {
00241       const RealType component =  static_cast< RealType >( pa[i] );
00242       const RealType difference = static_cast< RealType >( (*this)[i] ) - component;
00243       sum += difference * difference;
00244       }
00245     return sum;
00246     }
00247 
00251   template < typename TCoordRepB >
00252   RealType EuclideanDistanceTo( const Point<TCoordRepB,NPointDimension> & pa ) const
00253     {
00254     const double distance = vcl_sqrt(
00255       static_cast<double>( this->SquaredEuclideanDistanceTo( pa ) ) );
00256     return static_cast<RealType>( distance );
00257     }
00259 
00260 };
00261 
00262 template< class T, unsigned int NPointDimension >  
00263 ITK_EXPORT std::ostream& operator<<(std::ostream& os, 
00264                                     const Point<T,NPointDimension> & v); 
00265 
00266 template< class T, unsigned int NPointDimension >  
00267 ITK_EXPORT std::istream& operator>>(std::istream& is, 
00268                                     Point<T,NPointDimension> & v); 
00269 
00292 template< class TPointContainer, class TWeightContainer >
00293 ITK_EXPORT class BarycentricCombination  
00294 {
00295 public:
00297   typedef TPointContainer                      PointContainerType;
00298   typedef typename PointContainerType::Pointer PointContainerPointer;
00299   typedef typename PointContainerType::Element PointType;
00300   typedef TWeightContainer                     WeightContainerType;
00301 
00302   BarycentricCombination() {}; 
00303   ~BarycentricCombination() {};
00304 
00305   static PointType Evaluate( 
00306     const PointContainerPointer & points, 
00307     const WeightContainerType & weights );
00308 };
00309 
00310 }  // end namespace itk
00311 
00312 // Define instantiation macro for this template.
00313 #define ITK_TEMPLATE_Point(_, EXPORT, x, y) namespace itk { \
00314   _(2(class EXPORT Point< ITK_TEMPLATE_2 x >)) \
00315   _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00316                                       const Point< ITK_TEMPLATE_2 x >&))) \
00317   _(1(EXPORT std::istream& operator>>(std::istream&, \
00318                                       Point< ITK_TEMPLATE_2 x >&))) \
00319   namespace Templates { typedef Point< ITK_TEMPLATE_2 x > Point##y; } \
00320   }
00321 
00322 #if ITK_TEMPLATE_EXPLICIT
00323 # include "Templates/itkPoint+-.h"
00324 #endif
00325 
00326 #if ITK_TEMPLATE_TXX
00327 # include "itkPoint.txx"
00328 #endif
00329 
00330 #endif 
00331 

Generated at Mon Jul 12 2010 19:27:46 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000