45 #include "DGtal/base/Common.h"
46 #include "DGtal/base/Exceptions.h"
47 #include "DGtal/kernel/SpaceND.h"
48 #include "DGtal/kernel/domains/HyperRectDomain.h"
49 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
50 #include "DGtal/io/boards/Board2D.h"
52 #include "DGtal/geometry/curves/CBidirectionalSegmentComputer.h"
53 #include "DGtal/io/boards/CDrawableWithBoard2D.h"
55 using namespace DGtal;
57 using namespace LibBoard;
66 bool testDSS4drawing()
70 typedef std::vector<Point>::iterator Iterator;
73 std::vector<Point> contour;
74 contour.push_back(Point(0,0));
75 contour.push_back(Point(1,0));
76 contour.push_back(Point(1,1));
77 contour.push_back(Point(2,1));
78 contour.push_back(Point(2,1));
79 contour.push_back(Point(3,1));
80 contour.push_back(Point(3,2));
81 contour.push_back(Point(4,2));
82 contour.push_back(Point(5,2));
83 contour.push_back(Point(6,2));
84 contour.push_back(Point(6,3));
85 contour.push_back(Point(6,4));
89 trace.
beginBlock(
"Add points while it is possible and draw the result");
92 theDSS4.init( contour.begin() );
93 trace.
info() << theDSS4 <<
" " << theDSS4.isValid() << std::endl;
95 while ( (theDSS4.end() != contour.end())
96 &&(theDSS4.extendForward()) ) {}
98 trace.
info() << theDSS4 <<
" " << theDSS4.isValid() << std::endl;
103 board.
setUnit(Board::UCentimeter);
105 board <<
SetMode(domain.className(),
"Grid")
107 board <<
SetMode(
"PointVector",
"Grid");
109 board <<
SetMode(theDSS4.className(),
"Points")
111 board <<
SetMode(theDSS4.className(),
"BoundingBox")
126 bool testDSS8drawing()
130 typedef std::vector<Point>::iterator Iterator;
133 std::vector<Point> boundary;
134 boundary.push_back(Point(0,0));
135 boundary.push_back(Point(1,1));
136 boundary.push_back(Point(2,1));
137 boundary.push_back(Point(3,2));
138 boundary.push_back(Point(4,2));
139 boundary.push_back(Point(5,2));
140 boundary.push_back(Point(6,3));
141 boundary.push_back(Point(6,4));
144 trace.
beginBlock(
"Add points while it is possible and draw the result");
146 theDSS8.init( boundary.begin() );
148 trace.
info() << theDSS8 <<
" " << theDSS8.isValid() << std::endl;
152 while ( (theDSS8.end()!=boundary.end())
153 &&(theDSS8.extendForward()) ) {}
155 trace.
info() << theDSS8 <<
" " << theDSS8.isValid() << std::endl;
162 board.
setUnit(Board::UCentimeter);
165 board <<
SetMode(domain.className(),
"Paving")
167 board <<
SetMode(
"PointVector",
"Both");
169 board <<
SetMode(theDSS8.className(),
"Points")
171 board <<
SetMode(theDSS8.className(),
"BoundingBox")
188 bool testExtendretractForward()
193 typedef std::vector<Point>::iterator Iterator;
197 std::vector<Point> contour;
198 contour.push_back(Point(0,0));
199 contour.push_back(Point(1,0));
200 contour.push_back(Point(1,1));
201 contour.push_back(Point(2,1));
202 contour.push_back(Point(3,1));
203 contour.push_back(Point(3,2));
204 contour.push_back(Point(4,2));
205 contour.push_back(Point(5,2));
206 contour.push_back(Point(6,2));
207 contour.push_back(Point(6,3));
208 contour.push_back(Point(6,4));
213 std::deque<DSS4 > v1,v2;
215 newDSS4.init(contour.begin());
216 v1.push_back(newDSS4);
219 trace.
info() <<
"forward scan" << std::endl;
221 while ( (newDSS4.end() != contour.end())
222 &&(newDSS4.extendForward()) ) {
223 v1.push_back(newDSS4);
227 trace.
info() <<
"backward scan" << std::endl;
229 Iterator i(newDSS4.end());
234 while ( (reverseDSS4.begin()!=contour.begin())
235 &&(reverseDSS4.extendBackward()) ) {
237 reverseDSS4.extendBackward(contour.begin());
242 v2.push_front(reverseDSS4);
243 while (reverseDSS4.retractBackward()) {
244 v2.push_front(reverseDSS4);
249 trace.
info() <<
"comparison" << std::endl;
250 trace.
info() << v1.size() <<
" == " << v2.size() << std::endl;
251 ASSERT(v1.size() == v2.size());
254 for (
unsigned int k = 0; k < v1.size(); k++) {
255 if (v1.at(k) != v2.at(k)) isOk =
false;
256 trace.
info() <<
"DSS4 :" << k << std::endl;
258 trace.
info() << v1.at(k) << v2.at(k) << std::endl;
262 if (isOk)
trace.
info() <<
"ok for the " << v1.size() <<
" DSS4" << std::endl;
263 else trace.
info() <<
"failure" << std::endl;
271 #ifdef WITH_BIGINTEGER
276 bool testBIGINTEGER()
281 typedef DGtal::BigInteger Coordinate;
283 typedef std::vector<Point>::iterator Iterator;
290 std::vector<Point> contour;
291 contour.push_back(Point(1000000000,1000000000));
292 contour.push_back(Point(1000000001,1000000000));
293 contour.push_back(Point(1000000002,1000000000));
294 contour.push_back(Point(1000000003,1000000000));
295 contour.push_back(Point(1000000003,1000000001));
296 contour.push_back(Point(1000000004,1000000001));
297 contour.push_back(Point(1000000005,1000000001));
298 contour.push_back(Point(1000000005,1000000002));
301 theDSS4.init( contour.begin() );
302 while ( (theDSS4.end() != contour.end())
303 &&(theDSS4.extendForward()) ) {}
305 trace.
info() << theDSS4 <<
" " << theDSS4.isValid() << std::endl;
309 if( (theDSS4.getA() == 2)
310 &&(theDSS4.getB() == 5)
311 &&(theDSS4.getMu() == mu)
312 &&(theDSS4.getOmega() == 7) ) {
334 typedef std::vector<Point>::iterator Iterator;
337 std::vector<Point> boundary;
338 boundary.push_back(Point(10,10));
339 boundary.push_back(Point(10,11));
340 boundary.push_back(Point(11,11));
344 theDSS8.init(boundary.begin());
345 theDSS8.extendForward();
346 return ( !theDSS8.extendForward() );
352 void testArithDSSConceptChecking()
355 typedef std::vector<Point>::iterator Iterator;
362 int main(
int argc,
char **argv)
367 for (
int i = 0; i < argc; ++i )
373 testArithDSSConceptChecking();
376 bool res = testDSS4drawing()
378 && testExtendretractForward()
380 #ifdef WITH_BIGINTEGER
384 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;