DGtal  1.3.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;
}
// //
DGtal::Trace::endBlock
double endBlock()
DGtal::Color::Green
static const Color Green
Definition: Color.h:393
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::PointListReader
Aim: Implements method to read a set of points represented in each line of a file.
Definition: PointListReader.h:84
DGtal::Color::Blue
static const Color Blue
Definition: Color.h:395
DGtal::AlphaThickSegmentComputer
Aim: This class is devoted to the recognition of alpha thick segments as described in ....
Definition: AlphaThickSegmentComputer.h:127
DGtal::CustomStyle
Definition: Board2D.h:217
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:70
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
DGtal::Color::None
static const Color None
Definition: Color.h:388
LibBoard::Board::drawLine
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:368