This example shows the recognition of a simple standard digital plane with the Chord algorithm (class ChordGenericStandardPlaneComputer ). 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/geometry/surfaces/ChordGenericStandardPlaneComputer.h"
#include "DGtal/io/viewers/Viewer3D.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;
}
}
template <typename Viewer3D, typename InputIterator>
void
{
for ( ; it != itE; ++it )
viewer << *it;
}
template <typename Domain>
typename Domain::Integer a,
typename Domain::Integer b,
typename Domain::Integer c,
typename Domain::Integer mu )
{
typedef typename Domain::Integer
Integer;
typedef typename Domain::Point
Point;
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 PlaneComputer::Primitive Primitive;
PlaneComputer plane;
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;
MyViewer viewer;
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 ) );
for ( std::vector<Point>::const_iterator it = recognized.begin(),
itE = recognized.end(); it != itE; ++it )
if ( ! strip( *it ) ) viewer << *it;
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();
}
Aim: A class that recognizes pieces of digital planes of given diagonal width. When the width is ,...
void init(InternalScalar widthNumerator=NumberTraits< InternalScalar >::ONE, InternalScalar widthDenominator=NumberTraits< InternalScalar >::ONE)
Structure representing an RGB triple with alpha component.
void beginBlock(const std::string &keyword="")
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Point::Coordinate Integer
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
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)