DGtal  1.3.beta
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 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;
}
// //
DGtal::Trace::endBlock
double endBlock()
DGtal::FrechetShortcut
Aim: On-line computation Computation of the longest shortcut according to the Fréchet distance for a ...
Definition: FrechetShortcut.h:107
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::SaturatedSegmentation::end
SaturatedSegmentation::SegmentComputerIterator end() const
DGtal::SaturatedSegmentation::begin
SaturatedSegmentation::SegmentComputerIterator begin() const
DGtal::SaturatedSegmentation::SegmentComputerIterator
Aim: Specific iterator to visit all the maximal segments of a saturated segmentation.
Definition: SaturatedSegmentation.h:179
DGtal::Trace::info
std::ostream & info()
DGtal::GreedySegmentation
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Definition: GreedySegmentation.h:149
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::Z2i::Curve
GridCurve< K2 > Curve
Definition: StdDefs.h:116
Segmentation
SaturatedSegmentation< SegmentComputer > Segmentation
Definition: testArithmeticalDSSComputerOnSurfels.cpp:56
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
LibBoard::error
MessageStream error
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::SaturatedSegmentation
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
Definition: SaturatedSegmentation.h:153