DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testLightImplicitDigitalSurface-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/LightImplicitDigitalSurface.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 LightImplicitDigitalSurface.
46 namespace DGtal {
47  template <typename KSpace, typename PointPredicate>
48  bool
49  testLightImplicitDigitalSurface( 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 ... LightImplicitDigitalSurface" );
62  trace.beginBlock ( "LightImplicitDigitalSurface instanciation" );
63  Boundary boundary( K, pp,
65  trace.endBlock();
66  trace.beginBlock ( "Counting the number of surfels (breadth first traversal)" );
67  unsigned int nbsurfels = 0;
68  for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
69  it != it_end; ++it )
70  {
71  ++nbsurfels;
72  }
73  trace.info() << nbsurfels << " surfels found." << std::endl;
74  nb++, nbok += nbsurfels == 354382 ? 1 : 0;
75  trace.info() << "(" << nbok << "/" << nb << ") "
76  << "nbsurfels == 354382" << std::endl;
77  trace.endBlock();
78  trace.endBlock();
79  return nbok == nb;
80  }
81 
82 
83  template <typename TPoint3>
85  typedef TPoint3 Point;
86  inline
87  ImplicitDigitalEllipse3( double a, double b, double c )
88  : myA( a ), myB( b ), myC( c )
89  {}
90  inline
91  bool operator()( const TPoint3 & p ) const
92  {
93  double x = ( (double) p[ 0 ] / myA );
94  double y = ( (double) p[ 1 ] / myB );
95  double z = ( (double) p[ 2 ] / myC );
96  return ( x*x + y*y + z*z ) <= 1.0;
97  }
98  double myA, myB, myC;
99  };
100 }
101 
103 // Standard services - public :
104 
105 int main( int, char** )
106 {
107  using namespace Z3i;
108  typedef DGtal::ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
109  typedef KSpace::SCell Surfel;
110  bool res;
111  trace.beginBlock ( "Testing class Object" );
112  Point p1( -200, -200, -200 );
113  Point p2( 200, 200, 200 );
114  KSpace K;
115  if ( K.init( p1, p2, true ) )
116  {
117  ImplicitDigitalEllipse ellipse( 180.0, 135.0, 102.0 );
118  Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
119  res = testLightImplicitDigitalSurface<KSpace, ImplicitDigitalEllipse>
120  ( K, ellipse, bel );
121  }
122  else
123  res = false;
124  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
125  trace.endBlock();
126  return res ? 0 : 1;
127 }