DGtal  0.9.2
lower-integer-convex-hull.cpp
1 
14 #include "DGtal/base/Common.h"
17 #include "DGtal/arithmetic/LatticePolytope2D.h"
18 #include "DGtal/io/boards/Board2D.h"
19 #include "DGtal/shapes/Shapes.h"
20 #include "DGtal/helpers/StdDefs.h"
22 
24 
25 using namespace DGtal;
26 
28 
29 void usage( int, char** argv )
30 {
31  std::cerr << "Usage: " << argv[ 0 ] << " <a> <b> <c>" << std::endl;
32  std::cerr << "\t - Cuts a square by ax+by <= c. Displays everything in files "
33  << "lower-integer-convex-hull*.eps" << std::endl;
34 }
35 
39 int main( int argc, char** argv )
40 {
41  if ( argc < 4 )
42  {
43  usage( argc, argv );
44  return 0;
45  }
46 
48  using namespace Z2i;
49  typedef LatticePolytope2D<Space> CIP;
51 
53  CIP cip;
54  cip.push_front( Point( -10, -10 ) );
55  cip.push_front( Point( -10, 10 ) );
56  cip.push_front( Point( 10, 10 ) );
57  cip.push_front( Point( 10, -10 ) );
58  Domain domain = cip.boundingBoxDomain();
59  Board2D board;
60  board << domain
61  << CustomStyle( cip.className(),
63  << cip;
64  board.saveEPS( "lower-integer-convex-hull.eps" );
65  board.clear();
67 
68  int a = atoi( argv[ 1 ] );
69  int b = atoi( argv[ 2 ] );
70  int c = atoi( argv[ 3 ] );
71 
73  typedef LatticePolytope2D<Z2>::HalfSpace HalfSpace;
74  HalfSpace hs( Vector( a, b ), c );
75  cip.cut( hs );
76  DigitalSet aSet( domain );
78  board << domain
79  << CustomStyle( aSet.className(),
81  << SetMode( Point().className(), "Grid" )
82  << aSet
83  << CustomStyle( cip.className(),
85  << cip;
86  board.saveEPS( "lower-integer-convex-hull-cut.eps" );
88 
90  std::cout << "Number of vertices = " << cip.size() << std::endl;
91  std::cout << "Area = " << (((double)cip.twiceArea())/2.0) << std::endl;
92  std::cout << "Number of interior points = " << cip.numberInteriorPoints() << std::endl;
93  std::cout << "Number of boundary points = " << cip.numberBoundaryPoints() << std::endl;
95  return 0;
96 }
97 
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition: StdDefs.h:100
void push_front(const Point &K)
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
static const Color None
Definition: Color.h:387
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
Space::Point Point
Definition: StdDefs.h:95
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A half-space specified by a vector N and a constant c. The half-space is the set ...
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
static const Color Red
Definition: Color.h:391
static const Color Green
Definition: Color.h:392
Space::Vector Vector
Definition: StdDefs.h:96
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane...
static void makeSetFromPointPredicate(DigitalSet &aSet, const PointPredicate &aPP)
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70
std::string className() const