DGtal 1.3.0
Loading...
Searching...
No Matches
geometry/curves/exampleFrechetShortcut.cpp

This snippet segments a digital curve into Frechet shortcuts.

See also
Fréchet Shortcuts and Analysis of one-dimensional discrete structures
#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 DGtal;
using namespace Z2i;
int main( int argc, char** argv )
{
trace.beginBlock ( "Example FrechetShortcut" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
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; // input stream
instream.open (filename.c_str(), ifstream::in);
Curve c; //grid curve
c.initFromVectorStream(instream);
Board2D board;
// Display the pixels as arrows range to show the way the curve is scanned
board << c.getArrowsRange();
trace.beginBlock("Simple example");
Curve::PointsRange r = c.getPointsRange();
// Computation of one shortcut
Shortcut s(error);
s.init( r.begin() );
while ( ( s.end() != r.end() )
&&( s.extendFront() ) ) {}
// Computation of a greedy segmentation
Segmentation theSegmentation( r.begin(), r.end(), Shortcut(error) );
// the segmentation is computed here
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
trace.endBlock();
return 0;
}
// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
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="")
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
SaturatedSegmentation< SegmentComputer > Segmentation
int main()
Definition: testBits.cpp:56