This example shows the tangential cover 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/geometry/curves/SaturatedSegmentation.h"
#include "DGtal/base/Circulator.h"
#include "DGtal/geometry/curves/SegmentComputerUtils.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
{
trace.
beginBlock (
"Example of AlphaThickSegment tangential cover obtained from SaturatedSegmentation" );
typedef std::vector<Z2i::RealPoint>::const_iterator RAConstIterator;
typedef Circulator<RAConstIterator> ConstCirculator;
typedef AlphaThickSegmentComputer<Z2i::RealPoint, ConstCirculator> AlphaThickSegmentComputer2D;
typedef SaturatedSegmentation<AlphaThickSegmentComputer2D> AlphaSegmentation;
Board2D aBoard, aBoard2;
std::string file = examplesPath + "samples/contourSnoisy.sdp";
std::vector<Z2i::RealPoint> aContour = PointListReader<Z2i::RealPoint>::getPointsFromFile (file);
aBoard << SetMode(aContour[0].className(), "Grid");
aBoard2 << 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);
aBoard2.fillPolyline(poly);
Circulator<RAConstIterator> circulator (aContour.begin(), aContour.begin(), aContour.end());
AlphaThickSegmentComputer2D computer(4, functions::Hull2D::EuclideanThickness);
AlphaSegmentation segmentator(circulator, circulator, computer);
AlphaSegmentation::SegmentComputerIterator i = segmentator.begin();
AlphaSegmentation::SegmentComputerIterator end = segmentator.end();
for ( ; i != end; ++i) {
AlphaThickSegmentComputer2D current(*i);
aBoard << SetMode(current.className(), "BoundingBox");
aBoard << current;
}
aBoard.saveEPS("exampleAlphaThickSegmentTgtCover.eps");
trace.
beginBlock (
"Example of AlphaThickSegment tangential cover obtained for a single point" );
unsigned int index = 80;
AlphaThickSegmentComputer2D first (computer);
AlphaThickSegmentComputer2D last (computer);
aBoard2.fillCircle((*(circulator+index))[0], (*(circulator+index))[1], 1.0);
while(first.end() != last.end()){
aBoard2 << SetMode(first.className(), "BoundingBox");
aBoard2 << first;
}
aBoard2 << last;
stringstream name;
name << "exampleAlphaThickSegmentTgtCoverPoint" << index<< ".eps";
aBoard2.saveEPS(name.str().c_str());
return 0;
}
Structure representing an RGB triple with alpha component.
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
void lastMaximalSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &begin, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
void nextMaximalSegment(SC &s, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
void firstMaximalSegment(SC &s, const typename SC::ConstIterator &i, const typename SC::ConstIterator &begin, const typename SC::ConstIterator &end, DGtal::ForwardSegmentComputer)
Struct representing a 2D point.
int main(int argc, char **argv)