DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testImplicitDigitalSurface-benchmark.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/topology/DigitalSurface.h"
34 #include "DGtal/topology/DigitalSetBoundary.h"
35 #include "DGtal/topology/ImplicitDigitalSurface.h"
36 #include "DGtal/topology/BreadthFirstVisitor.h"
37 #include "DGtal/shapes/Shapes.h"
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 // Functions for testing class ImplicitDigitalSurface.
46 namespace DGtal {
47  template <typename KSpace, typename PointPredicate>
48  bool
49  testImplicitDigitalSurface( const KSpace & K,
50  const PointPredicate & pp,
51  const typename KSpace::Surfel & bel )
52  {
53  typedef typename KSpace::Point Point;
54  typedef typename KSpace::Surfel Surfel;
56  typedef typename Boundary::SurfelConstIterator ConstIterator;
57  typedef typename Boundary::Tracker Tracker;
58 
59  unsigned int nbok = 0;
60  unsigned int nb = 0;
61  trace.beginBlock ( "Testing block ... ImplicitDigitalSurface" );
62  trace.beginBlock ( "ImplicitDigitalSurface instanciation" );
63  Boundary boundary( K, pp,
65  true );
66  trace.endBlock();
67  trace.beginBlock ( "Counting the number of surfels (breadth first traversal)" );
68  unsigned int nbsurfels = 0;
69  for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
70  it != it_end; ++it )
71  {
72  ++nbsurfels;
73  }
74  trace.info() << nbsurfels << " surfels found." << std::endl;
75  nb++, nbok += nbsurfels == 354382 ? 1 : 0;
76  trace.info() << "(" << nbok << "/" << nb << ") "
77  << "nbsurfels == 354382" << std::endl;
78  trace.endBlock();
79  trace.endBlock();
80  return nbok == nb;
81  }
82 
83 
84  template <typename TPoint3>
86  typedef TPoint3 Point;
87  inline
88  ImplicitDigitalEllipse3( double a, double b, double c )
89  : myA( a ), myB( b ), myC( c )
90  {}
91  inline
92  bool operator()( const TPoint3 & p ) const
93  {
94  double x = ( (double) p[ 0 ] / myA );
95  double y = ( (double) p[ 1 ] / myB );
96  double z = ( (double) p[ 2 ] / myC );
97  return ( x*x + y*y + z*z ) <= 1.0;
98  }
99  double myA, myB, myC;
100  };
101 }
102 
104 // Standard services - public :
105 
106 int main( int , char** )
107 {
108  using namespace Z3i;
109  typedef DGtal::ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
110  typedef KSpace::SCell Surfel;
111  bool res;
112  trace.beginBlock ( "Testing class Object" );
113  Point p1( -200, -200, -200 );
114  Point p2( 200, 200, 200 );
115  KSpace K;
116  if ( K.init( p1, p2, true ) )
117  {
118  ImplicitDigitalEllipse ellipse( 180.0, 135.0, 102.0 );
119  Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
120  res =
121  testImplicitDigitalSurface<KSpace, ImplicitDigitalEllipse>
122  ( K, ellipse, bel );
123  }
124  else
125  res = false;
126  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
127  trace.endBlock();
128  return res ? 0 : 1;
129 }