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"
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;;
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);
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);
380 (P2 ==
Point(9,10) ) && ( P3 ==
Point(10,9) ) ;
381 nbOk += (
test) ? 1 : 0;
382 trace.
info() <<
"Test 3 " << ((
test) ?
"passed" :
"failed" ) << endl;
395 nbOk += (
test) ? 1 : 0;
396 trace.
info() <<
"Test 4 " << ((
test) ?
"passed" :
"failed" ) << endl;
416 nbOk += (
test) ? 1 : 0;
417 trace.
info() <<
"Test 5 " << ((
test) ?
"passed" :
"failed" ) << endl;
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;
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;
474 ( outer2inner == pl2pixExpected ) &&
475 ( inner2outer == pix2plExpected );
476 nbOk += (
test) ? 1 : 0;
477 trace.
info() <<
"Test 8 " << ((
test) ?
"passed" :
"failed" ) << endl;
486 numVector c2clean, clean2c;
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;
530 fst.open ((testPath +
"samples/contourS.fc").c_str() , ios::in);
539 std::string filenameImage = testPath +
"samples/contourS.png";
541 image.shiftDepth(500);
566int 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
static void write(std::ostream &out, const FreemanChain &c)
ConstIterator end() const
static void displacement(int &dx, int &dy, char aCode)
ConstIterator begin() const
CodesRange getCodesRange()
static char addToCode(char code, int n)
Vector totalDisplacement() const
static void innerContour(FreemanChain &aInnerChain, std::vector< unsigned int > &aOuter2inner, std::vector< unsigned int > &aInner2outer, const FreemanChain &aOuterChain, bool ccw=true)
Self::ConstIterator findQuadrantChange(OrderedAlphabet &A) const
FreemanChain & retract(Size n=1)
Point getPoint(Index pos) const
static void read(std::istream &in, FreemanChain &c)
static void getContourPoints(const FreemanChain &fc, std::vector< Point > &aVContour)
static void pointel2pixel(FreemanChain &aPixChain, std::vector< unsigned int > &aPl2pix, std::vector< unsigned int > &aPix2pl, const FreemanChain &aPlChain)
Self::ConstIterator findQuadrantChange4(OrderedAlphabet &A) const
FreemanChain & extend(char code)
static void movePointFromFC(Point &aPoint, char aCode)
FreemanChain subChain(Index pos, Size n) const
static char movement(char aCode1, char aCode2, bool ccw=true)
static bool cleanOuterSpikes(FreemanChain &aCleanC, std::vector< unsigned int > &aC2clean, std::vector< unsigned int > &aClean2c, const FreemanChain &c, bool ccw=true)
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()
HyperRectDomain< Space2Type > Domain2D
bool testStaticServices()
bool testPublicSercives()
bool testPointsIterators()
SpaceND< 2, int > Space2Type
bool test(const I &itb, const I &ite)