This example shows the recognition of a simple digital plane with the COBA algorithm (class COBANaivePlaneComputer). 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/io/viewers/PolyscopeViewer.h"
#include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
template <typename Viewer3D, typename Domain, typename Predicate>
void
{
for (
typename Domain::ConstIterator itB =
domain.begin(), itE =
domain.end();
itB != itE; ++itB )
{
if ( pred( *itB ) )
viewer << *itB;
}
}
int main(
int argc,
char** argv )
{
trace.beginBlock (
"Testing class COBANaivePlaneComputer" );
unsigned int nbok = 0;
unsigned int nb = 0;
typedef PlaneComputer::Primitive Primitive;
PlaneComputer plane;
plane.
init( 2, 100, 1, 1 );
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();
trace.info() <<
"strip=" << strip
<< " 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;
PolyscopeViewer viewer;
Color green( 0, 255, 0 );
Color grey( 200, 200, 200 );
viewer << grey;
viewer << ( pt0_inside ? green : red ) << pt0;
viewer << ( pt1_inside ? green : red ) << pt1;
viewer << ( pt2_inside ? green : red ) << pt2;
viewer << ( pt3_inside ? green : red ) << pt3;
viewer << ( pt4_inside ? green : red ) << pt4;
viewer << ( pt5_inside ? green : red ) << pt5;
viewer << ( pt6_inside ? green : red ) << pt6;
viewer << grey;
return 0;
}
Aim: A class that contains the COBA algorithm (Emilie Charrier, Lilian Buzer, DGCI2008) for recognizi...
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
Structure representing an RGB triple with alpha component.
void show() override
Starts the event loop and display of elements.
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
HyperRectDomain< Space > Domain
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)