This snippet segments a digital curve into Frechet shortcuts.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/FrechetShortcut.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
using namespace Z2i;
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
trace.
info() <<
" " << argv[ i ];
std::string filename;
double error;
if(argc == 1)
{
trace.
info() <<
"Use default file and error value\n";
filename = examplesPath + "samples/plant-frechet.dat";
error = 3;
}
else
if(argc != 3)
{
trace.
info() <<
"Please enter a filename and error value.\n";
return 0;
}
else
{
filename = argv[1];
error = atof(argv[2]);
}
ifstream instream;
instream.open (filename.c_str(), ifstream::in);
Curve c;
c.initFromVectorStream(instream);
board << c.getArrowsRange();
Curve::PointsRange r = c.getPointsRange();
Shortcut s(error);
s.init( r.begin() );
while ( ( s.end() != r.end() )
&&( s.extendFront() ) ) {}
Segmentation theSegmentation( r.begin(), r.end(), Shortcut(error) );
Segmentation::SegmentComputerIterator it = theSegmentation.begin();
Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
for ( ; it != itEnd; ++it) {
s=Shortcut(*it);
trace.
info() << s << std::endl;
board << s;
}
board.
saveEPS(
"FrechetShortcutExample.eps", Board2D::BoundingBox, 5000 );
#ifdef WITH_CAIRO
board.
saveCairo(
"FrechetShortcutExample.png");
#endif
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: On-line computation Computation of the longest shortcut according to the Fréchet distance for a ...
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
void beginBlock(const std::string &keyword="")
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
DGtal is the top-level namespace which contains all DGtal functions and types.
SaturatedSegmentation< SegmentComputer > Segmentation