DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CompareLocalEstimators.h
1 
17 #pragma once
18 
34 #if defined(CompareLocalEstimators_RECURSES)
35 #error Recursive header files inclusion detected in CompareLocalEstimators.h
36 #else // defined(CompareLocalEstimators_RECURSES)
37 
38 #define CompareLocalEstimators_RECURSES
39 
40 #if !defined CompareLocalEstimators_h
41 
42 #define CompareLocalEstimators_h
43 
45 // Inclusions
46 #include <cmath>
47 #include <iostream>
48 #include "DGtal/base/Common.h"
49 #include "DGtal/base/Statistic.h"
50 
52 namespace DGtal
53 {
55  // template class CompareLocalEstimators
65  template <typename TFirstEsimator, typename TSecondEstimator>
67  {
68 
69  // ----------------------- Types ------------------------------
70  public:
71 
72  typedef TFirstEsimator FirstEstimator;
73  typedef TSecondEstimator SecondEstimator;
74 
75  typedef typename FirstEstimator::ConstIterator ConstIterator;
76  typedef typename FirstEstimator::Quantity Quantity;
77 
81 
83 
84  // ----------------------- Interface --------------------------------------
85  public:
86 
100  static
101  Quantity compare(FirstEstimator & aFirstEstimator,
102  SecondEstimator & aSecondEstimator,
103  const ConstIterator &it)
104  {
105  ASSERT( aFirstEstimator.isValid());
106  ASSERT( aSecondEstimator.isValid());
107 
108  return aFirstEstimator.eval(it) - aSecondEstimator.eval(it);
109  }
110 
111 
127  static
129  compare(FirstEstimator & aFirstEstimator,
130  SecondEstimator & aSecondEstimator,
131  const ConstIterator & itb,
132  const ConstIterator & ite,
133  const bool storeSamples = false)
134  {
135  OutputStatistic stats(storeSamples);
136 
137  for(ConstIterator it = itb; it!= ite; ++it)
138  stats.addValue( compare(aFirstEstimator,aSecondEstimator,it));
139 
140  stats.terminate();
141  return stats;
142  }
143 
144 
159  static
160  double
161  compareVectors(FirstEstimator & aFirstEstimator,
162  SecondEstimator & aSecondEstimator,
163  const ConstIterator &it)
164  {
165  ASSERT( aFirstEstimator.isValid());
166  ASSERT( aSecondEstimator.isValid());
167  Quantity v1 = aFirstEstimator.eval(it), v2 = aSecondEstimator.eval(it);
168 
169  ASSERT( v1.norm() != 0.0 );
170  ASSERT( v2.norm() != 0.0 );
171  double ndot = (double) v1.dot(v2)
172  / ( (double) ( v1.norm() * v2.norm() ) );
173  return ( ndot > 1.0 ) ? 0.0
174  : ( ndot < -1.0 ) ? M_PI : acos( ndot );
175 
176  }
177 
178 
194  static
196  compareVectors(FirstEstimator & aFirstEstimator,
197  SecondEstimator & aSecondEstimator,
198  const ConstIterator & itb,
199  const ConstIterator & ite,
200  const bool storeSamples = false)
201  {
202  OutputVectorStatistic stats(storeSamples);
203 
204  for(ConstIterator it = itb; it!= ite; ++it)
205  stats.addValue( compareVectors(aFirstEstimator,aSecondEstimator,it));
206 
207  stats.terminate();
208  return stats;
209  }
210 
211  // ------------------------- Hidden services ------------------------------
212  private:
213 
220 
228 
229 
230  }; // end of class CompareLocalEstimators
231 
232 } // namespace DGtal
233 
234 
236 
237 #endif // !defined CompareLocalEstimators_h
238 
239 #undef CompareLocalEstimators_RECURSES
240 #endif // else defined(CompareLocalEstimators_RECURSES)