DGtal  0.9.3beta
geometry/tools/determinant/exampleInHalfPlane.cpp

Example of geometric predicates.

See also
Implementation of geometric predicates
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/geometry/tools/determinant/Simple2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/SimpleIncremental2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
#include "DGtal/geometry/tools/determinant/Filtered2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/InHalfPlaneBy2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/PredicateFromOrientationFunctor2.h"
#include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
using namespace std;
using namespace DGtal;
bool
basicUsage()
{
//domain definition
typedef SpaceND< 2, DGtal::int16_t > DigitalSpace;
typedef Domain::Point Point;
Domain domain( Point(-32767,-32767), Point(32767,32767) );
Point P, Q, R;
P = Point(0,0);
Q = Point(5,2);
R = Point(2,1);
//problem: are P, Q, R counter-clockwise oriented ?
//orientation functor
OrientationFunctor orientationFunctor;
//geometric predicate
pointPredicate( orientationFunctor );
//initialization
pointPredicate.init( P, Q );
//which is equivalent to
//orientationFunctor.init( P, Q );
//because the predicate stores a pointer to the functor
bool isCCW;
//decision
isCCW = pointPredicate( R );
//which is equivalent to the following shortcut:
//isCCW = pointPredicate( P, Q, R );
return isCCW;
}
void
advice()
{
{
//for coordinates of 30 (not zero) bits
Functor *a = new Functor();
BOOST_VERIFY(a);
}
{
//for coordinates of 52 (not zero) bits
typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
Functor *a = new Functor();
BOOST_VERIFY(a);
//NB. using double as coordinate type is slightly faster than using DGtal::int64_t
//typedef PointVector<2, double> Point;
}
{
//for coordinates of 62 (not zero) bits
Functor *a= new Functor();
BOOST_VERIFY( a);
}
{
//for coordinates of 62 (not zero) bits
//if long double is implemented as the 80-bit extended precision type
typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
Functor *a = new Functor();
BOOST_VERIFY(a == a);
}
#ifdef WITH_BIGINTEGER
{
//for arbitrary coordinates
Functor *a= new Functor();
BOOST_VERIFY( a);
}
#endif
}
int main( int argc, char** argv )
{
trace.beginBlock ( "Example exampleInHalfPlane" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
basicUsage();
advice();
return 0;
}
// //