DGtal  0.9.3
testBinomialConvolver.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/kernel/PointVector.h"
34 #include "DGtal/geometry/curves/BinomialConvolver.h"
35 #include "DGtal/geometry/curves/estimation/CCurveLocalGeometricEstimator.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 
42 // Functions for testing class Signal.
44 
49 {
50  unsigned int nbok = 0;
51  unsigned int nb = 0;
52 
53  trace.beginBlock ( "Testing block ..." );
54  typedef PointVector<2, double> RealPoint;
55  std::vector< RealPoint > points;
56  points.push_back( RealPoint( { 0.0, 0.0 } ) );
57  points.push_back( RealPoint( { 1.0, 0.0 } ) );
58  points.push_back( RealPoint( { 2.0, 0.0 } ) );
59  points.push_back( RealPoint( { 2.0, 1.0 } ) );
60  points.push_back( RealPoint( { 2.0, 2.0 } ) );
61  points.push_back( RealPoint( { 1.0, 2.0 } ) );
62  points.push_back( RealPoint( { 0.0, 2.0 } ) );
63  points.push_back( RealPoint( { 0.0, 1.0 } ) );
64 
65  typedef std::vector< RealPoint >::const_iterator ConstIteratorOnPoints;
66  typedef BinomialConvolver<ConstIteratorOnPoints, double> MyBinomialConvolver;
67 
68  for ( unsigned int n = 1; n < 10; ++n )
69  {
70  trace.info() << "Binomial convolver n=" << n << std::endl;
71  MyBinomialConvolver bcc( n );
72  bcc.init( 1.0, points.begin(), points.end(), true );
73  for ( unsigned int i = 0; i < 8; ++i )
74  std::cout << i
75  << " " << bcc.x( i ).first
76  << " " << bcc.x( i ).second
77  << " " << bcc.tangent( i ).first
78  << " " << bcc.tangent( i ).second
79  << " " << bcc.curvature( i )
80  << std::endl;
81  }
82  unsigned int n = MyBinomialConvolver::suggestedSize( 1.0, points.begin(), points.end() );
83  trace.info() << "Binomial convolver suggested n="
84  << n
85  << std::endl;
86 
88  TangentBCFct;
90  CurvatureBCFct;
95  BCTangentEstimator tgtEstimator;
96  BCCurvatureEstimator curvEstimator;
97 
98  tgtEstimator.init( 1.0, points.begin(), points.end(), true );
99  curvEstimator.init( 1.0, points.begin(), points.end(), true );
100  for ( ConstIteratorOnPoints it = points.begin(), it_end = points.end();
101  it != it_end; ++it )
102  {
103  std::cout << *it
104  << " " << tgtEstimator.eval( it )
105  << " " << curvEstimator.eval( it )
106  << std::endl;
107  }
108  nbok += true ? 1 : 0;
109  nb++;
110  trace.info() << "(" << nbok << "/" << nb << ") "
111  << "true == true" << std::endl;
112  trace.endBlock();
113 
114  return nbok == nb;
115 }
116 
118 // Standard services - public :
119 
120 int main( int argc, char** argv )
121 {
122  trace.beginBlock ( "Testing class BinomialConvolver" );
123  trace.info() << "Args:";
124  for ( int i = 0; i < argc; ++i )
125  trace.info() << " " << argv[ i ];
126  trace.info() << endl;
127 
128  bool res = testBinomialConvolver(); // && ... other tests
129  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
130  trace.endBlock();
131  return res ? 0 : 1;
132 }
133 // //
Aim: This class is a functor for getting the tangent vector of a binomial convolver.
void beginBlock(const std::string &keyword="")
int main(int argc, char **argv)
Trace trace
Definition: Common.h:137
STL namespace.
double endBlock()
Aim: This class is a functor for getting the curvature of a binomial convolver.
std::ostream & emphase()
Aim: This class represents a 2D contour convolved by some binomial. It computes first and second orde...
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: This concept describes an object that can process a range so as to return one estimated quantity...
std::ostream & info()
bool testBinomialConvolver()
Aim: This class encapsulates a BinomialConvolver and a functor on BinomialConvolver so as to be a mod...