DGtal  1.5.beta
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)
38 #define CompareLocalEstimators_RECURSES
39 
40 #if !defined CompareLocalEstimators_h
42 #define CompareLocalEstimators_h
43 
45 // Inclusions
46 #include <cmath>
47 #include <iostream>
48 #include "DGtal/base/Common.h"
49 #include "DGtal/math/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 
76  typedef typename FirstEstimator::Quantity Quantity;
77 
81 
83 
84  // ----------------------- Interface --------------------------------------
85  public:
86 
101  static
102  Quantity compare(FirstEstimator & aFirstEstimator,
103  SecondEstimator & aSecondEstimator,
104  const ConstIterator &it,
105  const double h = 1.)
106  {
107  ASSERT( aFirstEstimator.isValid() );
108  ASSERT( aSecondEstimator.isValid( ));
109 
110  return aFirstEstimator.eval(it, h) - aSecondEstimator.eval(it, h);
111  }
112 
113 
130  static
132  compare(FirstEstimator & aFirstEstimator,
133  SecondEstimator & aSecondEstimator,
134  const ConstIterator & itb,
135  const ConstIterator & ite,
136  const double h = 1.,
137  const bool storeSamples = false)
138  {
139  OutputStatistic stats(storeSamples);
140 
141  for(ConstIterator it = itb; it!= ite; ++it)
142  stats.addValue(compare(aFirstEstimator, aSecondEstimator, it, h));
143 
144  stats.terminate();
145  return stats;
146  }
147 
148 
164  static
165  double
166  compareVectors(FirstEstimator & aFirstEstimator,
167  SecondEstimator & aSecondEstimator,
168  const ConstIterator &it,
169  const double h = 1.)
170  {
171  ASSERT( aFirstEstimator.isValid());
172  ASSERT( aSecondEstimator.isValid());
173  Quantity v1 = aFirstEstimator.eval(it, h), v2 = aSecondEstimator.eval(it, h);
174 
175  ASSERT( v1.norm() != 0.0 );
176  ASSERT( v2.norm() != 0.0 );
177  double ndot = (double) v1.dot(v2)
178  / ( (double) ( v1.norm() * v2.norm() ) );
179  return ( ndot > 1.0 ) ? 0.0
180  : ( ndot < -1.0 ) ? M_PI : acos( ndot );
181  }
182 
183 
200  static
202  compareVectors(FirstEstimator & aFirstEstimator,
203  SecondEstimator & aSecondEstimator,
204  const ConstIterator & itb,
205  const ConstIterator & ite,
206  const double h,
207  const bool storeSamples = false)
208  {
209  OutputVectorStatistic stats(storeSamples);
210 
211  for(ConstIterator it = itb; it!= ite; ++it)
212  stats.addValue(compareVectors(aFirstEstimator, aSecondEstimator, it, h));
213 
214  stats.terminate();
215  return stats;
216  }
217 
218  // ------------------------- Hidden services ------------------------------
219  private:
220 
227 
235 
236 
237  }; // end of class CompareLocalEstimators
238 
239 } // namespace DGtal
240 
241 
243 
244 #endif // !defined CompareLocalEstimators_h
245 
246 #undef CompareLocalEstimators_RECURSES
247 #endif // else defined(CompareLocalEstimators_RECURSES)
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition: Statistic.h:70
void addValue(Quantity v)
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Functor to compare two local geometric estimators.
static OutputStatistic compare(FirstEstimator &aFirstEstimator, SecondEstimator &aSecondEstimator, const ConstIterator &itb, const ConstIterator &ite, const double h=1., const bool storeSamples=false)
static OutputVectorStatistic compareVectors(FirstEstimator &aFirstEstimator, SecondEstimator &aSecondEstimator, const ConstIterator &itb, const ConstIterator &ite, const double h, const bool storeSamples=false)
Statistic< double > OutputVectorStatistic
static double compareVectors(FirstEstimator &aFirstEstimator, SecondEstimator &aSecondEstimator, const ConstIterator &it, const double h=1.)
Statistic< Quantity > OutputStatistic
Output statistic type.
FirstEstimator::Quantity Quantity
CompareLocalEstimators & operator=(const CompareLocalEstimators &other)
static Quantity compare(FirstEstimator &aFirstEstimator, SecondEstimator &aSecondEstimator, const ConstIterator &it, const double h=1.)
CompareLocalEstimators(const CompareLocalEstimators &other)
FirstEstimator::ConstIterator ConstIterator