DGtal  1.4.beta
geometry/curves/exampleAlphaThickSegmentNoisy.cpp

This example shows a simple alpha-thick segment recognition given from a noisy input contour with floating point coordinates.

See also
Alpha-thick Segment Recognition
Simple example of some alpha-thick segments recognition with alpha = 2, 9 and 15.
#include <iostream>
#include "ConfigExamples.h"
#include "DGtal/base/Common.h"
#include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/readers/PointListReader.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace DGtal;
int main( )
{
trace.beginBlock ( "Example exampleAlphaThickSegment" );
typedef AlphaThickSegmentComputer< Z2i::RealPoint > AlphaThickSegmentComputer2D;
Board2D aBoard;
std::string file = examplesPath + "samples/contourSnoisy.sdp";
std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile(file);
// displaying contour
aBoard << SetMode(aContour[0].className(), "Grid");
for (unsigned int i = 0; i< aContour.size(); i++){
aBoard << aContour[i];
aBoard.drawLine(aContour[i][0], aContour[i][1],
aContour[(i+1)%aContour.size()][0], aContour[(i+1)%aContour.size()][1]);
}
//initialisation of an AlphaThickSegmentComputer2D of thickness 10 and forward recognition.
AlphaThickSegmentComputer2D anAlphaSegment(15);
std::vector<Z2i::RealPoint>::const_iterator it = aContour.begin();
while (anAlphaSegment.extendFront(*it)) {
it++;
}
aBoard << anAlphaSegment;
AlphaThickSegmentComputer2D anAlphaSegment2(9);
anAlphaSegment2.init(aContour.begin());
while (anAlphaSegment2.end() != aContour.end() &&
anAlphaSegment2.extendFront()) {
}
aBoard << CustomStyle( anAlphaSegment2.className(), new CustomColors( DGtal::Color::Blue, DGtal::Color::None ) );
aBoard << anAlphaSegment2;
AlphaThickSegmentComputer2D anAlphaSegment3(2);
anAlphaSegment3.init(aContour.begin());
while (anAlphaSegment3.end() != aContour.end() &&
anAlphaSegment3.extendFront()) {
}
aBoard << CustomStyle( anAlphaSegment3.className(), new CustomColors( DGtal::Color::Green, DGtal::Color::None ) );
aBoard << anAlphaSegment3;
aBoard.saveEPS("exampleAlphaThickSegmentNoisy.eps");
return 0;
}
// //
static const Color None
Definition: Color.h:412
static const Color Green
Definition: Color.h:417
static const Color Blue
Definition: Color.h:419
void beginBlock(const std::string &keyword="")
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)