DGtal 1.4.0
Loading...
Searching...
No Matches
testFreemanChain.cpp File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/io/boards/Board2D.h"
#include "ConfigTest.h"
Include dependency graph for testFreemanChain.cpp:

Go to the source code of this file.

Typedefs

typedef SpaceND< 2, int > Space2Type
 
typedef HyperRectDomain< Space2TypeDomain2D
 

Functions

bool testConstructors ()
 
bool testPublicSercives ()
 
bool testPointsIterators ()
 
bool testCodesIterators ()
 
bool testStaticServices ()
 
bool testDisplay ()
 
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
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2010/07/05

Functions for testing class FreemanChain.

This file is part of the DGtal library.

Definition in file testFreemanChain.cpp.

Typedef Documentation

◆ Domain2D

Definition at line 52 of file testFreemanChain.cpp.

◆ Space2Type

typedef SpaceND<2,int> Space2Type

Definition at line 51 of file testFreemanChain.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 566 of file testFreemanChain.cpp.

567{
568 trace.beginBlock ( "Testing class FreemanChain" );
569 trace.info() << "Args:";
570 for ( int i = 0; i < argc; ++i )
571 trace.info() << " " << argv[ i ];
572 trace.info() << endl;
573
574 bool res =
580 testDisplay();
581
582 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
583
584 trace.endBlock();
585
586 return res ? 0 : 1;
587}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool testCodesIterators()
bool testDisplay()
bool testConstructors()
bool testStaticServices()
bool testPublicSercives()
bool testPointsIterators()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testCodesIterators(), testConstructors(), testDisplay(), testPointsIterators(), testPublicSercives(), testStaticServices(), and DGtal::trace.

◆ testCodesIterators()

bool testCodesIterators ( )

test codes iterators

Definition at line 280 of file testFreemanChain.cpp.

281{
282 typedef int Coordinate;
285// typedef Range::ConstIterator PointIterator;
286// typedef std::reverse_iterator<PointIterator> ReverseIterator;
287
288 trace.beginBlock ( "Testing CodesRange Iterator" );
289
290 std::stringstream ss;
291 std::string myString = "0 0 000011112222333";
292 ss << myString << std::endl;
293 FreemanChain seq(ss);
294
295 trace.info()<< "Freeman chain set to " << myString << endl;
296 trace.info()<< seq << endl;
297 Range r = seq.getCodesRange();
298 trace.info()<< r << endl;
299
300 trace.info()<< "Iterates on letters." << endl;
301 std::stack<char> myStack;
302
303 unsigned int nbLetters = 0;
304 for (Range::ConstIterator i = r.begin(); i != r.end(); ++i)
305 {
306 myStack.push(*i);
307 nbLetters++;
308 }
309
310 trace.info()<< "Test reverse iterator." << endl;
311 bool samePoints = true;
312 for (Range::ConstReverseIterator ri = r.rbegin();
313 ri != r.rend();
314 ++ri)
315 {
316 if ( !myStack.empty() && ( *ri == myStack.top() ) )
317 {
318 myStack.pop();
319 }
320 else
321 {
322 samePoints = false;
323 break;
324 }
325 }
326 trace.endBlock();
327 return myStack.empty() && samePoints && ( nbLetters == seq.size() );
328}
Aim: model of CRange that provides services to (circularly)iterate over the letters of the freeman ch...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
std::reverse_iterator< ConstIterator > ConstReverseIterator

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::FreemanChain< TInteger >::getCodesRange(), DGtal::Trace::info(), DGtal::FreemanChain< TInteger >::size(), and DGtal::trace.

Referenced by main().

◆ testConstructors()

bool testConstructors ( )

Test Constructors

Definition at line 58 of file testFreemanChain.cpp.

59{
61 typedef FreemanChain::ConstIterator Iterator;
62
63 trace.beginBlock ( "Testing FreemanChain constructors" );
64
65 trace.info() << "Constructor from string and coordinates" << endl;
66 std::string s = "00001030003222321222";
67 FreemanChain c1(s, -42, 12);
68
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);
73 FreemanChain c2(myVector);
74
75 trace.info() << "Constructor from input stream" << endl;
76 std::stringstream ss;
77 ss << "-42 12 " << s << "\n";
78 FreemanChain c3(ss);
79
80 trace.info() << "Copy constructor" << endl;
81 FreemanChain c4(c1);
82
83 trace.info() << "Copy operator" << endl;
84 FreemanChain c5("0123" , 0, 0);
85 FreemanChain c6(c5);
86
87 c5 = c1;
88
89 trace.info() << "c1 = " << c1 << endl;
90 trace.info() << "c2 = " << c2 << endl;
91 trace.info() << "c3 = " << c3 << endl;
92 trace.info() << "c4 = " << c4 << endl;
93 trace.info() << "c5 = " << c5 << endl;
94 trace.info() << "c6 = " << c6 << endl;
95
96 bool res = (
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)
103 );
104 trace.endBlock();
105 return res;
106}

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testDisplay()

bool testDisplay ( )

testDisplay

Definition at line 518 of file testFreemanChain.cpp.

519{
521 //typedef FreemanChain::Point Point;
522 //typedef FreemanChain::Vector Vector;
523 //typedef FreemanChain::ConstIterator Iterator;
524 //typedef std::vector<unsigned int> numVector;
525
526 Board2D aBoard;
528
529 fstream fst;
530 fst.open ((testPath + "samples/contourS.fc").c_str() , ios::in);
531 FreemanChain fc(fst);
532
533 aBoard.setPenColor(Color::Red);
534
535 //aBoard << DrawPavingPixel();
536
537 aBoard << fc;
538
539 std::string filenameImage = testPath + "samples/contourS.png"; // ! only PNG with Cairo for the moment !
540 LibBoard::Image image( 0, 84, 185, 85, filenameImage, 20 );
541 image.shiftDepth(500);
542 LibBoard::Board & board = aBoard;
543 board << image;
544
545 aBoard.saveSVG( "testDisplayFC.svg", Board::BoundingBox, 5000 );
546 aBoard.saveEPS( "testDisplayFC.eps", Board::BoundingBox, 5000 );
547 aBoard.saveFIG( "testDisplayFC.fig", Board::BoundingBox, 5000 );
548
549#ifdef WITH_CAIRO
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);
554#endif
555
556 return true;
557}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
static const Color Red
Definition Color.h:416
Class for EPS, FIG or SVG drawings.
Definition Board.h:35
Board & setPenColor(const DGtal::Color &color)
Definition Board.cpp:297
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition Board.cpp:906
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
void setUnit(Unit unit)
Definition Board.cpp:239
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1138
Used to draw image in figure.

References LibBoard::Board::BoundingBox, DGtal::Color::Red, LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveFIG(), LibBoard::Board::saveSVG(), LibBoard::Board::setPenColor(), LibBoard::Board::setUnit(), and LibBoard::Board::UCentimeter.

Referenced by main().

◆ testPointsIterators()

bool testPointsIterators ( )

test iterators

Definition at line 229 of file testFreemanChain.cpp.

230{
231 typedef int Coordinate;
234 typedef FreemanChain::ConstIterator PointIterator;
235 typedef std::reverse_iterator<PointIterator> ReverseIterator;
236
237 trace.beginBlock ( "Testing FreemanChain Iterator" );
238
239 std::stringstream ss;
240 std::string myString = "0 0 000011112222333";
241 ss << myString << std::endl;
242 FreemanChain seq(ss);
243
244 trace.info()<< "Freeman chain set to " << myString << endl;
245 trace.info()<< seq << endl;
246
247 trace.info()<< "Iterates on points." << endl;
248 std::stack<Point> myStack;
249
250 unsigned int nbPts = 0;
251 for (PointIterator i = seq.begin(); i != seq.end(); ++i)
252 {
253 myStack.push(*i);
254 nbPts++;
255 }
256
257 trace.info()<< "Test reverse iterator." << endl;
258 bool samePoints = true;
259 for (ReverseIterator ri(seq.end());
260 ri != ReverseIterator(seq.begin());
261 ++ri)
262 {
263 if ( !myStack.empty() && ( *ri == myStack.top() ) )
264 {
265 myStack.pop();
266 }
267 else
268 {
269 samePoints = false;
270 break;
271 }
272 }
273 trace.endBlock();
274 return myStack.empty() && samePoints && ( nbPts == seq.size() + 1);
275}
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa.
MyPointD Point

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::FreemanChain< TInteger >::size(), and DGtal::trace.

Referenced by main().

◆ testPublicSercives()

bool testPublicSercives ( )

Test public services

Definition at line 113 of file testFreemanChain.cpp.

114{
117 typedef FreemanChain::ConstIterator Iterator;
118
119 trace.beginBlock ( "Testing public sercives" );
120
121 FreemanChain fc("000103000322232122", 0, 0);
122 int nbOk = 0;
123
124 // unsigned int code( Index pos ) const;
125 bool test = ( fc.code(5) == '3' );
126 nbOk += (test) ? 1 : 0;
127 trace.info() << "Test 1 " << ((test) ? "passed" : "failed" ) << endl;
128
129 // Size size() const;
130 test = ( fc.size() == 18 );
131 nbOk += (test) ? 1 : 0;
132 trace.info() << "Test 2 " << ((test) ? "passed" : "failed" ) << endl;
133
134 // FreemanChain subChain( Index pos, Size n ) const;
135 test = ( fc.subChain(3, 3) == FreemanChain("103", 3, 0) );
136 nbOk += (test) ? 1 : 0;
137 trace.info() << "Test 3 " << ((test) ? "passed" : "failed" ) << endl;
138
139 // FreemanChain operator+(const FreemanChain& other) const;
140 // FreemanChain operator+=(const FreemanChain& other) const;
141 FreemanChain fcA("001",0,0);
142 FreemanChain fcB("001",0,0);
143 FreemanChain fcC("003",0,0);
144 fcB += fcC + fcB;
145 test = ( fcB == FreemanChain("001003001", 0, 0) ) &&
146 ( fcB.totalDisplacement() == fcA.totalDisplacement()*2 + fcC.totalDisplacement() );
147 nbOk += (test) ? 1 : 0;
148 trace.info() << "Test 4 " << ((test) ? "passed" : "failed" ) << endl;
149
150 // void computeBoundingBox( TInteger & min_x, TInteger& min_y,
151 // TInteger& max_x, TInteger& max_y ) const;
152 int min_x, min_y, max_x, max_y;
153 fc.computeBoundingBox( 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;
157
158 // typename Self::ConstIterator
159 // findQuadrantChange( OrderedAlphabet & A ) const;
160 OrderedAlphabet oa( '0', 4 );
161 Iterator it = fc.findQuadrantChange( oa );
162 test = ( it.position() == 4 );
163 nbOk += (test) ? 1 : 0;
164 trace.info() << "Test 6 " << ((test) ? "passed" : "failed" ) << endl;
165
166 // typename Self::ConstIterator
167 // findQuadrantChange4( OrderedAlphabet & A ) const;
168 it = fc.findQuadrantChange4( oa );
169 test = ( it.position() == 9 );
170 nbOk += (test) ? 1 : 0;
171 trace.info() << "Test 7 " << ((test) ? "passed" : "failed" ) << endl;
172
173 // int isClosed() const ;
174 test = ( ! fc.isClosed() && ( fc + FreemanChain("21") ).isClosed() );
175 nbOk += (test) ? 1 : 0;
176 trace.info() << "Test 8 " << ((test) ? "passed" : "failed" ) << endl;
177
178
179 // int ccwLoops() const;
180 test = ( FreemanChain("0001212323", 12, 21).ccwLoops() == 1 ) &&
181 ( FreemanChain("0003232121", 12, 21).ccwLoops() == -1 ) &&
182 ( FreemanChain("000323212", 12, 21).ccwLoops() == 0 ) &&
183 ( FreemanChain("012301230123", 12, 21).ccwLoops() == 3 );
184 nbOk += (test) ? 1 : 0;
185 trace.info() << "Test 9 " << ((test) ? "passed" : "failed" ) << endl;
186
187
188
189 // Point getPoint ( Index pos ) const;
190 it = fc.begin();
191 test = true;
192 for (unsigned int i=0; i <= fc.size(); ++i, ++it)
193 {
194 test = ( fc.getPoint(i) == *it );
195 if (!test) break;
196 }
197 nbOk += (test) ? 1 : 0;
198 trace.info() << "Test 10 " << ((test) ? "passed" : "failed" ) << endl;
199
200 // Point firstPoint ( ) const
201 // Point lastPoint ( ) const
202 test = ( ( fc.subChain(4,3).firstPoint() == Point(3,1) ) &&
203 ( fc.subChain(4,3).lastPoint() == Point(5,0) ) );
204 nbOk += (test) ? 1 : 0;
205 trace.info() << "Test 11 " << ((test) ? "passed" : "failed" ) << endl;
206
207 // FreemanChain & extend(char code);
208 // FreemanChain & retract(char code);
209 fcA = fc;
210 fcA.extend('2');
211 fcB = fcA.extend('1');
212 test = ( (fcB == fc + FreemanChain("21",0,0) ) && fcA.isClosed()
213 && ( fcB.retract().retract() == fc ) );
214 nbOk += (test) ? 1 : 0;
215 trace.info() << "Test 12 " << ((test) ? "passed" : "failed" ) << endl;
216
217 trace.endBlock();
218
219 return ( nbOk == 12);
220
221}
int ccwLoops() const
Aim: Describes an alphabet over an interval of (ascii) letters, where the lexicographic order can be ...
bool test(const I &itb, const I &ite)

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::ccwLoops(), DGtal::FreemanChain< TInteger >::code(), DGtal::FreemanChain< TInteger >::computeBoundingBox(), DGtal::Trace::endBlock(), DGtal::FreemanChain< TInteger >::extend(), DGtal::FreemanChain< TInteger >::findQuadrantChange(), DGtal::FreemanChain< TInteger >::findQuadrantChange4(), DGtal::FreemanChain< TInteger >::firstPoint(), DGtal::FreemanChain< TInteger >::getPoint(), DGtal::Trace::info(), DGtal::FreemanChain< TInteger >::isClosed(), DGtal::FreemanChain< TInteger >::lastPoint(), DGtal::FreemanChain< TInteger >::retract(), DGtal::FreemanChain< TInteger >::size(), DGtal::FreemanChain< TInteger >::subChain(), test(), DGtal::FreemanChain< TInteger >::totalDisplacement(), and DGtal::trace.

Referenced by main().

◆ testStaticServices()

bool testStaticServices ( )

Test static services

Definition at line 333 of file testFreemanChain.cpp.

334{
337 typedef std::vector<unsigned int> numVector;
338 bool test = false;
339 int nbOk = 0;
340
341 trace.beginBlock ( "Testing static services" );
342
343 // static void write( std::ostream & out, const FreemanChain & c )
344 // static void read( std::istream & in, FreemanChain & c );
345 std::string s1("0001");
346 int x0 = -1;
347 int y0 = -1;
348 stringstream ss1, ss2;
349 ss1 << x0 << " " << y0 << " " << s1 << std::endl;;
350 FreemanChain f;
351 FreemanChain::read(ss1, f);
352 FreemanChain::write(ss2, f);
353 int x, y;
354 std::string s2;
355 ss2 >> x >> y >> s2;
356 test = (x == x0) && (y == y0) && (s1 == s2);
357 nbOk += (test) ? 1 : 0;
358 trace.info() << "Test 1 " << ((test) ? "passed" : "failed" ) << endl;
359
360 // static void getContourPoints(const FreemanChain & fc,
361 // std::vector<Point> & aVContour );
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;
373
374
375 // static void movePointFromFC(Point & aPoint, unsigned int aCode )
376 Point P0(10,10), P1(10,10), P2(10,10), P3(10,10);
379 test = ( P0 == Point(11,10) ) && ( P1 == Point(10,11) ) &&
380 (P2 == Point(9,10) ) && ( P3 == Point(10,9) ) ;
381 nbOk += (test) ? 1 : 0;
382 trace.info() << "Test 3 " << ((test) ? "passed" : "failed" ) << endl;
383
384
385 // static unsigned int movement( unsigned int aCode1, unsigned int aCode2,
386 // bool ccw = true );
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;
397
398 // static char addToCode( char code, int n);
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;
418
419
420 // static void displacement( int & dx, int & dy, unsigned int aCode );
421 // static Point displacement( unsigned int aCode );
422 int X[4], Y[4];
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');
427
428 p0 = FreemanChain::displacement( '0' );
429 p1 = FreemanChain::displacement( '1' );
430 p2 = FreemanChain::displacement( '2' );
431 p3 = FreemanChain::displacement( '3' );
432
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;
439
440
441 // static void pointel2pixel( FreemanChain & aPixChain,
442 // std::vector<unsigned int> & aPl2pix,
443 // std::vector<unsigned int> & aPix2pl,
444 // const FreemanChain & aPlChain )
445 f = FreemanChain("000112321233", 0, 0);
446 numVector pl2pix, pix2pl;
447 FreemanChain pixChain;
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 );
458 test = ( pixChain == FreemanChain("00132213", 0, 0) ) &&
459 ( pl2pix == pl2pixExpected ) &&
460 ( pix2pl == pix2plExpected );
461 nbOk += (test) ? 1 : 0;
462 trace.info() << "Test 7 " << ((test) ? "passed" : "failed" ) << endl;
463
464
465 // static void innerContour( FreemanChain & aInnerChain,
466 // std::vector<unsigned int> & aOuter2inner,
467 // std::vector<unsigned int> & aInner2outer,
468 // const FreemanChain & aOuterChain,
469 // bool ccw = true );
470 FreemanChain innerChain;
471 numVector outer2inner, inner2outer;
472 FreemanChain::innerContour ( innerChain, outer2inner, inner2outer, f, true);
473 test = ( innerChain == FreemanChain("00132213", 0, 0 ) ) &&
474 ( outer2inner == pl2pixExpected ) &&
475 ( inner2outer == pix2plExpected );
476 nbOk += (test) ? 1 : 0;
477 trace.info() << "Test 8 " << ((test) ? "passed" : "failed" ) << endl;
478
479
480 // static bool cleanOuterSpikes( FreemanChain & aCleanC,
481 // std::vector<unsigned int> & aC2clean,
482 // std::vector<unsigned int> & aClean2c,
483 // const FreemanChain & c,
484 // bool ccw = true );
485 FreemanChain c( "0000112312213233", 0, 0 );
486 numVector c2clean, clean2c;
487 FreemanChain cleanC;
488 bool cleaned = FreemanChain::cleanOuterSpikes( cleanC, c2clean, clean2c, c, true );
489 FreemanChain cleanCExpected("22233000011231", 3, 2);
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;
508 trace.endBlock();
509 return test;
510}
static void write(std::ostream &out, const FreemanChain &c)
static void displacement(int &dx, int &dy, char aCode)
static char addToCode(char code, int n)
static void innerContour(FreemanChain &aInnerChain, std::vector< unsigned int > &aOuter2inner, std::vector< unsigned int > &aInner2outer, const FreemanChain &aOuterChain, bool ccw=true)
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)
static void movePointFromFC(Point &aPoint, char aCode)
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)
Struct representing a 2D point.
Definition Point.h:27

References DGtal::FreemanChain< TInteger >::addToCode(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::cleanOuterSpikes(), DGtal::FreemanChain< TInteger >::displacement(), DGtal::Trace::endBlock(), DGtal::FreemanChain< TInteger >::getContourPoints(), DGtal::Trace::info(), DGtal::FreemanChain< TInteger >::innerContour(), DGtal::FreemanChain< TInteger >::movement(), DGtal::FreemanChain< TInteger >::movePointFromFC(), DGtal::FreemanChain< TInteger >::pointel2pixel(), DGtal::FreemanChain< TInteger >::read(), test(), DGtal::trace, and DGtal::FreemanChain< TInteger >::write().

Referenced by main().