DGtal 1.3.0
Loading...
Searching...
No Matches
testFrechetShortcut.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include <iterator>
33#include <cstdio>
34#include <cmath>
35#include <fstream>
36#include <vector>
37
38#include "DGtal/base/Common.h"
39#include "DGtal/base/Exceptions.h"
40#include "DGtal/kernel/SpaceND.h"
41
42#include "DGtal/kernel/domains/HyperRectDomain.h"
43#include "DGtal/geometry/curves/FrechetShortcut.h"
44#include "DGtal/io/boards/Board2D.h"
45
46#include "DGtal/io/boards/CDrawableWithBoard2D.h"
47#include "DGtal/geometry/curves/CForwardSegmentComputer.h"
48#include "DGtal/helpers/StdDefs.h"
49
50#include "DGtal/geometry/curves/GreedySegmentation.h"
51
52
54
55using namespace std;
56using namespace DGtal;
57using namespace LibBoard;
58using namespace Z2i;
59
61// Functions for testing class FrechetShortcut.
63
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}
116
117
118
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}
127
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}
211
212
213
214
215
217// Standard services - public :
218
219int main( int argc, char** argv )
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}
234// //
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
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: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
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...
SaturatedSegmentation::SegmentComputerIterator end() const
SaturatedSegmentation::SegmentComputerIterator begin() const
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
MyDigitalSurface::ConstIterator ConstIterator
GridCurve< K2 > Curve
Definition: StdDefs.h:116
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
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...
Struct representing a 2D point.
Definition: Point.h:27
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
SaturatedSegmentation< SegmentComputer > Segmentation
int main()
Definition: testBits.cpp:56
void testFrechetShortcutConceptChecking()
bool testFrechetShortcut()
bool testSegmentation()