DGtal  1.5.beta
testBallQuadViewer.cpp
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/topology/ImplicitDigitalSurface.h"
36 #include "DGtal/io/viewers/Viewer3D.h"
38 
39 using namespace std;
40 using namespace DGtal;
41 
43 // Functions for testing class BallQuad.
45 
49 template <typename TPoint3>
50 struct ImplicitDigitalBall3 {
51  typedef TPoint3 Point;
52  inline
53  ImplicitDigitalBall3( double r )
54  : myR( r )
55  {}
56  inline
57  bool operator()( const TPoint3 & p ) const
58  {
59  double x = ( (double) p[ 0 ] );
60  double y = ( (double) p[ 1 ] );
61  double z = ( (double) p[ 2 ] );
62  return ( x*x + y*y + z*z -myR*myR) <= 0.0;
63  }
64  double myR;
65 };
66 
67 
68 bool testBallQuad(int argc, char **argv)
69 {
70  unsigned int nbok = 0;
71  unsigned int nb = 0;
72 
73  QApplication application(argc, argv);
74 
75  trace.beginBlock ( "Testing... Ball with quadnormal");
76  using namespace Z3i;
77  typedef ImplicitDigitalBall3<Point> ImplicitDigitalBall;
79  typedef Boundary::SurfelConstIterator ConstIterator;
80  typedef Boundary::Surfel Surfel;
81  Point p1( -100, -100, -100 );
82  Point p2( 100, 100, 100 );
83  KSpace K;
84  nbok += K.init( p1, p2, true ) ? 1 : 0;
85  nb++;
86  trace.info() << "(" << nbok << "/" << nb << ") "
87  << "K.init() is ok" << std::endl;
88  ImplicitDigitalBall ball( 60.0 );
89  Surfel bel = Surfaces<KSpace>::findABel( K, ball, 10000 );
90  Boundary boundary( K, ball,
92  unsigned int nbsurfels = 0;
93 
94  Viewer3D<Space,KSpace> viewer(K);
95  viewer.setWindowTitle("simpleViewer");
96  viewer.show();
97 
98 
99  for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
100  it != it_end; ++it )
101  {
102  ++nbsurfels;
103 
105  *it,
106  viewer.embedKS(*it).getNormalized());
107  }
108 
109  trace.info() << nbsurfels << " surfels found." << std::endl;
110  viewer << Display3D<Space, KSpace>::updateDisplay;
111 
112  bool res = application.exec();
113 
114  return res;
115 }
116 
118 // Standard services - public :
119 
120 int main( int argc, char** argv )
121 {
122  trace.beginBlock ( "Testing class BallQuad" );
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 = testBallQuad(argc,argv); // && ... other tests
129  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
130  trace.endBlock();
131  return res ? 0 : 1;
132 }
133 // //
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.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
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:153
Factory for GPL Display3D:
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
int main(int argc, char **argv)
bool testBallQuad()
MyPointD Point
Definition: testClone2.cpp:383
KSpace K