This example shows how to create a LatticePolytope2D that represents a square. Then given integer parameters a, b, c, it cuts the polygon by the half-plane \( ax+by \le c \). It also outputs some statistics.
#include "DGtal/base/Common.h"
#include "DGtal/arithmetic/LatticePolytope2D.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
void usage( int, char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <a> <b> <c>" << std::endl;
std::cerr << "\t - Cuts a square by ax+by <= c. Displays everything in files "
<< "lower-integer-convex-hull*.eps" << std::endl;
}
int main(
int argc,
char** argv )
{
if ( argc < 4 )
{
usage( argc, argv );
return 0;
}
using namespace Z2i;
CIP cip;
cip.push_front(
Point( -10, 10 ) );
cip.push_front(
Point( 10, 10 ) );
cip.push_front(
Point( 10, -10 ) );
<< cip;
board.
saveEPS(
"lower-integer-convex-hull.eps" );
int a = atoi( argv[ 1 ] );
int b = atoi( argv[ 2 ] );
int c = atoi( argv[ 3 ] );
HalfSpace hs(
Vector( a, b ), c );
cip.cut( hs );
<< aSet
<< cip;
board.
saveEPS(
"lower-integer-convex-hull-cut.eps" );
std::cout << "Number of vertices = " << cip.size() << std::endl;
std::cout << "Area = " << (((double)cip.twiceArea())/2.0) << std::endl;
std::cout << "Number of interior points = " << cip.numberInteriorPoints() << std::endl;
std::cout << "Number of boundary points = " << cip.numberBoundaryPoints() << std::endl;
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane....
void push_front(const Point &K)
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
DigitalPlane::Point Vector
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 .
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet