DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testAlphaThickSegmentComputer.cpp File Reference
#include <iostream>
#include <cmath>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/curves/AlphaThickSegmentComputer.h"
#include "DGtal/io/readers/PointListReader.h"
#include "DGtal/io/boards/Board2D.h"

Go to the source code of this file.

Functions

bool testAlphaThickSegmentConvexHullAndBox ()
 
bool testAlphaThickSegmentComputerFloatingPointContour ()
 
bool testAlphaThickSegmentFreeman ()
 
bool testAlphaThickSpecialInit ()
 
bool testMultiWidth ()
 
bool testThicknessDefinitions ()
 
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
2015/01/07

Functions for testing class AlphaThickSegmentComputer.

This file is part of the DGtal library.

Definition in file testAlphaThickSegmentComputer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 542 of file testAlphaThickSegmentComputer.cpp.

543{
544 trace.beginBlock ( "Testing class AlphaThickSegmentComputer" );
545 trace.info() << "Args:";
546 for ( int i = 0; i < argc; ++i )
547 trace.info() << " " << argv[ i ];
548 trace.info() << endl;
549
552
553 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
554
555
556 trace.endBlock();
557 return res ? 0 : 1;
558}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testAlphaThickSpecialInit()
bool testAlphaThickSegmentComputerFloatingPointContour()
bool testThicknessDefinitions()
bool testAlphaThickSegmentConvexHullAndBox()
bool testAlphaThickSegmentFreeman()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testAlphaThickSegmentComputerFloatingPointContour(), testAlphaThickSegmentConvexHullAndBox(), testAlphaThickSegmentFreeman(), testAlphaThickSpecialInit(), testMultiWidth(), testThicknessDefinitions(), and DGtal::trace.

◆ testAlphaThickSegmentComputerFloatingPointContour()

bool testAlphaThickSegmentComputerFloatingPointContour ( )

Test alpha thick segment with floating points.

Definition at line 196 of file testAlphaThickSegmentComputer.cpp.

197{
198 unsigned int nbok = 0;
199 unsigned int nb = 0;
200 Board2D aBoard;
201 typedef AlphaThickSegmentComputer< Z2i::RealPoint> AlphaThickSegmentComputer2D;
203
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";
208
209 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer(2);
210 anAlphaThickSegmentComputer.init(aContour.begin()+10);
211
212 while (anAlphaThickSegmentComputer.end()!= aContour.end() &&
213 anAlphaThickSegmentComputer.extendFront()){
214 }
215
216
217 // Display alpha thick segment
218 aBoard << SetMode((*anAlphaThickSegmentComputer.begin()).className(), "Grid");
219 aBoard << anAlphaThickSegmentComputer;
220
221
222 // Test primitive of parallelStrip and display the input curve
223 Primitive pStrip = anAlphaThickSegmentComputer.primitive();
224 unsigned int nbInStrip = 0;
225
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()){
230 Z2i::RealPoint next = *(it+1);
231 aBoard.setLineWidth(2);
233 aBoard.drawLine((*it)[0], (*it)[1], next[0], next[1]);
234 }
235 if (pStrip(*it)){
236 nbInStrip++;
237 aBoard << *it;
238 }
239 }
240 trace.info() << "Nb contour points in the segment parallel strip (awaited 32) = " << nbInStrip << std::endl;
241
242 nbok += nbInStrip==32;
243 nb++;
244
245 nbok += anAlphaThickSegmentComputer.getNumberSegmentPoints()==31 ? 1 : 0;
246 nb++;
247
248 trace.info() << "Segment size (awaited 31): " << anAlphaThickSegmentComputer.getNumberSegmentPoints() << std::endl;
249 aBoard.saveEPS("testAlphaThickSegmentComputer_FloatingPt.eps");
250
251 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
252 trace.endBlock();
253 return nbok == nb;
254}
Aim: This class is devoted to the recognition of alpha thick segments as described in ....
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
static const Color Gray
Definition: Color.h:414
Aim: A parallel strip in the space is the intersection of two parallel half-planes such that each hal...
Definition: ParallelStrip.h:91
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition: Board.cpp:368
Board & setLineWidth(double width)
Definition: Board.cpp:329
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
static std::vector< TPoint > getPointsFromFile(const std::string &filename, std::vector< unsigned int > aVectPosition=std::vector< unsigned int >())
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247

References DGtal::Trace::beginBlock(), LibBoard::Board::drawLine(), DGtal::Trace::endBlock(), DGtal::PointListReader< TPoint >::getPointsFromFile(), DGtal::Color::Gray, DGtal::Trace::info(), LibBoard::Board::saveEPS(), LibBoard::Board::setLineWidth(), LibBoard::Board::setPenColor(), and DGtal::trace.

Referenced by main().

◆ testAlphaThickSegmentConvexHullAndBox()

bool testAlphaThickSegmentConvexHullAndBox ( )

Test the convexhull and box of a the alpha-thick segment computer.

Definition at line 52 of file testAlphaThickSegmentComputer.cpp.

53{
54 unsigned int nbok = 0;
55 unsigned int nb = 0;
56
57 Board2D aBoard;
58 typedef AlphaThickSegmentComputer< Z2i::Point > AlphaThickSegmentComputer2D;
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";
63 bool res = true;
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());
72
73
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()){}
82
83
84 // Display convexhull
85 aBoard.setLineWidth(5);
87 for (AlphaThickSegmentComputer2D::ConvexhullConstIterator it = anAlphaThickSegmentComputer.convexhullBegin();
88 it != anAlphaThickSegmentComputer.convexhullEnd(); it++){
89 if ((it+1) != anAlphaThickSegmentComputer.convexhullEnd()){
90 aBoard.drawLine((*it)[0], (*it)[1],
91 (*(it+1))[0],
92 (*(it+1))[1]);
93 }else{
94 aBoard.drawLine((*it)[0], (*it)[1],
95 (*(anAlphaThickSegmentComputer.convexhullBegin()))[0],
96 (*(anAlphaThickSegmentComputer.convexhullBegin()))[1]);
97 }
98 }
99
100
101 // Display boundingbox
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;
115
116
117 // Display the input curve
118 aBoard << SetMode((*aContour.begin()).className(), "Grid");
119 for (std::vector<Z2i::Point>::const_iterator it = aContour.begin();
120 it != aContour.end(); it++){
121 aBoard << *it;
122 if (it+1 != aContour.end()){
123 Z2i::Point next = *(it+1);
125 aBoard.drawLine((*it)[0], (*it)[1], next[0], next[1]);
126 }
127 }
128
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;
132 nbok += res ? 1 : 0;
133 nb++;
134 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
135 trace.endBlock();
136
137 trace.beginBlock("Testing access to extremity points");
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;
142
143 res = anAlphaThickSegmentComputer.getExtremityPoints().first == *(aContour.begin())&&
144 anAlphaThickSegmentComputer.getExtremityPoints().second == Z2i::Point(80,18);
145 nbok += res ? 1 : 0;
146 nb++;
147 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
148 trace.endBlock();
149
150
151 trace.beginBlock("Testing access to anti podal points");
152 std::pair<std::pair<Z2i::Point, Z2i::Point>,
153 Z2i::Point> pairAntipodal = anAlphaThickSegmentComputer.getAntipodalLeaningPoints();
154
155 Z2i::Point p = pairAntipodal.first.first;
156 Z2i::Point q = pairAntipodal.first.second;
157 Z2i::Point s = pairAntipodal.second;
159 aBoard.drawLine(p[0], p[1], q[0], q[1]);
160 aBoard.fillCircle(s[0], s[1], 0.2);
161 aBoard.saveEPS("testAlphaThickSegmentComputer_ConvexhullAntipodal.eps");
162
163 trace.info() << "Antipodal pair: p " << p << ", q:" << q << ", s: "<< s << std::endl;
164 trace.info() << "Should be " << Z2i::Point(78,16) << " " << Z2i::Point(79,6) << Z2i::Point(83,13) <<std::endl;
165
166 res = p==Z2i::Point(78,16) && q==Z2i::Point(79,6) && s == Z2i::Point(83,13);
167 nbok += res ? 1 : 0;
168 nb++;
169 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
170
171
172 trace.beginBlock("Testing getter of segment parameters");
173 pairAntipodal = anAlphaThickSegmentComputer4.getAntipodalLeaningPoints();
174 p = pairAntipodal.first.first;
175 q = pairAntipodal.first.second;
176 s = pairAntipodal.second;
177
178 Z2i::RealPoint vectDir = (p-q)[0]>0? p-q: q-p;
179
180 trace.info() << "Segment4 params: vect Dir: " << vectDir << std::endl;
181 trace.info() << "Should be: " << Z2i::RealPoint(1,1) <<std::endl;
182
183 res = vectDir == Z2i::RealPoint(1,1);
184 nbok += res ? 1 : 0;
185 nb++;
186 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
187 trace.endBlock();
188 return nbok == nb;
189}
static const Color Purple
Definition: Color.h:424
static const Color Yellow
Definition: Color.h:422
static const Color None
Definition: Color.h:412
static const Color Green
Definition: Color.h:417
static const Color Red
Definition: Color.h:416
static const Color Blue
Definition: Color.h:419
static const Color Magenta
Definition: Color.h:421
void fillCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:471
Space::RealPoint RealPoint
Definition: StdDefs.h:97
Space::Point Point
Definition: StdDefs.h:95
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279

References DGtal::Trace::beginBlock(), DGtal::Color::Blue, LibBoard::Board::drawLine(), DGtal::Trace::endBlock(), LibBoard::Board::fillCircle(), DGtal::PointListReader< TPoint >::getPointsFromFile(), DGtal::Color::Gray, DGtal::Color::Green, DGtal::Trace::info(), DGtal::Color::Magenta, DGtal::Color::None, DGtal::Color::Purple, DGtal::Color::Red, LibBoard::Board::saveEPS(), LibBoard::Board::setLineWidth(), LibBoard::Board::setPenColor(), DGtal::trace, and DGtal::Color::Yellow.

Referenced by main().

◆ testAlphaThickSegmentFreeman()

bool testAlphaThickSegmentFreeman ( )

Test alpha thick segment computer on Freeman Chain.

Definition at line 263 of file testAlphaThickSegmentComputer.cpp.

264{
265 unsigned int nbok = 0;
266 unsigned int nb = 0;
268 typedef AlphaThickSegmentComputer< Z2i::Space::Point, FCConstIterator > AlphaThickSegmentComputer2D;
269
270 Board2D aBoard;
271
272
273
274 trace.beginBlock ( "Testing AlphaThickSegmentComputer2D on Freeman chain ..." );
275
276 // Reading input contour
277 std::string freemanChainFilename = testPath + "samples/klokan.fc";
278 fstream fst;
279 fst.open (freemanChainFilename.c_str(), ios::in);
281 fst.close();
282 aBoard << fc;
283
284
285 AlphaThickSegmentComputer2D anAlphaThickSegmentComputer(70.0);
286 anAlphaThickSegmentComputer.init(fc.begin());
287 while (anAlphaThickSegmentComputer.end() != fc.end() &&
288 anAlphaThickSegmentComputer.extendFront()){
289 }
290
291
292 // Display segment
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;
297 nb++;
298
299 // Display points inside the parallel strip
300 unsigned int nbInStrip = 0;
301 AlphaThickSegmentComputer2D::Primitive parallelStrip = anAlphaThickSegmentComputer.primitive();
302
303 for(FCConstIterator it = fc.begin(); it != fc.end(); it++){
304 if(parallelStrip(*it)){
306 aBoard.drawCircle( (*it)[0],(*it)[1], 1.0) ;
307 nbInStrip++;
308 }
309 }
311 aBoard.fillCircle( (*(fc.begin()))[0],(*(fc.begin()))[1], 1.0) ;
312
313 trace.info() << "Nb contour points in the segment parallel strip (awaited 818) = " << nbInStrip << std::endl;
314
315
316 nbok += nbInStrip==818 ? 1 : 0;
317 nb++;
318
319 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
320 trace.endBlock();
321 aBoard.saveEPS("testAlphaThickSegmentComputer_Freeman.eps");
322
323 return nbok == nb;
324
325}
void drawCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:451

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::Color::Blue, LibBoard::Board::drawCircle(), DGtal::FreemanChain< TInteger >::end(), DGtal::Trace::endBlock(), LibBoard::Board::fillCircle(), DGtal::Color::Green, DGtal::Trace::info(), LibBoard::Board::saveEPS(), LibBoard::Board::setPenColor(), and DGtal::trace.

Referenced by main().

◆ testAlphaThickSpecialInit()

bool testAlphaThickSpecialInit ( )

Test special cases on various initialisations.

Definition at line 331 of file testAlphaThickSegmentComputer.cpp.

332{
333 unsigned int nbok = 0;
334 unsigned int nb = 0;
335 Board2D aBoard, aBoard2;
336 typedef AlphaThickSegmentComputer< Z2i::RealPoint> AlphaThickSegmentComputer2D;
337 trace.beginBlock ( "Test special cases on various initialisations ..." );
338
339 AlphaThickSegmentComputer2D segment(1.3);
340 std::vector<Z2i::RealPoint> aContour;
341 aContour.push_back(Z2i::RealPoint(29,20));
342 aContour.push_back(Z2i::RealPoint(30,20.01 ));
343 aContour.push_back(Z2i::RealPoint(31, 21));
344 aContour.push_back(Z2i::RealPoint(32,20));
345 segment.init(aContour.begin());
346 segment.extendFront();
347 while (segment.end()!= aContour.end() &&
348 segment.extendFront()){
349 }
350 nb++;
351 nbok = segment.getNumberSegmentPoints()==4;
352
353 // Display alpha thick segment
354 for( std::vector<Z2i::RealPoint>::const_iterator it = aContour.begin(); it != aContour.end(); it++){
355 aBoard << *it;
356 }
357 // Display alpha thick segment
358 aBoard << SetMode((*segment.begin()).className(), "Grid");
359 aBoard << segment;
360
361 functors::Round<> rounding_functor;
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]);
368 aBoard.fillCircle(s[0], s[1], 0.2);
369 aBoard.saveEPS("testSpecialInit.eps");
370
371 trace.info() << "Segment size: " << segment.getNumberSegmentPoints() << "(awaited : " << 4 <<")"<< std::endl;
372 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
373 trace.endBlock();
374 aBoard.saveEPS("testSpecialInit.eps");
375
376 return nbok==nb;
377}
Functor that rounds to the nearest integer.

References DGtal::Trace::beginBlock(), DGtal::Color::Blue, LibBoard::Board::drawLine(), DGtal::Trace::endBlock(), LibBoard::Board::fillCircle(), DGtal::Color::Green, DGtal::Trace::info(), LibBoard::Board::saveEPS(), LibBoard::Board::setPenColor(), and DGtal::trace.

Referenced by main().

◆ testMultiWidth()

bool testMultiWidth ( )

Test multi width segment computer

Definition at line 384 of file testAlphaThickSegmentComputer.cpp.

385{
386 Board2D aBoard;
387 typedef AlphaThickSegmentComputer< Z2i::RealPoint> AlphaThickSegmentComputer2D;
388 unsigned nb=0;
389 unsigned nbok =0;
390 trace.beginBlock ( "Testing alpha-thick segment with multi width ..." );
391 std::vector<Z2i::RealPoint> aContour;
392 std::string fileContour = testPath + "samples/contourNoiseSample2.sdp";
394 HueShadeColorMap<double> hueMap(0.0, 10);
395 unsigned int pos=0;
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);
400 nbTotalAdded++;
401 while (anAlphaThickSegmentComputer.end()!= aContour.end() &&
402 anAlphaThickSegmentComputer.extendFront()){
403 nbTotalAdded++;
404 }
405 aBoard << SetMode((*anAlphaThickSegmentComputer.begin()).className(), "Grid");
406
407 aBoard << CustomStyle( anAlphaThickSegmentComputer.className(),
408 new CustomColors( hueMap(width), DGtal::Color::None ) );
409 aBoard << anAlphaThickSegmentComputer;
410 }
411 trace.info() << "Nb total points added: " << nbTotalAdded << "(awaited: 2300) " << std::endl;
412 trace.endBlock();
413 aBoard.saveEPS("testMultiWidth.eps");
414 nb++;
415 nbok += nbTotalAdded == 2300;
416 return nb==nbok;
417}
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::PointListReader< TPoint >::getPointsFromFile(), DGtal::Trace::info(), DGtal::Color::None, LibBoard::Board::saveEPS(), and DGtal::trace.

Referenced by main().

◆ testThicknessDefinitions()

bool testThicknessDefinitions ( )

Test euclidean two thickness definitions

Definition at line 427 of file testAlphaThickSegmentComputer.cpp.

427 {
428 Board2D aBoardHVthickness;
429 Board2D aBoardEuclthickness;
430 typedef AlphaThickSegmentComputer<Z2i::Point> AlphaThickSegmentComputer2D;
431 unsigned nb=0;
432 unsigned nbok =0;
433 trace.beginBlock ( "Testing alpha-thick segment with different thickness definitions:" );
434
435 AlphaThickSegmentComputer2D anAlphaSegmentHV(1.35, functions::Hull2D::HorizontalVerticalThickness);
436 AlphaThickSegmentComputer2D anAlphaSegmentEucl(1.35, functions::Hull2D::EuclideanThickness);
437
438 Z2i::Domain adom(Z2i::Point(99,45), Z2i::Point(106,55));
439 aBoardEuclthickness << adom;
440 aBoardHVthickness << adom;
441
442 std::vector<Z2i::Point> aVect;
443 aVect.push_back(Z2i::Point(104, 54));
444 aVect.push_back(Z2i::Point(104, 53));
445 aVect.push_back(Z2i::Point(103, 53));
446 aVect.push_back(Z2i::Point(103, 52));
447 aVect.push_back(Z2i::Point(102, 52));
448 aVect.push_back(Z2i::Point(102, 51));
449 aVect.push_back(Z2i::Point(102, 50));
450 aVect.push_back(Z2i::Point(101, 50));
451 aVect.push_back(Z2i::Point(101, 49));
452 aVect.push_back(Z2i::Point(101, 48));
453 aVect.push_back(Z2i::Point(100, 48));
454 aVect.push_back(Z2i::Point(100, 47));
455 // Display the input curve
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()){
463 Z2i::Point next = *(it+1);
464 aBoardEuclthickness.setPenColor(DGtal::Color::Gray);
465 aBoardHVthickness.setPenColor(DGtal::Color::Gray);
466 aBoardEuclthickness.drawLine((*it)[0], (*it)[1], next[0], next[1]);
467 aBoardHVthickness.drawLine((*it)[0], (*it)[1], next[0], next[1]);
468 }
469 }
470
471 anAlphaSegmentEucl.init(aVect.begin());
472 while(anAlphaSegmentEucl.end() != aVect.end()
473 && anAlphaSegmentEucl.extendFront()){
474 }
475 anAlphaSegmentHV.init(aVect.begin());
476 while(anAlphaSegmentHV.end() != aVect.end()
477 && anAlphaSegmentHV.extendFront()){
478 }
479
480
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;
483
484
485 aBoardHVthickness << CustomStyle( anAlphaSegmentEucl.className(), new CustomColors( DGtal::Color::Blue, DGtal::Color::None ) );
486 aBoardEuclthickness << CustomStyle( anAlphaSegmentHV.className(), new CustomColors( DGtal::Color::Blue, DGtal::Color::None ) );
487 aBoardHVthickness << anAlphaSegmentHV;
488 aBoardEuclthickness << anAlphaSegmentEucl;
489
490 std::vector<Z2i::Point> hullHV = anAlphaSegmentHV.getConvexHull();
491 std::vector<Z2i::Point> hullEucl = anAlphaSegmentEucl.getConvexHull();
492 aBoardEuclthickness.setLineWidth(5);
493 aBoardHVthickness.setLineWidth(5);
494 aBoardEuclthickness.setPenColor(DGtal::Color::Purple);
495 aBoardHVthickness.setPenColor(DGtal::Color::Purple);
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]);
500 }
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]);
505 }
506
507 Z2i::Point pEucl = anAlphaSegmentEucl.getAntipodalLeaningPoints().first.first;
508 Z2i::Point qEucl = anAlphaSegmentEucl.getAntipodalLeaningPoints().first.second;
509 Z2i::Point sEucl = anAlphaSegmentEucl.getAntipodalLeaningPoints().second;
510
511 Z2i::Point pHV = anAlphaSegmentHV.getAntipodalLeaningPoints().first.first;
512 Z2i::Point qHV = anAlphaSegmentHV.getAntipodalLeaningPoints().first.second;
513 Z2i::Point sHV = anAlphaSegmentHV.getAntipodalLeaningPoints().second;
514 aBoardEuclthickness.setPenColor(DGtal::Color::Red);
515 aBoardHVthickness.setPenColor(DGtal::Color::Red);
516
517 aBoardEuclthickness.drawCircle( pEucl[0], pEucl[1], 0.25);
518 aBoardHVthickness.drawCircle( pHV[0], pHV[1], 0.25);
519
520 aBoardEuclthickness.drawCircle( qEucl[0], qEucl[1], 0.25);
521 aBoardHVthickness.drawCircle( qHV[0], qHV[1], 0.25);
522
523 aBoardEuclthickness.setPenColor(DGtal::Color::Green);
524 aBoardHVthickness.setPenColor(DGtal::Color::Green);
525
526 aBoardEuclthickness.drawCircle( sEucl[0], sEucl[1], 0.25);
527 aBoardHVthickness.drawCircle( sHV[0], sHV[1], 0.25);
528
529 aBoardEuclthickness.saveEPS("testAlphaThickEucl.eps");
530 aBoardHVthickness.saveEPS("testAlphaThickHV.eps");
531
532 trace.endBlock();
533 return nb==nbok;
534}

References DGtal::Trace::beginBlock(), DGtal::Color::Blue, LibBoard::Board::drawCircle(), LibBoard::Board::drawLine(), DGtal::Trace::endBlock(), DGtal::functions::Hull2D::EuclideanThickness, DGtal::Color::Gray, DGtal::Color::Green, DGtal::functions::Hull2D::HorizontalVerticalThickness, DGtal::Trace::info(), DGtal::Color::None, pHV, DGtal::Color::Purple, qHV, DGtal::Color::Red, LibBoard::Board::saveEPS(), LibBoard::Board::setLineWidth(), LibBoard::Board::setPenColor(), sHV, and DGtal::trace.

Referenced by main().