DGtal 1.4.0
Loading...
Searching...
No Matches
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 "ConfigTest.h"
Include dependency graph for testFrechetShortcut.cpp:

Go to the source code of this file.

Functions

bool testFrechetShortcut ()
 
void testFrechetShortcutConceptChecking ()
 
bool testSegmentation ()
 
bool testSegmentationLarger (const string &filename, int min, int max, double delta)
 
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 308 of file testFrechetShortcut.cpp.

309{
310 trace.beginBlock ( "Testing class FrechetShortcut" );
311 trace.info() << "Args:";
312 for ( int i = 0; i < argc; ++i )
313 trace.info() << " " << argv[ i ];
314 trace.info() << endl;
315
317
318
319 std::string Plant054 = testPath + "samples/Plant054.dat";
320 std::string beetle = testPath + "samples/beetle-1.dat";
321
322
323 bool res = testFrechetShortcut() && testSegmentation() && testSegmentationLarger(Plant054,0,20,0.5) && testSegmentationLarger(beetle,0,30,5); // && ... other tests
324 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
325 trace.endBlock();
326 return res ? 0 : 1;
327}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool testSegmentationLarger(const string &filename, int min, int max, double delta)
void testFrechetShortcutConceptChecking()
bool testFrechetShortcut()
bool testSegmentation()

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

◆ testFrechetShortcut()

bool testFrechetShortcut ( )

Example of a test. To be completed.

Definition at line 68 of file testFrechetShortcut.cpp.

69{
70 unsigned int nbok = 0;
71 unsigned int nb = 0;
72
74 typedef std::vector<Point>::iterator Iterator;
75 typedef FrechetShortcut<Iterator,int> Shortcut;
76
77 std::vector<Point> contour;
78 contour.push_back(Point(0,0));
79 contour.push_back(Point(1,0));
80 contour.push_back(Point(2,0));
81 contour.push_back(Point(3,0));
82 contour.push_back(Point(4,0));
83 contour.push_back(Point(5,0));
84 contour.push_back(Point(6,0));
85 contour.push_back(Point(7,0));
86 contour.push_back(Point(7,1));
87 contour.push_back(Point(6,1));
88 contour.push_back(Point(5,1));
89 contour.push_back(Point(4,1));
90 contour.push_back(Point(3,1));
91 contour.push_back(Point(2,1));
92 contour.push_back(Point(3,2));
93 contour.push_back(Point(4,2));
94 contour.push_back(Point(5,2));
95 contour.push_back(Point(6,2));
96 contour.push_back(Point(7,2));
97 contour.push_back(Point(8,2));
98 contour.push_back(Point(9,2));
99
100 trace.beginBlock ( "Testing block ..." );
101
102 Shortcut s(5);
103 s.init(contour.begin());
104
105 trace.info() << s << std::endl;
106
107 while ( (s.end() != contour.end())
108 &&(s.extendFront()) ) {}
109
110 trace.info() << s << std::endl;
111
112
113 trace.endBlock();
114
115 return nbok == nb;
116}
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.
Space::Point Point
Definition StdDefs.h:95

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

Referenced by main().

◆ testFrechetShortcutConceptChecking()

void testFrechetShortcutConceptChecking ( )

Definition at line 120 of file testFrechetShortcut.cpp.

121{
123 typedef std::vector<Point>::const_iterator ConstIterator;
124 typedef FrechetShortcut<ConstIterator,int> Shortcut;
125 BOOST_CONCEPT_ASSERT(( concepts::CDrawableWithBoard2D<Shortcut> ));
126 BOOST_CONCEPT_ASSERT(( concepts::CForwardSegmentComputer<Shortcut> ));
127}
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 129 of file testFrechetShortcut.cpp.

130{
132
133 std::vector<Point> contour;
134 contour.push_back(Point(0,0));
135 contour.push_back(Point(1,0));
136 contour.push_back(Point(2,0));
137 contour.push_back(Point(3,0));
138 contour.push_back(Point(4,0));
139 contour.push_back(Point(5,0));
140 contour.push_back(Point(6,0));
141 contour.push_back(Point(7,0));
142 contour.push_back(Point(7,1));
143 contour.push_back(Point(6,1));
144 contour.push_back(Point(5,1));
145 contour.push_back(Point(4,1));
146 contour.push_back(Point(3,1));
147 contour.push_back(Point(2,1));
148 contour.push_back(Point(2,2));
149 contour.push_back(Point(3,2));
150 contour.push_back(Point(4,2));
151 contour.push_back(Point(5,2));
152 contour.push_back(Point(6,2));
153 contour.push_back(Point(7,2));
154 contour.push_back(Point(8,2));
155 contour.push_back(Point(9,2));
156
157 trace.beginBlock ( "Testing block ..." );
158
159 typedef Curve::PointsRange::ConstIterator Iterator;
161
162 Curve aCurve; //grid curve
163 aCurve.initFromVector(contour);
164
165 typedef Curve::PointsRange Range; //range
166 Range r = aCurve.getPointsRange(); //range
167
168 Board2D board;
169 board << r;
170 board << aCurve.getArrowsRange();
171
172 // Test when error = 3
173
174
175 int nbok = 3;
176 int nb=0;
177 trace.beginBlock ( "Greedy segmentation" );
178 {
180 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer(3) );
181
182 Segmentation::SegmentComputerIterator it = theSegmentation.begin();
183 Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
184
185 for ( ; it != itEnd; ++it) {
186 SegmentComputer s(*it);
187 trace.info() << s << std::endl;
188 board << (*it);
189 nb++;
190 }
191 trace.info() << theSegmentation << std::endl;
192 board.saveEPS("FrechetShortcutGreedySegmentationTest.eps", Board2D::BoundingBox, 5000 );
193 }
194
195 // test when error = 0
196
197
198 int nbok2 = 5;
199 int nb2=0;
200 trace.beginBlock ( "Greedy segmentation" );
201 {
203 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer(0) );
204
205 Segmentation::SegmentComputerIterator it = theSegmentation.begin();
206 Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
207
208 for ( ; it != itEnd; ++it) {
209 SegmentComputer s(*it);
210 trace.info() << s << std::endl;
211 board << (*it);
212 nb2++;
213 }
214 trace.info() << theSegmentation << std::endl;
215 board.saveEPS("FrechetShortcutGreedySegmentationTest.eps", Board2D::BoundingBox, 5000 );
216 }
217
218
219 /* Saturated segmentation does not work for FrechetShortcut
220 computer. Indeed, given two maximal Frechet shortcuts s1(begin, end) et
221 s2(begin, end), we can have s1.begin < s2.begin < s2.end <
222 s1.end. */
223
224
225 trace.endBlock();
226
227 return (nbok == nb) && (nbok2==nb2);
228}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
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().

◆ testSegmentationLarger()

bool testSegmentationLarger ( const string & filename,
int min,
int max,
double delta )

Definition at line 232 of file testFrechetShortcut.cpp.

233{
234 // Build output filename
235
236 std::size_t pos1 = filename.find("samples/");
237 std::size_t init = pos1+8;
238 std::size_t pos2 = filename.find(".dat");
239 std::size_t end = pos2-init;
240 std::string output = filename.substr(init,end);
241
242 trace.beginBlock ( "Testing block ..." );
243
244 trace.beginBlock ( "Greedy segmentation on larger contours" );
245
246 trace.info() << "Reading input curve" << filename << std::endl;
247
248 typedef Curve::PointsRange::ConstIterator Iterator;
249
250 Curve aCurve; //grid curve
251
252 ifstream instream; // input stream
253 instream.open (filename.c_str(), ifstream::in);
254
255 aCurve.initFromVectorStream(instream);
256
257
258 typedef Curve::PointsRange Range; //range
259 Range r = aCurve.getPointsRange(); //range
260
261 Board2D board;
262 board << r;
263 board << aCurve.getArrowsRange();
264
265 trace.info() << "Size of input curve = " << aCurve.size() << std::endl;
266
267 typedef Curve::PointsRange::ConstIterator Iterator;
270
271 for(double error = min; error <= max; error+=delta)
272 {
273 trace.info() << "error = " << error << "\t";
274 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer(error) );
275
276 Segmentation::SegmentComputerIterator it = theSegmentation.begin();
277 Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
278
279 int size = 0;
280 for ( ; it != itEnd; ++it)
281 size++;
282
283 trace.info() << "size of simplified curve = " << size << std::endl;
284
285 it = theSegmentation.begin();
286 for ( ; it != itEnd; ++it)
287 {
288 SegmentComputer s(*it);
289 board << (*it);
290 }
291 // save simplified curves in eps file
292 string outputFilename = "FrechetShortcut-"+output+".eps";
293 board.saveEPS(outputFilename.c_str(), Board2D::BoundingBox, 5000 );
294 }
295
296 trace.endBlock();
297 trace.endBlock();
298
299 return 1;
300}
bool initFromVectorStream(std::istream &in)
Storage::size_type size() const
MessageStream error
int max(int a, int b)
K init(Point(0, 0, 0), Point(512, 512, 512), true)

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

Referenced by main().