This example shows the greedy decomposition of an noisy contour from the alpha-thick segment primitive with alpha = 4.
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
#include <DGtal/io/readers/GenericReader.h>
using namespace std;
{
typedef std::vector<Z2i::RealPoint>::const_iterator
ConstIterator;
typedef AlphaThickSegmentComputer<Z2i::RealPoint, ConstIterator > AlphaThickSegmentComputer2D;
Board2D aBoard;
std::string file = examplesPath + "samples/contourSnoisy.sdp";
std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile (file);
typedef GreedySegmentation<AlphaThickSegmentComputer2D> DecompositionAT;
aBoard << SetMode(aContour[0].className(), "Grid");
std::vector<LibBoard::Point> poly;
for (
unsigned int i = 0; i< aContour.size(); i++) poly.push_back(
LibBoard::Point(aContour[i][0], aContour[i][1]));
aBoard.fillPolyline(poly);
aBoard << SetMode("AlphaThickSegment", "BoundingBox");
DecompositionAT theDecomposition(aContour.begin(), aContour.end(), AlphaThickSegmentComputer2D(4));
for ( DecompositionAT::SegmentComputerIterator
it = theDecomposition.begin(),
itEnd = theDecomposition.end();
it != itEnd; ++it )
{
aBoard << CustomStyle( (*it).className(),
new CustomPenColor( Color::Blue ) );
aBoard<< *it;
}
aBoard.saveEPS("greedyAlphaThickDecomposition.eps");
return 0;
}
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Struct representing a 2D point.
int main(int argc, char **argv)