54 unsigned int nbok = 0;
59 trace.
beginBlock (
"Testing convexhull and boxes of alpha-thick segment on noisy discrete contour." );
60 std::vector<Z2i::Point> aContour;
61 std::string fileContour = testPath +
"samples/contourNoiseSample.sdp";
64 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer(5);
65 anAlphaThickSegmentComputer.init(aContour.begin());
66 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer2(10);
67 anAlphaThickSegmentComputer2.init(aContour.begin());
68 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer3(2);
69 anAlphaThickSegmentComputer3.init(aContour.begin());
70 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer4(1);
71 anAlphaThickSegmentComputer4.init(aContour.begin());
74 while (anAlphaThickSegmentComputer.end() != aContour.end() &&
75 anAlphaThickSegmentComputer.extendFront()){}
76 while (anAlphaThickSegmentComputer2.end() != aContour.end() &&
77 anAlphaThickSegmentComputer2.extendFront() ){}
78 while (anAlphaThickSegmentComputer3.end() != aContour.end() &&
79 anAlphaThickSegmentComputer3.extendFront()){}
80 while (anAlphaThickSegmentComputer4.end() != aContour.end() &&
81 anAlphaThickSegmentComputer4.extendFront()){}
87 for (AlphaThickSegmentComputer2D::ConvexhullConstIterator it = anAlphaThickSegmentComputer.convexhullBegin();
88 it != anAlphaThickSegmentComputer.convexhullEnd(); it++){
89 if ((it+1) != anAlphaThickSegmentComputer.convexhullEnd()){
95 (*(anAlphaThickSegmentComputer.convexhullBegin()))[0],
96 (*(anAlphaThickSegmentComputer.convexhullBegin()))[1]);
102 aBoard <<
SetMode((*anAlphaThickSegmentComputer.begin()).className(),
"Grid");
103 aBoard <<
CustomStyle( anAlphaThickSegmentComputer2.className(),
105 aBoard << anAlphaThickSegmentComputer2;
106 aBoard <<
CustomStyle( anAlphaThickSegmentComputer.className(),
108 aBoard << anAlphaThickSegmentComputer;
109 aBoard <<
CustomStyle( anAlphaThickSegmentComputer3.className(),
111 aBoard << anAlphaThickSegmentComputer3;
112 aBoard <<
CustomStyle( anAlphaThickSegmentComputer4.className(),
114 aBoard << anAlphaThickSegmentComputer4;
118 aBoard <<
SetMode((*aContour.begin()).className(),
"Grid");
119 for (std::vector<Z2i::Point>::const_iterator it = aContour.begin();
120 it != aContour.end(); it++){
122 if (it+1 != aContour.end()){
125 aBoard.
drawLine((*it)[0], (*it)[1], next[0], next[1]);
129 aBoard.
saveEPS(
"testAlphaThickSegmentComputer_Convexhull.eps");
130 trace.
info() <<
" Alpha Thick with alpha 5, size (awaited be 41) = " << anAlphaThickSegmentComputer.getNumberSegmentPoints();
131 res = anAlphaThickSegmentComputer.getNumberSegmentPoints()==41;
134 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
138 trace.
info() <<
"First extremity point: " << anAlphaThickSegmentComputer.getExtremityPoints().first <<
139 " ( should be " << *(aContour.begin())<<
")" << std::endl;
140 trace.
info() <<
"Second extremity point: " << anAlphaThickSegmentComputer.getExtremityPoints().second <<
141 " ( should be (80, 18) )" << std::endl;
143 res = anAlphaThickSegmentComputer.getExtremityPoints().first == *(aContour.begin())&&
144 anAlphaThickSegmentComputer.getExtremityPoints().second ==
Z2i::Point(80,18);
147 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
152 std::pair<std::pair<Z2i::Point, Z2i::Point>,
153 Z2i::Point> pairAntipodal = anAlphaThickSegmentComputer.getAntipodalLeaningPoints();
159 aBoard.
drawLine(p[0], p[1], q[0], q[1]);
161 aBoard.
saveEPS(
"testAlphaThickSegmentComputer_ConvexhullAntipodal.eps");
163 trace.
info() <<
"Antipodal pair: p " << p <<
", q:" << q <<
", s: "<< s << std::endl;
169 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
173 pairAntipodal = anAlphaThickSegmentComputer4.getAntipodalLeaningPoints();
174 p = pairAntipodal.first.first;
175 q = pairAntipodal.first.second;
176 s = pairAntipodal.second;
180 trace.
info() <<
"Segment4 params: vect Dir: " << vectDir << std::endl;
186 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
198 unsigned int nbok = 0;
204 trace.
beginBlock (
"Testing alpha-thick segment on contour composed of floating coords ..." );
205 std::vector<Z2i::RealPoint> aContour;
206 std::string fileContour = testPath +
"samples/contourNoiseSample2.sdp";
209 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer(2);
210 anAlphaThickSegmentComputer.init(aContour.begin()+10);
212 while (anAlphaThickSegmentComputer.end()!= aContour.end() &&
213 anAlphaThickSegmentComputer.extendFront()){
218 aBoard <<
SetMode((*anAlphaThickSegmentComputer.begin()).className(),
"Grid");
219 aBoard << anAlphaThickSegmentComputer;
223 Primitive pStrip = anAlphaThickSegmentComputer.primitive();
224 unsigned int nbInStrip = 0;
226 aBoard <<
SetMode((*aContour.begin()).className(),
"Grid");
227 for (std::vector<Z2i::RealPoint>::const_iterator it = aContour.begin();
228 it != aContour.end(); it++){
229 if (it+1 != aContour.end()){
233 aBoard.
drawLine((*it)[0], (*it)[1], next[0], next[1]);
240 trace.
info() <<
"Nb contour points in the segment parallel strip (awaited 32) = " << nbInStrip << std::endl;
242 nbok += nbInStrip==32;
245 nbok += anAlphaThickSegmentComputer.getNumberSegmentPoints()==31 ? 1 : 0;
248 trace.
info() <<
"Segment size (awaited 31): " << anAlphaThickSegmentComputer.getNumberSegmentPoints() << std::endl;
249 aBoard.
saveEPS(
"testAlphaThickSegmentComputer_FloatingPt.eps");
251 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
265 unsigned int nbok = 0;
274 trace.
beginBlock (
"Testing AlphaThickSegmentComputer2D on Freeman chain ..." );
277 std::string freemanChainFilename = testPath +
"samples/klokan.fc";
279 fst.open (freemanChainFilename.c_str(), ios::in);
285 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer(70.0);
286 anAlphaThickSegmentComputer.init(fc.
begin());
287 while (anAlphaThickSegmentComputer.end() != fc.
end() &&
288 anAlphaThickSegmentComputer.extendFront()){
293 aBoard <<
SetMode((*anAlphaThickSegmentComputer.begin()).className(),
"Grid");
294 aBoard << anAlphaThickSegmentComputer;
295 trace.
info() <<
"Segment size (awaited 642): " << anAlphaThickSegmentComputer.getNumberSegmentPoints() << std::endl;
296 nbok += anAlphaThickSegmentComputer.getNumberSegmentPoints()==642 ? 1 : 0;
300 unsigned int nbInStrip = 0;
301 AlphaThickSegmentComputer2D::Primitive parallelStrip = anAlphaThickSegmentComputer.primitive();
303 for(FCConstIterator it = fc.
begin(); it != fc.
end(); it++){
304 if(parallelStrip(*it)){
313 trace.
info() <<
"Nb contour points in the segment parallel strip (awaited 818) = " << nbInStrip << std::endl;
316 nbok += nbInStrip==818 ? 1 : 0;
319 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
321 aBoard.
saveEPS(
"testAlphaThickSegmentComputer_Freeman.eps");
333 unsigned int nbok = 0;
337 trace.
beginBlock (
"Test special cases on various initialisations ..." );
339 AlphaThickSegmentComputer2D segment(1.3);
340 std::vector<Z2i::RealPoint> aContour;
345 segment.init(aContour.begin());
346 segment.extendFront();
347 while (segment.end()!= aContour.end() &&
348 segment.extendFront()){
351 nbok = segment.getNumberSegmentPoints()==4;
354 for( std::vector<Z2i::RealPoint>::const_iterator it = aContour.begin(); it != aContour.end(); it++){
358 aBoard <<
SetMode((*segment.begin()).className(),
"Grid");
362 Z2i::Point p( segment.getAntipodalLeaningPoints().first.first, rounding_functor );
363 Z2i::Point q( segment.getAntipodalLeaningPoints().first.second, rounding_functor );
364 Z2i::Point s( segment.getAntipodalLeaningPoints().second, rounding_functor );
366 aBoard.
drawLine(p[0], p[1], q[0], q[1]);
369 aBoard.
saveEPS(
"testSpecialInit.eps");
371 trace.
info() <<
"Segment size: " << segment.getNumberSegmentPoints() <<
"(awaited : " << 4 <<
")"<< std::endl;
372 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
374 aBoard.
saveEPS(
"testSpecialInit.eps");
390 trace.
beginBlock (
"Testing alpha-thick segment with multi width ..." );
391 std::vector<Z2i::RealPoint> aContour;
392 std::string fileContour = testPath +
"samples/contourNoiseSample2.sdp";
396 unsigned int nbTotalAdded=0;
397 for (
double width=0.5; width<10; width+= 0.2, pos += 1) {
398 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer(width);
399 anAlphaThickSegmentComputer.init(aContour.begin()+pos);
401 while (anAlphaThickSegmentComputer.end()!= aContour.end() &&
402 anAlphaThickSegmentComputer.extendFront()){
405 aBoard <<
SetMode((*anAlphaThickSegmentComputer.begin()).className(),
"Grid");
407 aBoard <<
CustomStyle( anAlphaThickSegmentComputer.className(),
409 aBoard << anAlphaThickSegmentComputer;
411 trace.
info() <<
"Nb total points added: " << nbTotalAdded <<
"(awaited: 2300) " << std::endl;
413 aBoard.
saveEPS(
"testMultiWidth.eps");
415 nbok += nbTotalAdded == 2300;
433 trace.
beginBlock (
"Testing alpha-thick segment with different thickness definitions:" );
439 aBoardEuclthickness << adom;
440 aBoardHVthickness << adom;
442 std::vector<Z2i::Point> aVect;
456 aBoardEuclthickness <<
SetMode((*aVect.begin()).className(),
"Grid");
457 aBoardHVthickness <<
SetMode((*aVect.begin()).className(),
"Grid");
458 for (std::vector<Z2i::Point>::const_iterator it = aVect.begin();
459 it != aVect.end(); it++){
460 aBoardHVthickness << *it;
461 aBoardEuclthickness << *it;
462 if (it+1 != aVect.end()){
466 aBoardEuclthickness.
drawLine((*it)[0], (*it)[1], next[0], next[1]);
467 aBoardHVthickness.
drawLine((*it)[0], (*it)[1], next[0], next[1]);
471 anAlphaSegmentEucl.init(aVect.begin());
472 while(anAlphaSegmentEucl.end() != aVect.end()
473 && anAlphaSegmentEucl.extendFront()){
475 anAlphaSegmentHV.init(aVect.begin());
476 while(anAlphaSegmentHV.end() != aVect.end()
477 && anAlphaSegmentHV.extendFront()){
481 trace.
info() <<
"Euclidean thickness based segment, th= " << anAlphaSegmentEucl.getThickness() << std::endl;
482 trace.
info() <<
"Horizontal/Vertical thickness based segment, th= " << anAlphaSegmentHV.getThickness() << std::endl;
487 aBoardHVthickness << anAlphaSegmentHV;
488 aBoardEuclthickness << anAlphaSegmentEucl;
490 std::vector<Z2i::Point> hullHV = anAlphaSegmentHV.getConvexHull();
491 std::vector<Z2i::Point> hullEucl = anAlphaSegmentEucl.getConvexHull();
496 for (
unsigned int i = 0; i < hullEucl.size(); i++){
497 aBoardEuclthickness.
drawLine(hullEucl.at(i)[0], hullEucl.at(i)[1],
498 hullEucl.at((i+1)%hullEucl.size())[0],
499 hullEucl.at((i+1)%hullEucl.size())[1]);
501 for (
unsigned int i = 0; i < hullHV.size(); i++){
502 aBoardHVthickness.
drawLine(hullHV.at(i)[0], hullHV.at(i)[1],
503 hullHV.at((i+1)%hullHV.size())[0],
504 hullHV.at((i+1)%hullHV.size())[1]);
507 Z2i::Point pEucl = anAlphaSegmentEucl.getAntipodalLeaningPoints().first.first;
508 Z2i::Point qEucl = anAlphaSegmentEucl.getAntipodalLeaningPoints().first.second;
509 Z2i::Point sEucl = anAlphaSegmentEucl.getAntipodalLeaningPoints().second;
511 Z2i::Point pHV = anAlphaSegmentHV.getAntipodalLeaningPoints().first.first;
512 Z2i::Point qHV = anAlphaSegmentHV.getAntipodalLeaningPoints().first.second;
513 Z2i::Point sHV = anAlphaSegmentHV.getAntipodalLeaningPoints().second;
517 aBoardEuclthickness.
drawCircle( pEucl[0], pEucl[1], 0.25);
520 aBoardEuclthickness.
drawCircle( qEucl[0], qEucl[1], 0.25);
526 aBoardEuclthickness.
drawCircle( sEucl[0], sEucl[1], 0.25);
529 aBoardEuclthickness.
saveEPS(
"testAlphaThickEucl.eps");
530 aBoardHVthickness.
saveEPS(
"testAlphaThickHV.eps");