DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lower-integer-convex-hull.cpp
1 
14 
15 
16 #include "DGtal/helpers/StdDefs.h"
17 #include "DGtal/arithmetic/LatticePolytope2D.h"
18 #include "DGtal/io/boards/Board2D.h"
19 #include "DGtal/shapes/Shapes.h"
21 
23 
24 using namespace DGtal;
25 
27 
28 void usage( int, char** argv )
29 {
30  std::cerr << "Usage: " << argv[ 0 ] << " <a> <b> <c>" << std::endl;
31  std::cerr << "\t - Cuts a square by ax+by <= c. Displays everything in files "
32  << "lower-integer-convex-hull*.eps" << std::endl;
33 }
34 
38 int main( int argc, char** argv )
39 {
40  if ( argc < 4 )
41  {
42  usage( argc, argv );
43  return 0;
44  }
45 
47  using namespace Z2i;
48  typedef LatticePolytope2D<Z2> CIP;
50 
52  CIP cip;
53  cip.push_front( Point( -10, -10 ) );
54  cip.push_front( Point( -10, 10 ) );
55  cip.push_front( Point( 10, 10 ) );
56  cip.push_front( Point( 10, -10 ) );
57  Domain domain = cip.boundingBoxDomain();
58  Board2D board;
59  board << domain
60  << CustomStyle( cip.className(),
62  << cip;
63  board.saveEPS( "lower-integer-convex-hull.eps" );
64  board.clear();
66 
67  int a = atoi( argv[ 1 ] );
68  int b = atoi( argv[ 2 ] );
69  int c = atoi( argv[ 3 ] );
70 
72  typedef LatticePolytope2D<Z2>::HalfSpace HalfSpace;
73  HalfSpace hs( Vector( a, b ), c );
74  cip.cut( hs );
75  DigitalSet aSet( domain );
77  board << domain
78  << CustomStyle( aSet.className(),
80  << SetMode( Point().className(), "Grid" )
81  << aSet
82  << CustomStyle( cip.className(),
84  << cip;
85  board.saveEPS( "lower-integer-convex-hull-cut.eps" );
87 
89  std::cout << "Number of vertices = " << cip.size() << std::endl;
90  std::cout << "Area = " << (((double)cip.twiceArea())/2.0) << std::endl;
91  std::cout << "Number of interior points = " << cip.numberInteriorPoints() << std::endl;
92  std::cout << "Number of boundary points = " << cip.numberBoundaryPoints() << std::endl;
94  return 0;
95 }
96