DGtal  0.9.2
exampleInHalfPlane.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 
37 #include "DGtal/geometry/tools/determinant/Simple2x2DetComputer.h"
38 #include "DGtal/geometry/tools/determinant/SimpleIncremental2x2DetComputer.h"
39 #include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
40 #include "DGtal/geometry/tools/determinant/Filtered2x2DetComputer.h"
41 #include "DGtal/geometry/tools/determinant/InHalfPlaneBy2x2DetComputer.h"
43 #include "DGtal/geometry/tools/determinant/PredicateFromOrientationFunctor2.h"
44 #include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
47 
48 using namespace std;
49 using namespace DGtal;
50 
52 
53 bool
54 basicUsage()
55 {
57  //domain definition
58  typedef SpaceND< 2, DGtal::int16_t > DigitalSpace;
60  typedef Domain::Point Point;
61  Domain domain( Point(-32767,-32767), Point(32767,32767) );
63 
65  Point P, Q, R;
66  P = Point(0,0);
67  Q = Point(5,2);
68  R = Point(2,1);
69  //problem: are P, Q, R counter-clockwise oriented ?
71 
73  //orientation functor
74  typedef InHalfPlaneBySimple3x3Matrix<Point, DGtal::int32_t> OrientationFunctor;
75  OrientationFunctor orientationFunctor;
77 
79  //geometric predicate
81  pointPredicate( orientationFunctor );
83 
85  //initialization
86  pointPredicate.init( P, Q );
87  //which is equivalent to
88  //orientationFunctor.init( P, Q );
89  //because the predicate stores a pointer to the functor
91 
92  bool isCCW;
94  //decision
95  isCCW = pointPredicate( R );
96  //which is equivalent to the following shortcut:
97  //isCCW = pointPredicate( P, Q, R );
99 
100  return isCCW;
101 }
102 
103 void
104 advice()
105 {
106  {
108  //for coordinates of 30 (not zero) bits
109  typedef PointVector<2, DGtal::int32_t> Point;
112  Functor *a = new Functor();
113  BOOST_VERIFY(a);
114  }
115 
116  {
118  //for coordinates of 52 (not zero) bits
119  typedef PointVector<2, DGtal::int64_t> Point;
120  typedef AvnaimEtAl2x2DetSignComputer<double> DetComputer;
121  typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
124  Functor *a = new Functor();
125  BOOST_VERIFY(a);
126  //NB. using double as coordinate type is slightly faster than using DGtal::int64_t
127  //typedef PointVector<2, double> Point;
128  }
129 
130  {
132  //for coordinates of 62 (not zero) bits
133  typedef PointVector<2, DGtal::int64_t> Point;
137  Functor *a= new Functor();
138  BOOST_VERIFY( a);
139  }
140 
141  {
143  //for coordinates of 62 (not zero) bits
144  //if long double is implemented as the 80-bit extended precision type
145  typedef PointVector<2, DGtal::int64_t> Point;
146  typedef AvnaimEtAl2x2DetSignComputer<long double> DetComputer;
147  typedef Filtered2x2DetComputer<DetComputer> FDetComputer;
149  Functor *a = new Functor();
150  BOOST_VERIFY(a == a);
152  }
153 
154 #ifdef WITH_BIGINTEGER
155  {
157  //for arbitrary coordinates
158  typedef PointVector<2, DGtal::BigInteger> Point;
159  typedef Simple2x2DetComputer<DGtal::BigInteger> DetComputer;
161  Functor *a= new Functor();
162  BOOST_VERIFY( a);
164  }
165 #endif
166 
167 }
168 
169 int main( int argc, char** argv )
170 {
171  trace.beginBlock ( "Example exampleInHalfPlane" );
172  trace.info() << "Args:";
173  for ( int i = 0; i < argc; ++i )
174  trace.info() << " " << argv[ i ];
175  trace.info() << endl;
176 
177  basicUsage();
178  advice();
179 
180  trace.endBlock();
181  return 0;
182 }
183 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
STL namespace.
double endBlock()
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: Small class useful to compute the determinant of a 2x2 matrix from its four coefficients, ie. .
Aim: Small adapter to models of COrientationFunctor2. It is a model of concepts::CPointPredicate. It is also a ternary predicate on points, useful for basic geometric tasks such as convex hull computation.
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...