DGtal  1.3.beta
testBallQuad.cpp
Go to the documentation of this file.
1 
30 #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/boards/Board3D.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 
69 {
70  unsigned int nbok = 0;
71  unsigned int nb = 0;
72 
73  trace.beginBlock ( "Testing... Ball with quadnormal");
74  using namespace Z3i;
75  typedef ImplicitDigitalBall3<Point> ImplicitDigitalBall;
77  typedef Boundary::SurfelConstIterator ConstIterator;
78  typedef Boundary::Surfel Surfel;
79  Point p1( -50, -50, -50 );
80  Point p2( 50, 50, 50 );
81  KSpace K;
82  nbok += K.init( p1, p2, true ) ? 1 : 0;
83  nb++;
84  trace.info() << "(" << nbok << "/" << nb << ") "
85  << "K.init() is ok" << std::endl;
86  ImplicitDigitalBall ball( 30.0 );
87  Surfel bel = Surfaces<KSpace>::findABel( K, ball, 10000 );
88  Boundary boundary( K, ball,
90  unsigned int nbsurfels = 0;
91 
92  Board3D<Space,KSpace> board(K);
93 
94  for ( ConstIterator it = boundary.begin(), it_end = boundary.end();
95  it != it_end; ++it )
96  {
97  ++nbsurfels;
98 
100  *it,
101  board.embedKS(*it).getNormalized());
102  }
103 
104  trace.info() << nbsurfels << " surfels found." << std::endl;
105 
106  board.saveOBJ("testball.obj");
107 
108 
109  nbok += true ? 1 : 0;
110  nb++;
111  trace.info() << "(" << nbok << "/" << nb << ") "
112  << "true == true" << std::endl;
113  trace.endBlock();
114 
115  return nbok == nb;
116 }
117 
119 // Standard services - public :
120 
121 int main( int argc, char** argv )
122 {
123  trace.beginBlock ( "Testing class BallQuad" );
124  trace.info() << "Args:";
125  for ( int i = 0; i < argc; ++i )
126  trace.info() << " " << argv[ i ];
127  trace.info() << endl;
128 
129  bool res = testBallQuad(); // && ... other tests
130  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
131  trace.endBlock();
132  return res ? 0 : 1;
133 }
134 // //
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::Trace::endBlock
double endBlock()
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::Display3D< Z3i::Space, Z3i::KSpace >::embedKS
RealPoint embedKS(const typename Z3i::KSpace ::SCell &cell) const
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::ImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition: ImplicitDigitalSurface.h:71
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Board3D
The class Board3D is a type of Display3D which export the figures in the format OBJ/MTL when calling ...
Definition: Board3D.h:81
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::Trace::info
std::ostream & info()
Surfel
KSpace::SCell Surfel
Definition: testArithmeticalDSSComputerOnSurfels.cpp:50
DGtal::Board3D::saveOBJ
void saveOBJ(const std::string &filename, const bool isNormalized=false)
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
main
int main(int argc, char **argv)
Definition: testBallQuad.cpp:121
testBallQuad
bool testBallQuad()
Definition: testBallQuad.cpp:68
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::Display3DFactory
Factory for GPL Display3D:
Definition: Display3DFactory.h:86
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64