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 std;
using namespace Z2i;
int main(
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
std::string filename;
if(argc == 1)
{
trace.
info() <<
"Use default file and error value\n";
filename = examplesPath + "samples/plant-frechet.dat";
}
else
if(argc != 3)
{
trace.
info() <<
"Please enter a filename and error value.\n";
return 0;
}
else
{
filename = argv[1];
}
ifstream instream;
instream.open (filename.c_str(), ifstream::in);
c.initFromVectorStream(instream);
Board2D board;
board << c.getArrowsRange();
Curve::PointsRange r = c.getPointsRange();
typedef FrechetShortcut<Curve::PointsRange::ConstIterator,int> Shortcut;
s.init( r.begin() );
while ( ( s.end() != r.end() )
&&( s.extendFront() ) ) {}
Segmentation::SegmentComputerIterator it = theSegmentation.begin();
Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
for ( ; it != itEnd; ++it) {
s=Shortcut(*it);
board << s;
}
board.saveEPS("FrechetShortcutExample.eps", Board2D::BoundingBox, 5000 );
#ifdef WITH_CAIRO
board.saveCairo("FrechetShortcutExample.png");
#endif
return 0;
}
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
SaturatedSegmentation< SegmentComputer > Segmentation