DGtal  1.2.0
Functions
exampleFrechetShortcut.cpp File Reference
#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"
Include dependency graph for exampleFrechetShortcut.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Isabelle Sivignon (isabe.nosp@m.lle..nosp@m.sivig.nosp@m.non@.nosp@m.gipsa.nosp@m.-lab.nosp@m..gren.nosp@m.oble.nosp@m.-inp..nosp@m.fr ) gipsa-lab Grenoble Images Parole Signal Automatique (CNRS, UMR 5216), CNRS, France
Date
2012/03/26

An example file named exampleFrechetShortcut.

This file is part of the DGtal library.

Definition in file exampleFrechetShortcut.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[FrechetShortcutUsage]

[FrechetShortcutUsage]

Definition at line 59 of file exampleFrechetShortcut.cpp.

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 }
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...
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
Trace trace
Definition: Common.h:154
MessageStream error
SaturatedSegmentation< SegmentComputer > Segmentation

References DGtal::SaturatedSegmentation< TSegmentComputer >::begin(), DGtal::Trace::beginBlock(), DGtal::SaturatedSegmentation< TSegmentComputer >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), and DGtal::trace.