This example shows the recognition of a simple standard digital plane with the COBA algorithm (class DGtal::COBAGenericStandardPlaneComputer). Green points belong to the naive plane. Grey points show farther points that also belong to the strip.
#include <cstdlib>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/geometry/surfaces/COBAGenericStandardPlaneComputer.h"
using namespace std;
template <typename Viewer3D, typename Domain, typename Predicate>
void
{
itB != itE; ++itB )
{
if ( pred( *itB ) )
viewer << *itB;
}
}
template <typename Viewer3D, typename InputIterator>
void
displayRange( Viewer3D & viewer, InputIterator it, InputIterator itE )
{
for ( ; it != itE; ++it )
viewer << *it;
}
template <typename Domain>
{
std::vector<Point> pts;
it != itE; ++it )
{
Integer r = a * p[ 0 ] + b * p[ 1 ] + c * p[ 2 ];
if ( ( mu <= r ) && ( r < mup ) )
pts.push_back( p );
}
return pts;
}
int main(
int argc,
char** argv )
{
using namespace Z3i;
unsigned int nb = 0;
unsigned int nbok = 0;
QApplication application(argc,argv);
unsigned int diameter = argc > 1 ? atoi( argv[ 1 ] ) : 10;
int a = argc > 2 ? atoi( argv[ 2 ] ) : 2;
int b = argc > 3 ? atoi( argv[ 3 ] ) : 3;
int c = argc > 4 ? atoi( argv[ 4 ] ) : 5;
int mu = argc > 5 ? atoi( argv[ 5 ] ) : 0;
<< mu << " <= " << a << " * x + "
<< b << " * y + " << c << " * z < "
Domain domain1(
Point( -diameter, -diameter, -diameter ),
Point( diameter, diameter, diameter ) );
typedef COBAGenericStandardPlaneComputer<Z3, BigInteger> PlaneComputer;
typedef PlaneComputer::Primitive Primitive;
PlaneComputer plane;
plane.init( 2*diameter, 1, 1 );
a, b , c, mu );
++nb, nbok += plane.extend( recognized.begin(), recognized.end() ) ? 1 : 0;
<< ") All points are recognized." << std::endl;
<< std::endl;
Primitive strip = plane.primitive();
<< " axis=" << strip.mainAxis()
<< " axiswidth=" << strip.axisWidth()
<< " diag=" << strip.mainDiagonal()
<< " diagwidth=" << strip.diagonalWidth()
<< std::endl;
++nb, nbok += ( strip.diagonalWidth() < sqrt(3.0) ) ? 1 : 0;
<< ") Diagonal width < sqrt(3)." << std::endl;
trace.
emphase() << ( (nb == nbok) ?
"Passed." :
"Error." ) << endl;
typedef Viewer3D<> MyViewer;
MyViewer viewer;
viewer.show();
Color red( 255, 0, 0 );
Color green( 0, 255, 0 );
Color grey( 200, 200, 200 );
Domain domain2(
Point( -2*diameter, -2*diameter, -2*diameter ),
Point( 2*diameter, 2*diameter, 2*diameter ) );
viewer << CustomColors3D( red, red );
for ( std::vector<Point>::const_iterator it = recognized.begin(),
itE = recognized.end(); it != itE; ++it )
if ( ! strip( *it ) ) viewer << *it;
viewer << CustomColors3D( green, green );
viewer << CustomColors3D( grey, grey );
viewer << MyViewer::updateDisplay;
trace.
info() <<
"- Points in green have been recognized as belonging to this standard plane." << std::endl;
trace.
info() <<
"- Points in grey belongs also to the parallel strip of the recognized standard plane." << std::endl;
trace.
info() <<
"- Points in red belongs to the parallel strip of the recognized standard plane but not to the input standard plane: NONE should be red." << std::endl;
return application.exec();
}
void beginBlock(const std::string &keyword="")
Point::Coordinate Integer
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
std::vector< typename Domain::Point > pointsInStandardPlane(const Domain &domain, typename Domain::Integer a, typename Domain::Integer b, typename Domain::Integer c, typename Domain::Integer mu)
void displayRange(const R &r)
HyperRectDomain< Space > Domain
void displayPredicate(Viewer3D &viewer, const Domain &domain, const Predicate &pred)