This example shows the recognition of a simple digital plane with the Chord algorithm (class DGtal::ChordNaivePlaneComputer). Green points belong to the naive plane. There is no naive plane containing the green points and any one of the red points.
#include <cstdlib>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/surfaces/ChordNaivePlaneComputer.h"
#include "DGtal/io/viewers/Viewer3D.h"
using namespace std;
template <typename Viewer3D, typename Domain, typename Predicate>
void
{
itB != itE; ++itB )
{
if ( pred( *itB ) )
viewer << *itB;
}
}
int main(
int argc,
char** argv )
{
using namespace Z3i;
QApplication application(argc,argv);
unsigned int nbok = 0;
unsigned int nb = 0;
typedef PlaneComputer::Primitive Primitive;
PlaneComputer plane;
bool pt0_inside = plane.extend( pt0 );
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") Plane=" << plane
<< std::endl;
bool pt1_inside = plane.extend( pt1 );
++nb; nbok += pt1_inside == true ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt1
<< " Plane=" << plane << std::endl;
bool pt2_inside = plane.extend( pt2 );
++nb; nbok += pt2_inside == true ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt2
<< " Plane=" << plane << std::endl;
bool pt3_inside = plane.extend( pt3 );
++nb; nbok += pt3_inside == false ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt3
<< " Plane=" << plane << std::endl;
bool pt4_inside = plane.extend( pt4 );
++nb; nbok += pt4_inside == false ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt4
<< " Plane=" << plane << std::endl;
bool pt5_inside = plane.extend( pt5 );
++nb; nbok += pt5_inside == true ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt5
<< " Plane=" << plane << std::endl;
bool pt6_inside = plane.extend( pt6 );
++nb; nbok += pt6_inside == true ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt5
<< " Plane=" << plane << std::endl;
Primitive strip = plane.primitive();
<< " axis=" << strip.mainAxis()
<< " axiswidth=" << strip.axisWidth()
<< " diag=" << strip.mainDiagonal()
<< " diagwidth=" << strip.diagonalWidth()
<< std::endl;
++nb; nbok += strip.axisWidth() < 1.0 ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") axiswidth < 1 "
<< std::endl;
++nb; nbok += strip.diagonalWidth() < sqrt(3.0) ? 1 : 0;
trace.
info() <<
"(" << nbok <<
"/" << nb <<
") axiswidth < sqrt(3) "
<< std::endl;
trace.
emphase() << ( nbok == nb ?
"Passed." :
"Error." ) << endl;
Color green( 0, 255, 0 );
Color grey( 200, 200, 200 );
return application.exec();
}