44#include "DGtal/base/Common.h"
45#include "DGtal/base/IteratorCirculatorTraits.h"
46#include "DGtal/helpers/StdDefs.h"
49#include "DGtal/geometry/tools/Hull2DHelpers.h"
51#include "DGtal/geometry/tools/PolarPointComparatorBy2x2DetComputer.h"
52#include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
53#include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
55#include "DGtal/shapes/ShapeFactory.h"
56#include "DGtal/shapes/Shapes.h"
58#include "DGtal/topology/DigitalSetBoundary.h"
59#include "DGtal/topology/DigitalSurface.h"
60#include "DGtal/graph/DepthFirstVisitor.h"
62#include "DGtal/io/boards/Board2D.h"
78template <
typename ForwardIterator,
typename Board>
79void drawPolygon(
const ForwardIterator& itb,
const ForwardIterator& ite,
80 Board& aBoard,
bool isClosed =
true)
86 ForwardIterator it = itb;
92 aBoard <<
SetMode( p.className(),
"Grid" )
98 for (++it; it != ite; ++it, prev = p)
105 aBoard.drawArrow(prev[0], prev[1], p[0], p[1]);
112 aBoard.drawArrow(prev[0], prev[1], p1[0], p1[1]);
131 using namespace functions::Hull2D;
140 vector<Z2i::Point> res;
144 StrictPredicate predicate( functor );
150 andrewConvexHullAlgorithm( pointSet.
begin(), pointSet.
end(), back_inserter( res ), predicate );
157 Z2i::Point antipodalP, antipodalQ, antipodalS;
162 trace.
info() <<
" ConvexHull HV thickness: " << th << std::endl;
168 board.
drawCircle( antipodalS[0], antipodalS[1], 0.2) ;
170 board.
drawCircle(antipodalP[0], antipodalP[1], 0.2);
171 board.
drawCircle(antipodalQ[0], antipodalQ[1], 0.2);
172 board.
drawLine(antipodalP[0], antipodalP[1], antipodalQ[0], antipodalQ[1]);
175 board.
saveSVG(
"ConvexHullCCW.svg" );
177 board.
saveCairo(
"ConvexHullCCW.png", Board2D::CairoPNG);
182 vector<Z2i::Point> res;
186 LargePredicate predicate( functor );
192 andrewConvexHullAlgorithm( pointSet.
begin(), pointSet.
end(), back_inserter( res ), predicate );
197 board.
saveSVG(
"ConvexHullCCWWithPointsOnEdges.svg" );
199 board.
saveCairo(
"ConvexHullCCWWithPointsOnEdges.png", Board2D::CairoPNG);
205 vector<Z2i::Point> res;
209 StrictPredicate predicate( functor );
215 andrewConvexHullAlgorithm( pointSet.
begin(), pointSet.
end(), back_inserter( res ), predicate );
220 board.
saveSVG(
"ConvexHullCW.svg" );
222 board.
saveCairo(
"ConvexHullCW.png", Board2D::CairoPNG);
227 vector<Z2i::Point> res;
231 StrictPredicate predicate( functor );
234 grahamConvexHullAlgorithm( pointSet.
begin(), pointSet.
end(), back_inserter( res ), predicate );
240 board.
saveSVG(
"ConvexHullCCWbis.svg" );
242 board.
saveCairo(
"ConvexHullCCWbis.png", Board2D::CairoPNG);
247 vector<Z2i::Point> polygonalLine;
258 vector<Z2i::Point> resGraham, res;
261 StrictPredicate predicate( functor );
262 closedGrahamScanFromAnyPoint( polygonalLine.begin(), polygonalLine.end(), back_inserter( resGraham ), predicate );
266 for (std::vector<Z2i::Point>::const_iterator
267 it = polygonalLine.begin(),
268 itEnd = polygonalLine.end();
274 melkmanConvexHullAlgorithm( polygonalLine.begin(), polygonalLine.end(), back_inserter( res ), functor );
279 drawPolygon( polygonalLine.begin(), polygonalLine.end(), board,
true );
280 board.
saveSVG(
"SimplePolygonalLine.svg" );
282 board.
saveCairo(
"SimplePolygonalLine.png", Board2D::CairoPNG);
285 drawPolygon( resGraham.begin(), resGraham.end(), board );
286 board.
saveSVG(
"SimplePolygonalLineGraham.svg" );
288 board.
saveCairo(
"SimplePolygonalLineGraham.png", Board2D::CairoPNG);
292 board.
saveSVG(
"SimplePolygonalLineMelkman.svg" );
294 board.
saveCairo(
"SimplePolygonalLineMelkman.png", Board2D::CairoPNG);
298 board.
saveSVG(
"SimplePolygonalLineMelkman2.svg" );
300 board.
saveCairo(
"SimplePolygonalLineMelkman2.png", Board2D::CairoPNG);
305 vector<Z2i::Point> res;
306 std::copy( pointSet.
begin(), pointSet.
end(), back_inserter( res ) );
308 std::sort( res.begin(), res.end() );
312 drawPolygon( res.begin(), res.end(), board,
false );
313 board.
saveSVG(
"AndrewWEVP.svg" );
315 board.
saveCairo(
"AndrewWEVP.png", Board2D::CairoPNG);
320 vector<Z2i::Point> res;
321 std::copy( pointSet.
begin(), pointSet.
end(), back_inserter( res ) );
327 std::vector<Z2i::Point>::iterator itMax
328 = std::max_element( res.begin(), res.end() );
333 std::sort( res.begin(), res.end(), comparator );
337 drawPolygon( res.begin(), res.end(), board,
false );
338 board.
saveSVG(
"GrahamWEVP.svg" );
340 board.
saveCairo(
"GrahamWEVP.png", Board2D::CairoPNG);
354int main(
int argc,
char** argv )
358 for (
int i = 0; i < argc; ++i )
Aim: Model of the concept StarShaped represents any circle in the plane.
RealPoint getUpperBound() const
RealPoint getLowerBound() const
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
ConstIterator end() const
ConstIterator begin() const
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: This class implements the on-line algorithm of Melkman for the computation of the convex hull of...
Aim: Small adapter to models of COrientationFunctor2. It is a model of concepts::CPointPredicate....
static void euclideanShaper(TDigitalSet &aSet, const TShapeFunctor &aFunctor, const double h=1.0)
void beginBlock(const std::string &keyword="")
Aim: Class that implements a binary point predicate, which is able to compare the position of two giv...
void setPole(const Point &aPole)
Board & setPenColor(const DGtal::Color &color)
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
void clear(const DGtal::Color &color=DGtal::Color::None)
void drawCircle(double x, double y, double radius, int depthValue=-1)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
void drawPolygon(const ForwardIterator &itb, const ForwardIterator &ite, Board &aBoard, bool isClosed=true)
double computeHullThickness(const ForwardIterator &itb, const ForwardIterator &ite, const ThicknessDefinition &def)
Procedure to compute the convex hull thickness given from different definitions (Horizontal/vertical ...
@ HorizontalVerticalThickness
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Go to http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/ForwardTraversal.html.
Go to http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/ReadableIterator.html.
DGtal::MelkmanConvexHull< Point, Functor > ch
InHalfPlaneBySimple3x3Matrix< Point, double > Functor