DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
exampleFrechetShortcut.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 
35 #include "ConfigExamples.h"
36 #include "DGtal/io/boards/Board2D.h"
37 #include "DGtal/geometry/curves/FrechetShortcut.h"
38 #include "DGtal/geometry/curves/GreedySegmentation.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 using namespace Z2i;
44 
45 
46 
47 
49 
50 int main( int argc, char** argv )
51 {
52  trace.beginBlock ( "Example FrechetShortcut" );
53  trace.info() << "Args:";
54  for ( int i = 0; i < argc; ++i )
55  trace.info() << " " << argv[ i ];
56  trace.info() << endl;
57 
58  std::string filename = examplesPath + "samples/plant-frechet.dat";
59  ifstream instream; // input stream
60  instream.open (filename.c_str(), ifstream::in);
61 
62 
63  double error = atof(argv[1]);
64  trace.info() << error << endl;
65 
66  Curve c; //grid curve
67  c.initFromVectorStream(instream);
68 
69  Board2D board;
70 
71  // Display the pixels as arrows range to show the way the curve is scanned
72  board << c.getArrowsRange();
73 
74  trace.beginBlock("Simple example");
75 
77  Curve::PointsRange r = c.getPointsRange();
78 
80 
81  // Computation of one shortcut
82  Shortcut s(error);
83 
84  s.init( r.begin() );
85  while ( ( s.end() != r.end() )
86  &&( s.extendForward() ) ) {}
87 
88 
89 
90  // Computation of a greedy segmentation
91 
92  typedef GreedySegmentation<Shortcut> Segmentation;
93 
94  Segmentation theSegmentation( r.begin(), r.end(), Shortcut(error) );
95 
96  // the segmentation is computed here
97  Segmentation::SegmentComputerIterator it = theSegmentation.begin();
98  Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
99 
100  for ( ; it != itEnd; ++it) {
101  s=Shortcut(*it);
102  trace.info() << s << std::endl;
103  board << s;
104  }
105 
106  board.saveEPS("FrechetShortcutExample.eps", Board2D::BoundingBox, 5000 );
107 
109 
110 
111  trace.endBlock();
112  return 0;
113 }
114 // //