Orfeo Toolbox  3.16
itkPoint.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkPoint.h,v $
5  Language: C++
6  Date: $Date: 2010-03-24 21:51:55 $
7  Version: $Revision: 1.70 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkPoint_h
18 #define __itkPoint_h
19 
20 #include "itkFixedArray.h"
21 
22 #include "itkNumericTraits.h"
23 #include "itkVector.h"
24 
25 #include <vnl/vnl_vector_ref.h>
26 
27 namespace itk
28 {
44 template<class TCoordRep, unsigned int NPointDimension=3>
45 class Point : public FixedArray< TCoordRep, NPointDimension >
46 {
47 public:
49  typedef Point Self;
51 
54  typedef TCoordRep ValueType;
55  typedef TCoordRep CoordRepType;
56 
57  typedef typename NumericTraits< ValueType >::RealType RealType;
58 
60  itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
61 
64  typedef typename BaseArray::Iterator Iterator;
66 
68  static unsigned int GetPointDimension()
69  { return NPointDimension; }
70 
73 
75  Point() {}
76 
78  template< class TPointValueType >
81 
83  Point& operator= (const Self& r);
84  Point& operator= (const ValueType r[NPointDimension]);
85 
87  bool
88  operator==(const Self &pt) const
89  {
90  bool same=true;
91  for (unsigned int i=0; i < PointDimension && same; i++)
92  { same = ((*this)[i] == pt[i]); }
93  return same;
94  }
95 
97  bool
98  operator!=(const Self &pt) const
99  {
100  bool same=true;
101  for (unsigned int i=0; i < PointDimension && same; i++)
102  { same = ((*this)[i] == pt[i]); }
103  return !same;
104  }
105 
107  const Self& operator+=(const VectorType &vec);
108 
110  const Self& operator-=(const VectorType &vec);
111 
113  VectorType operator-(const Self &pnt) const;
114 
116  Self operator+(const VectorType &vec) const;
117 
119  Self operator-(const VectorType &vec) const;
120 
123 
125  vnl_vector_ref<TCoordRep> GetVnlVector( void );
126 
128  vnl_vector<TCoordRep> GetVnlVector( void ) const;
129 
132  vnl_vector_ref<TCoordRep> Get_vnl_vector( void );
133 
137 
149  void SetToMidPoint( const Self &, const Self & );
150 
177  void SetToBarycentricCombination( const Self & A, const Self & B, double alpha );
178 
194  void SetToBarycentricCombination( const Self & A, const Self & B, const Self & C,
195  double weightA, double weightB );
196 
209  void SetToBarycentricCombination( const Self * P, const double * weights, unsigned int N);
210 
211 
214  template < typename TCoordRepB >
216  {
217  for(unsigned int i=0; i<NPointDimension; i++ )
218  {
219  (*this)[i] = static_cast<TCoordRep>( pa[i] );
220  }
221  }
222 
227  template < typename TCoordRepB >
229  {
230  RealType sum = NumericTraits< RealType >::Zero;
231  for(unsigned int i=0; i<NPointDimension; i++ )
232  {
233  const RealType component = static_cast< RealType >( pa[i] );
234  const RealType difference = static_cast< RealType >( (*this)[i] ) - component;
235  sum += difference * difference;
236  }
237  return sum;
238  }
239 
243  template < typename TCoordRepB >
245  {
246  const double distance = vcl_sqrt(
247  static_cast<double>( this->SquaredEuclideanDistanceTo( pa ) ) );
248  return static_cast<RealType>( distance );
249  }
250 
251 };
252 
253 template< class T, unsigned int NPointDimension >
254 ITK_EXPORT std::ostream& operator<<(std::ostream& os,
255  const Point<T,NPointDimension> & v);
256 
257 template< class T, unsigned int NPointDimension >
258 ITK_EXPORT std::istream& operator>>(std::istream& is,
259  Point<T,NPointDimension> & v);
260 
283 template< class TPointContainer, class TWeightContainer >
285 {
286 public:
288  typedef TPointContainer PointContainerType;
289  typedef typename PointContainerType::Pointer PointContainerPointer;
290  typedef typename PointContainerType::Element PointType;
291  typedef TWeightContainer WeightContainerType;
292 
295 
296  static PointType Evaluate(
297  const PointContainerPointer & points,
298  const WeightContainerType & weights );
299 };
300 
301 } // end namespace itk
302 
303 // Define instantiation macro for this template.
304 #define ITK_TEMPLATE_Point(_, EXPORT, x, y) namespace itk { \
305  _(2(class EXPORT Point< ITK_TEMPLATE_2 x >)) \
306  _(1(EXPORT std::ostream& operator<<(std::ostream&, \
307  const Point< ITK_TEMPLATE_2 x >&))) \
308  _(1(EXPORT std::istream& operator>>(std::istream&, \
309  Point< ITK_TEMPLATE_2 x >&))) \
310  namespace Templates { typedef Point< ITK_TEMPLATE_2 x > Point##y; } \
311  }
312 
313 #if ITK_TEMPLATE_EXPLICIT
314 # include "Templates/itkPoint+-.h"
315 #endif
316 
317 #if ITK_TEMPLATE_TXX
318 # include "itkPoint.txx"
319 #endif
320 
321 #endif

Generated at Sat Feb 2 2013 23:59:39 for Orfeo Toolbox with doxygen 1.8.1.1