DGtal  0.9.4beta
testLightImplicitDigitalSurface-benchmark.cpp
1 
30 #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/graph/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  {
54  typedef typename Boundary::SurfelConstIterator ConstIterator;
55 
56  unsigned int nbok = 0;
57  unsigned int nb = 0;
58  trace.beginBlock ( "Testing block ... LightImplicitDigitalSurface" );
59  trace.beginBlock ( "LightImplicitDigitalSurface instanciation" );
60  Boundary boundary( K, pp,
62  trace.endBlock();
63  trace.beginBlock ( "Counting the number of surfels (breadth first traversal)" );
64  unsigned int nbsurfels = 0;
65  for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
66  it != it_end; ++it )
67  {
68  ++nbsurfels;
69  }
70  trace.info() << nbsurfels << " surfels found." << std::endl;
71  nb++, nbok += nbsurfels == 354382 ? 1 : 0;
72  trace.info() << "(" << nbok << "/" << nb << ") "
73  << "nbsurfels == 354382" << std::endl;
74  trace.endBlock();
75  trace.endBlock();
76  return nbok == nb;
77  }
78 
79 
80  template <typename TPoint3>
81  struct ImplicitDigitalEllipse3 {
82  typedef TPoint3 Point;
83  inline
84  ImplicitDigitalEllipse3( double a, double b, double c )
85  : myA( a ), myB( b ), myC( c )
86  {}
87  inline
88  bool operator()( const TPoint3 & p ) const
89  {
90  double x = ( (double) p[ 0 ] / myA );
91  double y = ( (double) p[ 1 ] / myB );
92  double z = ( (double) p[ 2 ] / myC );
93  return ( x*x + y*y + z*z ) <= 1.0;
94  }
95  double myA, myB, myC;
96  };
97 }
98 
100 // Standard services - public :
101 
102 int main( int, char** )
103 {
104  using namespace Z3i;
105  typedef DGtal::ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
106  typedef KSpace::SCell Surfel;
107  bool res;
108  trace.beginBlock ( "Testing class Object" );
109  Point p1( -200, -200, -200 );
110  Point p2( 200, 200, 200 );
111  KSpace K;
112  if ( K.init( p1, p2, true ) )
113  {
114  ImplicitDigitalEllipse ellipse( 180.0, 135.0, 102.0 );
115  Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
116  res = testLightImplicitDigitalSurface<KSpace, ImplicitDigitalEllipse>
117  ( K, ellipse, bel );
118  }
119  else
120  res = false;
121  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
122  trace.endBlock();
123  return res ? 0 : 1;
124 }
void beginBlock(const std::string &keyword="")
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Trace trace
Definition: Common.h:137
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
double endBlock()
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()