DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
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"

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 219 of file testFrechetShortcut.cpp.

220{
221 trace.beginBlock ( "Testing class FrechetShortcut" );
222 trace.info() << "Args:";
223 for ( int i = 0; i < argc; ++i )
224 trace.info() << " " << argv[ i ];
225 trace.info() << endl;
226
228
229 bool res = testFrechetShortcut() && testSegmentation(); // && ... other tests
230 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
231 trace.endBlock();
232 return res ? 0 : 1;
233}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
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
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
Struct representing a 2D point.
Definition: Point.h:27

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{
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
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
164 typedef Curve::PointsRange::ConstIterator Iterator;
166
167 Curve aCurve; //grid curve
168 aCurve.initFromVector(contour);
169
170 typedef Curve::PointsRange Range; //range
171 Range r = aCurve.getPointsRange(); //range
172
173 Board2D board;
174 board << r;
175 board << aCurve.getArrowsRange();
176
177
178 double anerror = 3;
179 nbok =3;
180
181 trace.beginBlock ( "Greedy segmentation" );
182 {
184 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer(anerror) );
185
186 Segmentation::SegmentComputerIterator it = theSegmentation.begin();
187 Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
188
189 for ( ; it != itEnd; ++it) {
190 SegmentComputer s(*it);
191 trace.info() << s << std::endl;
192 board << (*it);
193 nb++;
194 }
195
196 //board << aCurve;
197 trace.info() << theSegmentation << std::endl;
198 board.saveEPS("FrechetShortcutGreedySegmentationTest.eps", Board2D::BoundingBox, 5000 );
199 }
200
201 /* Saturated segmentation does not work for FrechetShortcut
202 computer. Indeed, given two maximal Frechet shortcuts s1(begin, end) et
203 s2(begin, end), we can have s1.begin < s2.begin < s2.end <
204 s1.end. */
205
206
207 trace.endBlock();
208
209 return nbok == nb;
210}
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:805
GridCurve< K2 > Curve
Definition: StdDefs.h:116
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().