aimstil  5.0.5
point_tools.h
Go to the documentation of this file.
1 #ifndef POINT_TOOLS_H_
2 #define POINT_TOOLS_H_
3 
6 
7 // includes from TIL
8 #include "til/Accumulator.h"
9 
10 namespace til
11 {
12 
13  template < typename T, std::size_t D, typename TStorage, typename TNewPrecision>
14  struct change_precision< Point<T,D,TStorage> , TNewPrecision>
15  {
17  private: // requirements
19  };
20 
21  template < typename TAccumulationPoint, typename TPointCollection >
22  TAccumulationPoint centroid(const TPointCollection & c)
23  {
25  m.accumulate(c);
26  return m.get();
27  }
28 
29  template < typename T, std::size_t D >
30  T dist2(const Point<T,D> & p1, const Point<T,D> & p2)
31  {
32  return dist2(p1.data(), p2.data());
33  }
34 
37  template < typename TPrecision, typename T, std::size_t D >
38  TPrecision
39  dist2(const Point<T,D> & p1, const Point<T,D> & p2, prec<TPrecision>)
40  {
41  return dist2(p1.data(), p2.data(), prec<TPrecision>());
42  /*
43  TPrecision res(0);
44  // TODO: replace this by a template expression when have time
45  typename Point<T,D>::const_iterator iV1 = v1.begin();
46  typename Point<T,D>::const_iterator iV2 = v2.begin();
47  for (; iV1 != v1.end(); ++iV1, ++iV2)
48  {
49  // NB: I prefer to directly convert into TPrecision in case
50  // the content of vectors is unsigned.
51  res += square(TPrecision(*iV1) - TPrecision(*iV2));
52  }
53  return res;
54  */
55  }
56 
57  /*
58  template < typename TPrecision, typename T, std::size_t D >
59  TPrecision
60  dist2(const Point<T,D> & v1, const Point<T,D> & v2)
61  {
62  TPrecision res(0);
63  // TODO: replace this by a template expression when have time
64  typename Point<T,D>::const_iterator iV1 = v1.begin();
65  typename Point<T,D>::const_iterator iV2 = v2.begin();
66  for (; iV1 != v1.end(); ++iV1, ++iV2)
67  {
68  // NB: I prefer to directly convert into TPrecision in case
69  // the content of vectors is unsigned.
70  res += square(TPrecision(*iV1) - TPrecision(*iV2));
71  }
72  return res;
73  }
74 */
75 
79  // TODO: maybe add this kind of checks in the code?
80  /*
81  template < typename T, std::size_t D >
82  T dist2(const Point<T,D> & v1, const Point<T,D> & v2)
83  {
84  return dist2<T,T,D>(v1,v2);
85  }
86  */
87 
88  template < typename TPrecision, typename T, std::size_t D >
89  TPrecision
90  dist(const Point<T,D> & v1, const Point<T,D> & v2)
91  {
92  return TPrecision(std::sqrt(dist2(v1, v2, prec<double>())));
93  }
94 
95 
96 } // namespace til
97 
98 #endif /*POINT_TOOLS_H_*/
void sqrt(const TImage &in, TImage &out)
Definition: imageArith.h:326
Point< T, D, typename change_precision< TStorage, TNewPrecision >::type > type
Definition: point_tools.h:16
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
TAccumulationPoint centroid(const TPointCollection &c)
Definition: point_tools.h:22
void accumulate(typename boost::call_traits< T >::param_type value)
Accumulate a value.
Definition: Accumulator.h:104
A class to accumulate values and return their mean.
Definition: Accumulator.h:139
TPrec dist(const numeric_array< T1, D > &v1, const numeric_array< T2, D > &v2, prec< TPrec >)
Return the Euclidean distance between two arrays.
TAccumulation get()
Get mean of accumulated values.
Definition: Accumulator.h:150
Changing the numerical precision of an object.
Definition: traits.h:106
A dummy class used to pass a precision type for computations to some functions.
TPrec dist2(const numeric_array< T1, D > &v1, const numeric_array< T2, D > &v2, prec< TPrec >)
Return the squared Euclidean distance between two vectors, computed with a precision given as the fir...