DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testFP.cpp File Reference
#include <iostream>
#include <fstream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/FP.h"
#include "DGtal/io/boards/Board2D.h"
#include "ConfigTest.h"

Go to the source code of this file.

Functions

bool testFP (string filename)
 
template<typename Range1 , typename Range2 >
bool compare (const Range1 &pts, const Range2 &groundTruth)
 
bool stoppingCriterionTest ()
 
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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/01/26

Functions for testing class FP.

This file is part of the DGtal library.

Definition in file testFP.cpp.

Function Documentation

◆ compare()

template<typename Range1 , typename Range2 >
bool compare ( const Range1 &  pts,
const Range2 &  groundTruth 
)

Definition at line 98 of file testFP.cpp.

99{
100
101 DGtal::GridCurve<> curve;
102 curve.initFromPointsRange(pts.begin(), pts.end());
103
106 FaithfulPolygon theFP( curve.getPointsRange().c(), curve.getPointsRange().c() );
107
108 return ( (theFP.polygon().size() == groundTruth.size()) &&
109 std::equal(theFP.polygon().begin(), theFP.polygon().end(), groundTruth.begin()) );
110}
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:86
ConstCirculator c() const
Aim: Computes the faithful polygon (FP) of a range of 4/8-connected 2D Points.
Definition: FP.h:293
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
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)

References DGtal::ConstRangeAdapter< TIterator, TFunctor, TReturnType >::c(), DGtal::GridCurve< TKSpace >::getPointsRange(), and DGtal::GridCurve< TKSpace >::initFromPointsRange().

Referenced by stoppingCriterionTest().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 256 of file testFP.cpp.

257{
258 using namespace DGtal;
259
260 trace.beginBlock ( "Testing class FP" );
261 trace.info() << "Args:";
262 for ( int i = 0; i < argc; ++i )
263 trace.info() << " " << argv[ i ];
264 trace.info() << endl;
265
266 string sinus2D4 = testPath + "samples/sinus2D4.dat";
267 string square = testPath + "samples/smallSquare.dat";
268 string dss = testPath + "samples/DSS.dat";
269
270 bool res = testFP(sinus2D4)
271 && testFP(square)
272 && testFP(dss)
274 ;
275
276 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
277 trace.endBlock();
278 return res ? 0 : 1;
279}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
bool stoppingCriterionTest()
Definition: testFP.cpp:112
bool testFP(string filename)
Definition: testFP.cpp:56

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), stoppingCriterionTest(), and testFP().

◆ stoppingCriterionTest()

bool stoppingCriterionTest ( )

Definition at line 112 of file testFP.cpp.

113{
114 using namespace DGtal;
115 using namespace Z2i;
116
117 int nbok = 0;
118 int nb = 0;
119
120 trace.beginBlock ( "Stopping criterion" );
121
122 { //inflection part, one leaning point
123 std::vector<Point> pts, pts2;
124 pts.push_back(Point(0,0));
125 pts.push_back(Point(1,0));
126 pts.push_back(Point(1,1));
127 pts.push_back(Point(2,1));
128 pts.push_back(Point(3,1));
129 pts.push_back(Point(3,0));
130 pts.push_back(Point(4,0));
131 pts.push_back(Point(4,1));
132 pts.push_back(Point(4,2));
133 pts.push_back(Point(3,2));
134 pts.push_back(Point(2,2));
135 pts.push_back(Point(1,2));
136 pts.push_back(Point(0,2));
137 pts.push_back(Point(-1,2));
138 pts.push_back(Point(-2,2));
139 pts.push_back(Point(-2,1));
140 pts.push_back(Point(-2,0));
141 pts.push_back(Point(-1,0));
142
143 pts2.push_back(Point(1,1));
144 pts2.push_back(Point(3,1));
145 pts2.push_back(Point(3,0));
146 pts2.push_back(Point(4,0));
147 pts2.push_back(Point(4,2));
148 pts2.push_back(Point(-2,2));
149 pts2.push_back(Point(-2,0));
150 pts2.push_back(Point(1,0));
151
152 if(compare(pts, pts2))
153 nbok++;
154 nb++;
155
156 trace.info() << nbok << " / " << nb << std::endl;
157 }
158
159 { //inflection part, two distinct leaning points
160 std::vector<Point> pts, pts2;
161 pts.push_back(Point(0,0));
162 pts.push_back(Point(1,0));
163 pts.push_back(Point(1,1));
164 pts.push_back(Point(2,1));
165 pts.push_back(Point(3,1));
166 pts.push_back(Point(4,1));
167 pts.push_back(Point(4,0));
168 pts.push_back(Point(5,0));
169 pts.push_back(Point(5,1));
170 for (int i = 5; i >= -2; --i)
171 pts.push_back(Point(i,2));
172 pts.push_back(Point(-2,1));
173 pts.push_back(Point(-2,0));
174 pts.push_back(Point(-1,0));
175
176 pts2.push_back(Point(1,1));
177 pts2.push_back(Point(4,1));
178 pts2.push_back(Point(4,0));
179 pts2.push_back(Point(5,0));
180 pts2.push_back(Point(5,2));
181 pts2.push_back(Point(-2,2));
182 pts2.push_back(Point(-2,0));
183 pts2.push_back(Point(1,0));
184
185 if(compare(pts, pts2))
186 nbok++;
187 nb++;
188
189 trace.info() << nbok << " / " << nb << std::endl;
190 }
191
192 { //convex part, one leaning point
193 std::vector<Point> pts, pts2;
194 pts.push_back(Point(0,0));
195 pts.push_back(Point(1,0));
196 pts.push_back(Point(1,1));
197 pts.push_back(Point(2,1));
198 pts.push_back(Point(3,1));
199 pts.push_back(Point(3,2));
200 for (int i = 3; i >= -2; --i)
201 pts.push_back(Point(i,3));
202 pts.push_back(Point(-2,2));
203 pts.push_back(Point(-2,1));
204 pts.push_back(Point(-2,0));
205 pts.push_back(Point(-1,0));
206
207 //FP begins at the last leaning point of the first MS
208 pts2.push_back(Point(1,0));
209 pts2.push_back(Point(3,1));
210 pts2.push_back(Point(3,3));
211 pts2.push_back(Point(-2,3));
212 pts2.push_back(Point(-2,0));
213
214 if(compare(pts, pts2))
215 nbok++;
216 nb++;
217
218 trace.info() << nbok << " / " << nb << std::endl;
219 }
220
221 { //convex part, two distinct leaning points
222 std::vector<Point> pts, pts2;
223 pts.push_back(Point(0,0));
224 pts.push_back(Point(1,0));
225 pts.push_back(Point(1,1));
226 pts.push_back(Point(2,1));
227 pts.push_back(Point(3,1));
228 pts.push_back(Point(3,2));
229 for (int i = 3; i >= -1; --i)
230 pts.push_back(Point(i,3));
231 pts.push_back(Point(-1,2));
232 pts.push_back(Point(-1,1));
233 pts.push_back(Point(-1,0));
234
235 //FP begins at the last leaning point of the first MS
236 pts2.push_back(Point(3,1));
237 pts2.push_back(Point(3,3));
238 pts2.push_back(Point(-1,3));
239 pts2.push_back(Point(-1,0));
240 pts2.push_back(Point(1,0));
241
242 if(compare(pts, pts2))
243 nbok++;
244 nb++;
245
246 trace.info() << nbok << " / " << nb << std::endl;
247 }
248 trace.endBlock();
249
250 return (nb == nbok);
251}
MyPointD Point
Definition: testClone2.cpp:383
bool compare(const Range1 &pts, const Range2 &groundTruth)
Definition: testFP.cpp:98

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

Referenced by main().

◆ testFP()

bool testFP ( string  filename)

Test

Definition at line 56 of file testFP.cpp.

57{
58
59 using namespace DGtal;
60
61 trace.info() << endl;
62 trace.info() << "Reading GridCurve from " << filename << endl;
63
64 ifstream instream; // input stream
65 instream.open (filename.c_str(), ifstream::in);
66
67 //range of points
68 typedef int Coordinate;
69 typedef KhalimskySpaceND<2,Coordinate> Kspace; //space
70 GridCurve<Kspace> c; //building grid curve
71 c.initFromVectorStream(instream);
73 Range r = c.getPointsRange();//building range
74
75
76 //faithful polyon
77 trace.info() << "Building FP (process digital curve as";
78 trace.info() << ( (c.isClosed())?"closed":"open" ) << ")" << endl;
79
80 bool res = true;
81 if (c.isClosed())
82 {
84 FP theFP( r.c(), r.c() );
85 res = theFP.isValid();
86 }
87 else
88 {
90 FP theFP( r.begin(), r.end() );
91 res = theFP.isValid();
92 }
93 return res;
94
95}
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
bool initFromVectorStream(std::istream &in)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...

References DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), and DGtal::FP< TIterator, TInteger, connectivity >::isValid().

Referenced by main().