DGtal  0.9.3
exampleFrechetShortcut.cpp
Go to the documentation of this file.
1 
39 #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 
50 using namespace std;
51 using namespace DGtal;
52 using namespace Z2i;
53 
54 
55 
56 
58 
59 int 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 
118  typedef GreedySegmentation<Shortcut> Segmentation;
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 // //
void beginBlock(const std::string &keyword="")
Aim: On-line computation Computation of the longest shortcut according to the Fr├ęchet distance for a ...
Trace trace
Definition: Common.h:137
int main(int argc, char **argv)
STL namespace.
double endBlock()
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators. The last element of a given segment is the first one one of the next segment.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
GreedySegmentation::SegmentComputerIterator begin() const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70