DGtal  1.4.beta
testFrechetShortcut.cpp File Reference
#include <iostream>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/base/Exceptions.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/geometry/curves/FrechetShortcut.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/boards/CDrawableWithBoard2D.h"
#include "DGtal/geometry/curves/CForwardSegmentComputer.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
Include dependency graph for testFrechetShortcut.cpp:

Go to the source code of this file.

Functions

bool testFrechetShortcut ()
 
void testFrechetShortcutConceptChecking ()
 
bool testSegmentation ()
 
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

Functions for testing class FrechetShortcut.

This file is part of the DGtal library.

Definition in file testFrechetShortcut.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 218 of file testFrechetShortcut.cpp.

219 {
220  trace.beginBlock ( "Testing class FrechetShortcut" );
221  trace.info() << "Args:";
222  for ( int i = 0; i < argc; ++i )
223  trace.info() << " " << argv[ i ];
224  trace.info() << endl;
225 
227 
228  bool res = testFrechetShortcut() && testSegmentation(); // && ... other tests
229  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
230  trace.endBlock();
231  return res ? 0 : 1;
232 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
void testFrechetShortcutConceptChecking()
bool testFrechetShortcut()
bool testSegmentation()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testFrechetShortcut(), testFrechetShortcutConceptChecking(), testSegmentation(), and DGtal::trace.

◆ testFrechetShortcut()

bool testFrechetShortcut ( )

Example of a test. To be completed.

Definition at line 67 of file testFrechetShortcut.cpp.

68 {
69  unsigned int nbok = 0;
70  unsigned int nb = 0;
71 
72  typedef PointVector<2,int> Point;
73  typedef std::vector<Point>::iterator Iterator;
74  typedef FrechetShortcut<Iterator,int> Shortcut;
75 
76  std::vector<Point> contour;
77  contour.push_back(Point(0,0));
78  contour.push_back(Point(1,0));
79  contour.push_back(Point(2,0));
80  contour.push_back(Point(3,0));
81  contour.push_back(Point(4,0));
82  contour.push_back(Point(5,0));
83  contour.push_back(Point(6,0));
84  contour.push_back(Point(7,0));
85  contour.push_back(Point(7,1));
86  contour.push_back(Point(6,1));
87  contour.push_back(Point(5,1));
88  contour.push_back(Point(4,1));
89  contour.push_back(Point(3,1));
90  contour.push_back(Point(2,1));
91  contour.push_back(Point(3,2));
92  contour.push_back(Point(4,2));
93  contour.push_back(Point(5,2));
94  contour.push_back(Point(6,2));
95  contour.push_back(Point(7,2));
96  contour.push_back(Point(8,2));
97  contour.push_back(Point(9,2));
98 
99  trace.beginBlock ( "Testing block ..." );
100 
101  Shortcut s(5);
102  s.init(contour.begin());
103 
104  trace.info() << s << std::endl;
105 
106  while ( (s.end() != contour.end())
107  &&(s.extendFront()) ) {}
108 
109  trace.info() << s << std::endl;
110 
111 
112  trace.endBlock();
113 
114  return nbok == nb;
115 }
Aim: On-line computation Computation of the longest shortcut according to the Fréchet distance for a ...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testFrechetShortcutConceptChecking()

void testFrechetShortcutConceptChecking ( )

Definition at line 119 of file testFrechetShortcut.cpp.

120 {
121  typedef PointVector<2,int> Point;
122  typedef std::vector<Point>::const_iterator ConstIterator;
123  typedef FrechetShortcut<ConstIterator,int> Shortcut;
124  BOOST_CONCEPT_ASSERT(( concepts::CDrawableWithBoard2D<Shortcut> ));
125  BOOST_CONCEPT_ASSERT(( concepts::CForwardSegmentComputer<Shortcut> ));
126 }
MyDigitalSurface::ConstIterator ConstIterator
Aim: The concept CDrawableWithBoard2D specifies what are the classes that admit an export with Board2...
Aim: Defines the concept describing a forward segment computer. Like any model of CIncrementalSegment...

Referenced by main().

◆ testSegmentation()

bool testSegmentation ( )

Definition at line 128 of file testFrechetShortcut.cpp.

129 {
130  unsigned int nbok = 0;
131  unsigned int nb = 0;
132 
133  typedef PointVector<2,int> Point;
134  //typedef std::vector<Point>::iterator Iterator;
135  //typedef FrechetShortcut<Iterator,int> SegmentComputer;
136 
137  std::vector<Point> contour;
138  contour.push_back(Point(0,0));
139  contour.push_back(Point(1,0));
140  contour.push_back(Point(2,0));
141  contour.push_back(Point(3,0));
142  contour.push_back(Point(4,0));
143  contour.push_back(Point(5,0));
144  contour.push_back(Point(6,0));
145  contour.push_back(Point(7,0));
146  contour.push_back(Point(7,1));
147  contour.push_back(Point(6,1));
148  contour.push_back(Point(5,1));
149  contour.push_back(Point(4,1));
150  contour.push_back(Point(3,1));
151  contour.push_back(Point(2,1));
152  contour.push_back(Point(2,2));
153  contour.push_back(Point(3,2));
154  contour.push_back(Point(4,2));
155  contour.push_back(Point(5,2));
156  contour.push_back(Point(6,2));
157  contour.push_back(Point(7,2));
158  contour.push_back(Point(8,2));
159  contour.push_back(Point(9,2));
160 
161  trace.beginBlock ( "Testing block ..." );
162 
163  typedef Curve::PointsRange::ConstIterator Iterator;
165 
166  Curve aCurve; //grid curve
167  aCurve.initFromVector(contour);
168 
169  typedef Curve::PointsRange Range; //range
170  Range r = aCurve.getPointsRange(); //range
171 
172  Board2D board;
173  board << r;
174  board << aCurve.getArrowsRange();
175 
176 
177  double anerror = 3;
178  nbok =3;
179 
180  trace.beginBlock ( "Greedy segmentation" );
181  {
183  Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer(anerror) );
184 
185  Segmentation::SegmentComputerIterator it = theSegmentation.begin();
186  Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
187 
188  for ( ; it != itEnd; ++it) {
189  SegmentComputer s(*it);
190  trace.info() << s << std::endl;
191  board << (*it);
192  nb++;
193  }
194 
195  //board << aCurve;
196  trace.info() << theSegmentation << std::endl;
197  board.saveEPS("FrechetShortcutGreedySegmentationTest.eps", Board2D::BoundingBox, 5000 );
198  }
199 
200  /* Saturated segmentation does not work for FrechetShortcut
201  computer. Indeed, given two maximal Frechet shortcuts s1(begin, end) et
202  s2(begin, end), we can have s1.begin < s2.begin < s2.end <
203  s1.end. */
204 
205 
206  trace.endBlock();
207 
208  return nbok == nb;
209 }
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: 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
PointsRange getPointsRange() const
Definition: GridCurve.h:426
ArrowsRange getArrowsRange() const
Definition: GridCurve.h:450
Storage::const_iterator ConstIterator
Definition: GridCurve.h:314
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
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...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
SaturatedSegmentation< SegmentComputer > Segmentation

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

Referenced by main().