Computation of the alpha shape of the border of a digital shape.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/base/IteratorCirculatorTraits.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/tools/Hull2DHelpers.h"
#include "DGtal/geometry/tools/PolarPointComparatorBy2x2DetComputer.h"
#include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
#include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
#include "DGtal/geometry/tools/determinant/InGeneralizedDiskOfGivenRadius.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/topology/DigitalSetBoundary.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
template <typename ForwardIterator, typename Board>
void drawPolygon(
const ForwardIterator& itb,
const ForwardIterator& ite,
Board& aBoard, bool isClosed = true)
{
ForwardIterator it = itb;
if (it != ite)
{
aBoard << SetMode( p.className(), "Grid" )
<< CustomStyle( p.className()+"/Grid", new CustomPenColor( Color::Red ) )
<< p
<< CustomStyle( p.className()+"/Grid", new CustomPenColor( Color::Black ) );
for (++it; it != ite; ++it, prev = p)
{
p = *it;
aBoard << p;
if (prev != p)
aBoard.drawArrow(prev[0], prev[1], p[0], p[1]);
}
if (isClosed)
{
if (prev != p1)
aBoard.drawArrow(prev[0], prev[1], p1[0], p1[1]);
}
}
}
{
Shapes<Z2i::Domain>::euclideanShaper(digitalSet, ball);
typedef DigitalSetBoundary<Z2i::KSpace, Z2i::DigitalSet> DigitalSurfaceContainer;
typedef DigitalSurface<DigitalSurfaceContainer> CustomDigitalSurface;
DigitalSurfaceContainer digitalSurfaceContainer( kspace, digitalSet );
CustomDigitalSurface digitalSurface( digitalSurfaceContainer );
Z2i::Curve gridCurve;
typedef DepthFirstVisitor<DigitalSurface<DigitalSurfaceContainer> > CustomVisitor;
CustomVisitor visitor( digitalSurface, *digitalSurface.begin() );
while ( ! visitor.finished() )
{
gridCurve.pushBack( visitor.current().first );
visitor.expand();
}
PointRange pointsRange = gridCurve.getInnerPointsRange();
vector<Z2i::Point> border;
unique_copy( pointsRange.begin(), pointsRange.end(), back_inserter( border ) );
using namespace functions::Hull2D;
{
vector<Z2i::Point> res;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InGeneralizedDiskOfGivenRadius<Z2i::Point, DetComputer>
Functor;
typedef PredicateFromOrientationFunctor2<Functor> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShape0.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShape0.png", Board2D::CairoPNG);
#endif
}
{
vector<Z2i::Point> res;
typedef InHalfPlaneBySimple3x3Matrix<Z2i::Point, DGtal::int64_t>
Functor;
typedef PredicateFromOrientationFunctor2<Functor> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShape0bis.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShape0bis.png", Board2D::CairoPNG);
#endif
}
{
vector<Z2i::Point> res;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InGeneralizedDiskOfGivenRadius<Z2i::Point, DetComputer>
Functor;
typedef PredicateFromOrientationFunctor2<Functor> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShapeM1.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShapeM1.png", Board2D::CairoPNG);
#endif
}
{
trace.
info() <<
" alpha == -sqrt(5) " << endl;
vector<Z2i::Point> res;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InGeneralizedDiskOfGivenRadius<Z2i::Point, DetComputer>
Functor;
typedef PredicateFromOrientationFunctor2<Functor> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShapeMSqrt5.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShapeMSqrt5.png", Board2D::CairoPNG);
#endif
}
{
vector<Z2i::Point> res;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InGeneralizedDiskOfGivenRadius<Z2i::Point, DetComputer>
Functor;
typedef PredicateFromOrientationFunctor2<Functor> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShapeM5.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShapeM5.png", Board2D::CairoPNG);
#endif
}
{
vector<Z2i::Point> res;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InGeneralizedDiskOfGivenRadius<Z2i::Point, DetComputer>
Functor;
typedef PredicateFromOrientationFunctor2<Functor, false, true> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShapeP8.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShapeP8.png", Board2D::CairoPNG);
#endif
}
{
vector<Z2i::Point> res;
typedef AvnaimEtAl2x2DetSignComputer<DGtal::int64_t> DetComputer;
typedef InGeneralizedDiskOfGivenRadius<Z2i::Point, DetComputer>
Functor;
typedef PredicateFromOrientationFunctor2<Functor> Predicate;
Predicate predicate( functor );
Board2D board;
board.saveSVG( "AlphaShapeP9.svg" );
#ifdef WITH_CAIRO
board.saveCairo("AlphaShapeP9.png", Board2D::CairoPNG);
#endif
}
}
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
return 0;
}
void beginBlock(const std::string &keyword="")
std::vector< Point > PointRange
void drawPolygon(const ForwardIterator &itb, const ForwardIterator &ite, Board &aBoard, bool isClosed=true)
void closedGrahamScanFromAnyPoint(const ForwardIterator &itb, const ForwardIterator &ite, OutputIterator res, const Predicate &aPredicate)
Procedure that retrieves the vertices of the convex hull of a weakly externally visible polygon (WEVP...
DGtal is the top-level namespace which contains all DGtal functions and types.
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.
int main(int argc, char **argv)
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet