34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/base/Common.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "DGtal/geometry/curves/FreemanChain.h"
38 #include "DGtal/kernel/domains/HyperRectDomain.h"
39 #include "DGtal/io/boards/Board2D.h"
40 #include "ConfigTest.h"
45 using namespace DGtal;
65 trace.
info() <<
"Constructor from string and coordinates" << endl;
66 std::string s =
"00001030003222321222";
69 trace.
info() <<
"Constructor from point vector" << endl;
70 std::vector<Space2Type::Point> myVector;
71 for (Iterator i = c1.
begin(); i != c1.
end(); i++)
72 myVector.push_back(*i);
75 trace.
info() <<
"Constructor from input stream" << endl;
77 ss <<
"-42 12 " << s <<
"\n";
80 trace.
info() <<
"Copy constructor" << endl;
97 (c1 == c2) && (c1 == c3) && (c1 == c4) && (c1 == c5) && (c1 != c6)
98 && (c2 == c1) && (c2 == c3) && (c2 == c4) && (c2 == c5) && (c2 != c6)
99 && (c3 == c1) && (c3 == c2) && (c3 == c4) && (c3 == c5) && (c3 != c6)
100 && (c4 == c1) && (c4 == c2) && (c4 == c3) && (c4 == c5) && (c4 != c6)
101 && (c5 == c1) && (c5 == c2) && (c5 == c3) && (c5 == c4) && (c4 != c6)
102 && (c6 != c1) && (c6 != c2) && (c6 != c3) && (c6 != c4) && (c6 != c5)
126 nbOk += (
test) ? 1 : 0;
127 trace.
info() <<
"Test 1 " << ((
test) ?
"passed" :
"failed" ) << endl;
131 nbOk += (
test) ? 1 : 0;
132 trace.
info() <<
"Test 2 " << ((
test) ?
"passed" :
"failed" ) << endl;
136 nbOk += (
test) ? 1 : 0;
137 trace.
info() <<
"Test 3 " << ((
test) ?
"passed" :
"failed" ) << endl;
147 nbOk += (
test) ? 1 : 0;
148 trace.
info() <<
"Test 4 " << ((
test) ?
"passed" :
"failed" ) << endl;
152 int min_x, min_y, max_x, max_y;
154 test = ( (min_x == 0) && (min_y == -2) && (max_x == 7) && (max_y == 1) );
155 nbOk += (
test) ? 1 : 0;
156 trace.
info() <<
"Test 5 " << ((
test) ?
"passed" :
"failed" ) << endl;
162 test = ( it.position() == 4 );
163 nbOk += (
test) ? 1 : 0;
164 trace.
info() <<
"Test 6 " << ((
test) ?
"passed" :
"failed" ) << endl;
169 test = ( it.position() == 9 );
170 nbOk += (
test) ? 1 : 0;
171 trace.
info() <<
"Test 7 " << ((
test) ?
"passed" :
"failed" ) << endl;
175 nbOk += (
test) ? 1 : 0;
176 trace.
info() <<
"Test 8 " << ((
test) ?
"passed" :
"failed" ) << endl;
184 nbOk += (
test) ? 1 : 0;
185 trace.
info() <<
"Test 9 " << ((
test) ?
"passed" :
"failed" ) << endl;
192 for (
unsigned int i=0; i <= fc.
size(); ++i, ++it)
197 nbOk += (
test) ? 1 : 0;
198 trace.
info() <<
"Test 10 " << ((
test) ?
"passed" :
"failed" ) << endl;
204 nbOk += (
test) ? 1 : 0;
205 trace.
info() <<
"Test 11 " << ((
test) ?
"passed" :
"failed" ) << endl;
214 nbOk += (
test) ? 1 : 0;
215 trace.
info() <<
"Test 12 " << ((
test) ?
"passed" :
"failed" ) << endl;
219 return ( nbOk == 12);
231 typedef int Coordinate;
239 std::stringstream ss;
240 std::string myString =
"0 0 000011112222333";
241 ss << myString << std::endl;
244 trace.
info()<<
"Freeman chain set to " << myString << endl;
247 trace.
info()<<
"Iterates on points." << endl;
248 std::stack<Point> myStack;
250 unsigned int nbPts = 0;
251 for (PointIterator i = seq.
begin(); i != seq.
end(); ++i)
257 trace.
info()<<
"Test reverse iterator." << endl;
258 bool samePoints =
true;
263 if ( !myStack.empty() && ( *ri == myStack.top() ) )
274 return myStack.empty() && samePoints && ( nbPts == seq.
size() + 1);
282 typedef int Coordinate;
290 std::stringstream ss;
291 std::string myString =
"0 0 000011112222333";
292 ss << myString << std::endl;
295 trace.
info()<<
"Freeman chain set to " << myString << endl;
300 trace.
info()<<
"Iterates on letters." << endl;
301 std::stack<char> myStack;
303 unsigned int nbLetters = 0;
310 trace.
info()<<
"Test reverse iterator." << endl;
311 bool samePoints =
true;
316 if ( !myStack.empty() && ( *ri == myStack.top() ) )
327 return myStack.empty() && samePoints && ( nbLetters == seq.
size() );
337 typedef std::vector<unsigned int> numVector;
345 std::string s1(
"0001");
348 stringstream ss1, ss2;
349 ss1 << x0 <<
" " << y0 <<
" " << s1 << std::endl;;
351 FreemanChain::read(ss1, f);
352 FreemanChain::write(ss2, f);
356 test = (x == x0) && (y == y0) && (s1 == s2);
357 nbOk += (
test) ? 1 : 0;
358 trace.
info() <<
"Test 1 " << ((
test) ?
"passed" :
"failed" ) << endl;
362 Point p0, p1(-1,-1), p2(0,-1), p3(1,-1), p4(2,-1), p5(2,0);
363 vector<Point> pointVecRef, pointVecTest;
364 pointVecRef.push_back(p1);
365 pointVecRef.push_back(p2);
366 pointVecRef.push_back(p3);
367 pointVecRef.push_back(p4);
368 pointVecRef.push_back(p5);
369 FreemanChain::getContourPoints( f, pointVecTest );
370 test = pointVecRef == pointVecTest;
371 nbOk += (
test) ? 1 : 0;
372 trace.
info() <<
"Test 2 " << ((
test) ?
"passed" :
"failed" ) << endl;
376 Point P0(10,10), P1(10,10), P2(10,10), P3(10,10);
377 FreemanChain::movePointFromFC( P0,
'0'); FreemanChain::movePointFromFC( P1,
'1');
378 FreemanChain::movePointFromFC( P2,
'2'); FreemanChain::movePointFromFC( P3,
'3');
380 (P2 ==
Point(9,10) ) && ( P3 ==
Point(10,9) ) ;
381 nbOk += (
test) ? 1 : 0;
382 trace.
info() <<
"Test 3 " << ((
test) ?
"passed" :
"failed" ) << endl;
387 test = ( FreemanChain::movement (
'0' ,
'0' ,
true ) ==
'2' ) &&
388 ( FreemanChain::movement (
'0' ,
'1' ,
true ) ==
'1' ) &&
389 ( FreemanChain::movement (
'0' ,
'2' ,
true ) ==
'0' ) &&
390 ( FreemanChain::movement (
'0' ,
'3' ,
true ) ==
'3' ) &&
391 ( FreemanChain::movement (
'0' ,
'0' ,
false ) ==
'2' ) &&
392 ( FreemanChain::movement (
'0' ,
'1' ,
false ) ==
'3' ) &&
393 ( FreemanChain::movement (
'0' ,
'2' ,
false ) ==
'0' ) &&
394 ( FreemanChain::movement (
'0' ,
'3' ,
false ) ==
'1' );
395 nbOk += (
test) ? 1 : 0;
396 trace.
info() <<
"Test 4 " << ((
test) ?
"passed" :
"failed" ) << endl;
399 test = ( FreemanChain::addToCode(
'0' , 1 ) ==
'1' ) &&
400 ( FreemanChain::addToCode(
'1' , 1 ) ==
'2' ) &&
401 ( FreemanChain::addToCode(
'2' , 1 ) ==
'3' ) &&
402 ( FreemanChain::addToCode(
'3' , 1 ) ==
'0' ) &&
403 ( FreemanChain::addToCode(
'0' , -1 ) ==
'3' ) &&
404 ( FreemanChain::addToCode(
'1' , -1 ) ==
'0' ) &&
405 ( FreemanChain::addToCode(
'2' , -1 ) ==
'1' ) &&
406 ( FreemanChain::addToCode(
'3' , -1 ) ==
'2' ) &&
407 ( FreemanChain::addToCode(
'1' , 0 ) ==
'1' ) &&
408 ( FreemanChain::addToCode(
'1' , 2 ) ==
'3' ) &&
409 ( FreemanChain::addToCode(
'1' , 3 ) ==
'0' ) &&
410 ( FreemanChain::addToCode(
'1' , 4 ) ==
'1' ) &&
411 ( FreemanChain::addToCode(
'1' , 5 ) ==
'2' ) &&
412 ( FreemanChain::addToCode(
'1' , -2 ) ==
'3' ) &&
413 ( FreemanChain::addToCode(
'1' , -3 ) ==
'2' ) &&
414 ( FreemanChain::addToCode(
'1' , -4 ) ==
'1' ) &&
415 ( FreemanChain::addToCode(
'1' , -5 ) ==
'0' );
416 nbOk += (
test) ? 1 : 0;
417 trace.
info() <<
"Test 5 " << ((
test) ?
"passed" :
"failed" ) << endl;
423 FreemanChain::displacement( X[0] , Y[0],
'0');
424 FreemanChain::displacement( X[1] , Y[1],
'1');
425 FreemanChain::displacement( X[2] , Y[2],
'2');
426 FreemanChain::displacement( X[3] , Y[3],
'3');
428 p0 = FreemanChain::displacement(
'0' );
429 p1 = FreemanChain::displacement(
'1' );
430 p2 = FreemanChain::displacement(
'2' );
431 p3 = FreemanChain::displacement(
'3' );
433 test = (X[0] == 1) && (Y[0] == 0) && (p0 ==
Point( 1, 0)) &&
434 (X[1] == 0) && (Y[1] == 1) && (p1 ==
Point( 0, 1)) &&
435 (X[2] == -1) && (Y[2] == 0) && (p2 ==
Point(-1, 0)) &&
436 (X[3] == 0) && (Y[3] == -1) && (p3 ==
Point( 0,-1)) ;
437 nbOk += (
test) ? 1 : 0;
438 trace.
info() <<
"Test 6 " << ((
test) ?
"passed" :
"failed" ) << endl;
446 numVector pl2pix, pix2pl;
448 FreemanChain::pointel2pixel( pixChain, pl2pix, pix2pl, f );
449 numVector pl2pixExpected;
450 pl2pixExpected.push_back( 0 ); pl2pixExpected.push_back( 1 ); pl2pixExpected.push_back( 2 );
451 pl2pixExpected.push_back( 2 ); pl2pixExpected.push_back( 3 ); pl2pixExpected.push_back( 3 );
452 pl2pixExpected.push_back( 3 ); pl2pixExpected.push_back( 5 ); pl2pixExpected.push_back( 7 );
453 pl2pixExpected.push_back( 7 ); pl2pixExpected.push_back( 7 ); pl2pixExpected.push_back( 8 );
454 numVector pix2plExpected;
455 pix2plExpected.push_back( 0 ); pix2plExpected.push_back( 1 ); pix2plExpected.push_back( 3 );
456 pix2plExpected.push_back( 6 ); pix2plExpected.push_back( 7 ); pix2plExpected.push_back( 7 );
457 pix2plExpected.push_back( 8 ); pix2plExpected.push_back( 10 );
459 ( pl2pix == pl2pixExpected ) &&
460 ( pix2pl == pix2plExpected );
461 nbOk += (
test) ? 1 : 0;
462 trace.
info() <<
"Test 7 " << ((
test) ?
"passed" :
"failed" ) << endl;
471 numVector outer2inner, inner2outer;
472 FreemanChain::innerContour ( innerChain, outer2inner, inner2outer, f,
true);
474 ( outer2inner == pl2pixExpected ) &&
475 ( inner2outer == pix2plExpected );
476 nbOk += (
test) ? 1 : 0;
477 trace.
info() <<
"Test 8 " << ((
test) ?
"passed" :
"failed" ) << endl;
486 numVector c2clean, clean2c;
488 bool cleaned = FreemanChain::cleanOuterSpikes( cleanC, c2clean, clean2c, c,
true );
490 numVector c2cleanExpected;
491 c2cleanExpected.push_back( 5 ); c2cleanExpected.push_back( 6 ); c2cleanExpected.push_back( 7 );
492 c2cleanExpected.push_back( 8 ); c2cleanExpected.push_back( 9 ); c2cleanExpected.push_back(10 );
493 c2cleanExpected.push_back(11 ); c2cleanExpected.push_back(12 ); c2cleanExpected.push_back(13 );
494 c2cleanExpected.push_back( 0 ); c2cleanExpected.push_back( 1 ); c2cleanExpected.push_back( 2 );
495 c2cleanExpected.push_back( 2 ); c2cleanExpected.push_back( 2 ); c2cleanExpected.push_back( 3 );
496 c2cleanExpected.push_back( 4 );
497 numVector clean2cExpected;
498 clean2cExpected.push_back( 9 ); clean2cExpected.push_back(10 ); clean2cExpected.push_back(13 );
499 clean2cExpected.push_back(14 ); clean2cExpected.push_back(15 ); clean2cExpected.push_back( 0 );
500 clean2cExpected.push_back( 1 ); clean2cExpected.push_back( 2 ); clean2cExpected.push_back( 3 );
501 clean2cExpected.push_back( 4 ); clean2cExpected.push_back( 5 ); clean2cExpected.push_back( 6 );
502 clean2cExpected.push_back( 7 ); clean2cExpected.push_back( 8 );
503 test = cleaned && (cleanC == cleanCExpected) && (c2clean == c2cleanExpected)
504 && (clean2c == clean2cExpected);
505 nbOk += (
test) ? 1 : 0;
506 trace.
info() <<
"Test 9 " << ((
test) ?
"passed" :
"failed" ) << endl;
507 trace.
info() <<
"All tests="<<nbOk<<std::endl;
527 aBoard.
setUnit(Board::UCentimeter);
530 fst.open ((testPath +
"samples/contourS.fc").c_str() , ios::in);
539 std::string filenameImage = testPath +
"samples/contourS.png";
541 image.shiftDepth(500);
545 aBoard.
saveSVG(
"testDisplayFC.svg", Board::BoundingBox, 5000 );
546 aBoard.
saveEPS(
"testDisplayFC.eps", Board::BoundingBox, 5000 );
547 aBoard.
saveFIG(
"testDisplayFC.fig", Board::BoundingBox, 5000 );
550 aBoard.
saveCairo(
"testDisplayFC-cairo.pdf", Board2D::CairoPDF, Board::BoundingBox, 5000);
551 aBoard.
saveCairo(
"testDisplayFC-cairo.png", Board2D::CairoPNG, Board::BoundingBox, 5000);
552 aBoard.
saveCairo(
"testDisplayFC-cairo.ps", Board2D::CairoPS, Board::BoundingBox, 5000);
553 aBoard.
saveCairo(
"testDisplayFC-cairo.svg", Board2D::CairoSVG, Board::BoundingBox, 5000);
566 int main(
int argc,
char** argv )
570 for (
int i = 0; i < argc; ++i )
582 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: model of CRange that provides services to (circularly)iterate over the letters of the freeman ch...
void computeBoundingBox(TInteger &min_x, TInteger &min_y, TInteger &max_x, TInteger &max_y) const
char code(Index pos) const
ConstIterator end() const
ConstIterator begin() const
CodesRange getCodesRange()
FreemanChain & extend(char code)
Vector totalDisplacement() const
FreemanChain & retract(Size n=1)
Self::ConstIterator findQuadrantChange(OrderedAlphabet &A) const
Point getPoint(Index pos) const
Self::ConstIterator findQuadrantChange4(OrderedAlphabet &A) const
FreemanChain subChain(Index pos, Size n) const
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: Describes an alphabet over an interval of (ascii) letters, where the lexicographic order can be ...
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa.
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
TConstIterator ConstIterator
std::reverse_iterator< ConstIterator > ConstReverseIterator
void beginBlock(const std::string &keyword="")
Class for EPS, FIG or SVG drawings.
Board & setPenColor(const DGtal::Color &color)
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
DGtal is the top-level namespace which contains all DGtal functions and types.
Used to draw image in figure.
Struct representing a 2D point.
bool testCodesIterators()
int main(int argc, char **argv)
HyperRectDomain< Space2Type > Domain2D
bool testStaticServices()
bool testPublicSercives()
bool testPointsIterators()
SpaceND< 2, int > Space2Type
bool test(const I &itb, const I &ite)