DGtal 1.3.0
Loading...
Searching...
No Matches
testImplicitDigitalSurface-benchmark.cpp
1
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/graph/BreadthFirstVisitor.h"
37#include "DGtal/shapes/Shapes.h"
39
40using namespace std;
41using namespace DGtal;
42
44// Functions for testing class ImplicitDigitalSurface.
46namespace DGtal {
47 template <typename KSpace, typename PointPredicate>
48 bool
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 ... ImplicitDigitalSurface" );
59 trace.beginBlock ( "ImplicitDigitalSurface instanciation" );
60 Boundary boundary( K, pp,
62 true );
64 trace.beginBlock ( "Counting the number of surfels (breadth first traversal)" );
65 unsigned int nbsurfels = 0;
66 for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
67 it != it_end; ++it )
68 {
69 ++nbsurfels;
70 }
71 trace.info() << nbsurfels << " surfels found." << std::endl;
72 nb++; nbok += nbsurfels == 354382 ? 1 : 0;
73 trace.info() << "(" << nbok << "/" << nb << ") "
74 << "nbsurfels == 354382" << std::endl;
77 return nbok == nb;
78 }
79
80
81 template <typename TPoint3>
82 struct ImplicitDigitalEllipse3 {
83 typedef TPoint3 Point;
84 inline
85 ImplicitDigitalEllipse3( double a, double b, double c )
86 : myA( a ), myB( b ), myC( c )
87 {}
88 inline
89 bool operator()( const TPoint3 & p ) const
90 {
91 double x = ( (double) p[ 0 ] / myA );
92 double y = ( (double) p[ 1 ] / myB );
93 double z = ( (double) p[ 2 ] / myC );
94 return ( x*x + y*y + z*z ) <= 1.0;
95 }
96 double myA, myB, myC;
97 };
98}
99
101// Standard services - public :
102
103int main( int , char** )
104{
105 using namespace Z3i;
106 typedef DGtal::ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
107 typedef KSpace::SCell Surfel;
108 bool res;
109 trace.beginBlock ( "Testing class Object" );
110 Point p1( -200, -200, -200 );
111 Point p2( 200, 200, 200 );
112 KSpace K;
113 if ( K.init( p1, p2, true ) )
114 {
115 ImplicitDigitalEllipse ellipse( 180.0, 135.0, 102.0 );
116 Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
117 res =
118 testImplicitDigitalSurface<KSpace, ImplicitDigitalEllipse>
119 ( K, ellipse, bel );
120 }
121 else
122 res = false;
123 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
124 trace.endBlock();
125 return res ? 0 : 1;
126}
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
bool testImplicitDigitalSurface()