DGtal  1.2.0
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
{
//domain definition
typedef SpaceND< 2, DGtal::int16_t > DigitalSpace;
typedef HyperRectDomain< DigitalSpace > Domain;
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
typedef InHalfPlaneBySimple3x3Matrix<Point, DGtal::int32_t> OrientationFunctor;
OrientationFunctor orientationFunctor;
//geometric predicate
PredicateFromOrientationFunctor2<OrientationFunctor>
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
{
{
//for coordinates of 30 (not zero) bits
typedef PointVector<2, DGtal::int32_t> Point;
typedef InHalfPlaneBySimple3x3Matrix<Point, DGtal::int64_t> Functor;
Functor *a = new Functor();
BOOST_VERIFY(a);
delete a;
}
{
//for coordinates of 52 (not zero) bits
typedef PointVector<2, DGtal::int64_t> Point;
typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
typedef InHalfPlaneBy2x2DetComputer<Point, FDetComputer> Functor;
Functor *a = new Functor();
BOOST_VERIFY(a);
delete 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
typedef PointVector<2, DGtal::int64_t> Point;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InHalfPlaneBy2x2DetComputer<Point, DetComputer> Functor;
Functor *a= new Functor();
BOOST_VERIFY( a);
delete a;
}
{
//for coordinates of 62 (not zero) bits
//if long double is implemented as the 80-bit extended precision type
typedef PointVector<2, DGtal::int64_t> Point;
typedef AvnaimEtAl2x2DetSignComputer<long double> DetComputer;
typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
typedef InHalfPlaneBy2x2DetComputer<Point, FDetComputer> Functor;
Functor *a = new Functor();
BOOST_VERIFY(a == a);
delete a;
}
#ifdef WITH_BIGINTEGER
{
//for arbitrary coordinates
typedef PointVector<2, DGtal::BigInteger> Point;
typedef Simple2x2DetComputer<DGtal::BigInteger> DetComputer;
typedef InHalfPlaneBy2x2DetComputer<Point, DetComputer> Functor;
Functor *a= new Functor();
BOOST_VERIFY( a);
delete 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;
advice();
return 0;
}
// //
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void advice()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
bool basicUsage()
Domain domain
HyperRectDomain< Space > Domain