DGtal 1.3.0
Loading...
Searching...
No Matches
exampleFrechetShortcut.cpp
Go to the documentation of this file.
1
40#include <iostream>
41#include "DGtal/base/Common.h"
42#include "DGtal/helpers/StdDefs.h"
43
44#include "ConfigExamples.h"
45#include "DGtal/io/boards/Board2D.h"
46#include "DGtal/geometry/curves/FrechetShortcut.h"
47#include "DGtal/geometry/curves/GreedySegmentation.h"
49
50using namespace std;
51using namespace DGtal;
52using namespace Z2i;
53
54
55
56
58
59int main( int argc, char** argv )
60{
61 trace.beginBlock ( "Example FrechetShortcut" );
62 trace.info() << "Args:";
63 for ( int i = 0; i < argc; ++i )
64 trace.info() << " " << argv[ i ];
65 trace.info() << endl;
66
67 std::string filename;
68 double error;
69
70 if(argc == 1)
71 {
72 trace.info() << "Use default file and error value\n";
73 filename = examplesPath + "samples/plant-frechet.dat";
74 error = 3;
75 }
76 else
77 if(argc != 3)
78 {
79 trace.info() << "Please enter a filename and error value.\n";
80 return 0;
81 }
82 else
83 {
84 filename = argv[1];
85 error = atof(argv[2]);
86 }
87 ifstream instream; // input stream
88 instream.open (filename.c_str(), ifstream::in);
89
90
91
92 Curve c; //grid curve
93 c.initFromVectorStream(instream);
94
95 Board2D board;
96
97 // Display the pixels as arrows range to show the way the curve is scanned
98 board << c.getArrowsRange();
99
100 trace.beginBlock("Simple example");
101
103 Curve::PointsRange r = c.getPointsRange();
104
106
107 // Computation of one shortcut
108 Shortcut s(error);
109
110 s.init( r.begin() );
111 while ( ( s.end() != r.end() )
112 &&( s.extendFront() ) ) {}
113
114
115
116 // Computation of a greedy segmentation
117
119
120 Segmentation theSegmentation( r.begin(), r.end(), Shortcut(error) );
121
122 // the segmentation is computed here
123 Segmentation::SegmentComputerIterator it = theSegmentation.begin();
124 Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
125
126 for ( ; it != itEnd; ++it) {
127 s=Shortcut(*it);
128 trace.info() << s << std::endl;
129 board << s;
130 }
131
132 board.saveEPS("FrechetShortcutExample.eps", Board2D::BoundingBox, 5000 );
133
135 #ifdef WITH_CAIRO
136 board.saveCairo("FrechetShortcutExample.png");
137 #endif
138
139
140 trace.endBlock();
141 return 0;
142}
143// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
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....
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
bool initFromVectorStream(std::istream &in)
Aim: Specific iterator to visit all the maximal segments of a saturated segmentation.
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
SaturatedSegmentation::SegmentComputerIterator end() const
SaturatedSegmentation::SegmentComputerIterator begin() const
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.
Trace trace
Definition: Common.h:154
STL namespace.
SaturatedSegmentation< SegmentComputer > Segmentation
int main()
Definition: testBits.cpp:56