DGtal  0.9.3
Functions
testSegmentation.cpp File Reference
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <iostream>
#include <iterator>
#include "DGtal/base/Common.h"
#include "DGtal/base/Exceptions.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/Color.h"
#include "DGtal/base/Circulator.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/curves/FreemanChain.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
#include "DGtal/geometry/curves/SaturatedSegmentation.h"
#include "ConfigTest.h"
Include dependency graph for testSegmentation.cpp:

Go to the source code of this file.

Functions

template<typename Iterator , typename Board >
void draw (const Iterator &itb, const Iterator &ite, Board &aBoard)
 
template<typename Iterator , typename Board >
void drawCCP (const Iterator &itb, const Iterator &ite, Board &aBoard)
 
template<typename Iterator , typename Board >
void segmentationIntoDSSs (const Iterator &itb, const Iterator &ite, const Iterator &sitb, const Iterator &site, const string &aMode, Board &aBoard)
 
template<typename Iterator , typename Board >
void segmentationIntoMaximalDSSs (const Iterator &itb, const Iterator &ite, const Iterator &sitb, const Iterator &site, const string &aMode, Board &aBoard)
 
bool greedySegmentationVisualTest ()
 
bool SaturatedSegmentationVisualTest ()
 
bool SaturatedSegmentationTest ()
 
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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/07/22

This file is part of the DGtal library

Definition in file testSegmentation.cpp.

Function Documentation

◆ draw()

template<typename Iterator , typename Board >
void draw ( const Iterator &  itb,
const Iterator &  ite,
Board aBoard 
)

Drawing a segmentation

Examples:
doc-examples/kernelDomain.cpp, geometry/volumes/distance/exampleFMM2D.cpp, geometry/volumes/distance/toricdomainvolumetric.cpp, geometry/volumes/distance/voronoimap2D.cpp, geometry/volumes/dvcm-2d.cpp, and topology/khalimskySpaceScanner.cpp.

Definition at line 75 of file testSegmentation.cpp.

Referenced by main(), and testVoronoiMapFromSites2D().

76 {
77 
78  for (Iterator i(itb); i != ite; ++i) {
79 
80  typename Iterator::SegmentComputer segment(*i);
81 
82  aBoard << SetMode(segment.primitive().className(), "BoundingBox" )
83  << segment.primitive(); // draw bounding box
84 
85  }
86 
87 }
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247

◆ drawCCP()

template<typename Iterator , typename Board >
void drawCCP ( const Iterator &  itb,
const Iterator &  ite,
Board aBoard 
)

Drawing a segmentation

Examples:
geometry/curves/convex-and-concave-parts.cpp.

Definition at line 93 of file testSegmentation.cpp.

References DGtal::Color::Black, DGtal::Color::Blue, DGtal::Color::Green, DGtal::Color::Red, and DGtal::Color::Yellow.

94 {
95 
96  typedef typename Iterator::SegmentComputer::ConstIterator PointIterator;
97 
98  for (Iterator i(itb); i != ite; ++i) {
99 
100  //choose pen color
101  CustomPenColor* aPenColor;
102 
103  if ( !(i.intersectNext() && i.intersectPrevious()) ) {
104 
105  aPenColor = new CustomPenColor( Color::Black );
106 
107  } else {
108 
109  //end points
110 
111  PointIterator begin = i->begin(); --begin;
112  PointIterator end = i->end();
113 
114  //parameters
115  int mu = i->mu();
116  int omega = i->omega();
117 
118  //configurations
119  if ( (i->remainder(begin)<=mu-1)&&
120  (i->remainder(end)<=mu-1) ) { //concave
121  aPenColor = new CustomPenColor( Color::Green);
122  } else if ( (i->remainder(begin)>=mu+omega)&&
123  (i->remainder(end)>=mu+omega) ) { //convex
124  aPenColor = new CustomPenColor( Color::Blue );
125  } else if ( (i->remainder(begin)>=mu+omega)&&
126  (i->remainder(end)<=mu-1) ) { //convex to concave
127  aPenColor = new CustomPenColor( Color::Yellow );
128  } else if ( (i->remainder(begin)<=mu-1)&&
129  (i->remainder(end)>=mu+omega) ) { //concave to convex
130  aPenColor = new CustomPenColor( Color::Yellow );
131  } else { //pb
132  aPenColor = new CustomPenColor( Color::Red );
133  }
134 
135  }
136 
137  // draw each segment
138  aBoard << SetMode(i->primitive().className(), "BoundingBox" )
139  << CustomStyle( i->primitive().className(), aPenColor )
140  << i->primitive();
141 
142  }
143 
144 }
MyDigitalSurface::ConstIterator ConstIterator
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:312

◆ greedySegmentationVisualTest()

bool greedySegmentationVisualTest ( )

Simple visual test

Definition at line 200 of file testSegmentation.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::saveEPS(), and DGtal::trace.

Referenced by main().

201 {
202 
203  typedef int Coordinate;
204  typedef FreemanChain<Coordinate> FC;
206 
207 
208 
209  std::string filename = testPath + "samples/manche.fc";
210 
211  std::fstream fst;
212  fst.open (filename.c_str(), std::ios::in);
213  FC fc(fst);
214 
216 // open digital curve
217 
218  trace.beginBlock("Segmentation of a whole range (mode1)");
219 {
220  Board2D aBoard;
221  aBoard << SetMode("PointVector", "Grid") << fc;
222 
223  segmentationIntoDSSs<ConstIterator,Board2D>
224  (fc.begin(),fc.end(),
225  fc.begin(),fc.end(),
226  "Truncate",aBoard);
227 
228  aBoard.saveEPS("WholeOpenCurveWithItMode1.eps");
229 }
230  trace.endBlock();
231 
232 
233  trace.beginBlock("Segmentation of a whole range (mode3)");
234 {
235  Board2D aBoard;
236  aBoard << SetMode("PointVector", "Grid") << fc;
237 
238  segmentationIntoDSSs<ConstIterator,Board2D>
239  (fc.begin(),fc.end(),
240  fc.begin(),fc.end(),
241  "DoNotTruncate",aBoard);
242 
243  aBoard.saveEPS("WholeOpenCurveWithItMode3.eps");
244 }
245  trace.endBlock();
246 
247  trace.beginBlock("Segmentation of a whole range (mode2)");
248 {
249  Board2D aBoard;
250  aBoard << SetMode("PointVector", "Grid") << fc;
251 
252  segmentationIntoDSSs<ConstIterator,Board2D>
253  (fc.begin(),fc.end(),
254  fc.begin(),fc.end(),
255  "Truncate+1",aBoard);
256 
257  aBoard.saveEPS("WholeOpenCurveWithItMode2.eps");
258 }
259  trace.endBlock();
260 
261 
263 // subrange
264 
265  typedef vector<PointVector<2,Coordinate> > Curve;
266  typedef Curve::const_iterator RAConstIterator;
267 
268  Curve vPts;
269  vPts.assign ( fc.begin(), fc.end() );
270 
271  RAConstIterator start = vPts.begin()+15;
272  RAConstIterator stop = vPts.begin()+200;
273 
274 trace.info() << *start << " " << *stop << endl;
275 
276  trace.beginBlock("Segmentation of a subrange (mode1)");
277 {
278  Board2D aBoard;
279  aBoard << SetMode("PointVector", "Grid") << fc;
280  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
281 
282  segmentationIntoDSSs<RAConstIterator,Board2D>
283  (vPts.begin(),vPts.end(),
284  start,stop,
285  "Truncate",aBoard);
286 
287  aBoard.saveEPS("PartOpenCurveWithItMode1.eps");
288 }
289  trace.endBlock();
290 
291  trace.beginBlock("Segmentation of a subrange (mode2)");
292 {
293  Board2D aBoard;
294  aBoard << SetMode("PointVector", "Grid") << fc;
295  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
296 
297  segmentationIntoDSSs<RAConstIterator,Board2D>
298  (vPts.begin(),vPts.end(),
299  start,stop,
300  "Truncate+1",aBoard);
301 
302  aBoard.saveEPS("PartOpenCurveWithItMode2.eps");
303 }
304  trace.endBlock();
305 
306 
307  trace.beginBlock("Segmentation of a subrange (mode3)");
308 {
309  Board2D aBoard;
310  aBoard << SetMode("PointVector", "Grid") << fc;
311  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
312 
313  segmentationIntoDSSs<RAConstIterator,Board2D>
314  (vPts.begin(),vPts.end(),
315  start,stop,
316  "DoNotTruncate",aBoard);
317 
318  aBoard.saveEPS("PartOpenCurveWithItMode3.eps");
319 }
320  trace.endBlock();
321 
322 
324 // using circulators
325 
326  typedef Circulator<RAConstIterator> ConstCirculator;
327  ConstCirculator c(vPts.begin(),vPts.begin(),vPts.end());
328 
329  trace.beginBlock("Segmentation of a whole range (mode1) with circulators");
330 {
331  Board2D aBoard;
332  aBoard << SetMode("PointVector", "Grid") << fc;
333 
334  segmentationIntoDSSs<ConstCirculator,Board2D>
335  (c,c,c,c,
336  "Truncate",aBoard);
337 
338  aBoard.saveEPS("WholeOpenCurveWithCircMode1.eps");
339 }
340  trace.endBlock();
341 
342  trace.beginBlock("Segmentation of a whole range (mode2) with circulators");
343 {
344  Board2D aBoard;
345  aBoard << SetMode("PointVector", "Grid") << fc;
346 
347  segmentationIntoDSSs<ConstCirculator,Board2D>
348  (c,c,c,c,
349  "Truncate+1",aBoard);
350 
351  aBoard.saveEPS("WholeOpenCurveWithCircMode2.eps");
352 }
353  trace.endBlock();
354 
355 
356  trace.beginBlock("Segmentation of a whole range (mode3) with circulators");
357 {
358  Board2D aBoard;
359  aBoard << SetMode("PointVector", "Grid") << fc;
360 
361  segmentationIntoDSSs<ConstCirculator,Board2D>
362  (c,c,c,c,
363  "DoNotTruncate",aBoard);
364 
365  aBoard.saveEPS("WholeOpenCurveWithCircMode3.eps");
366 }
367  trace.endBlock();
368 
370 // subrange with circulators
371 
372  ConstCirculator cstart(start,vPts.begin(),vPts.end());
373  ConstCirculator cstop(stop,vPts.begin(),vPts.end());
374 
375  trace.beginBlock("Segmentation of a subrange (mode1) with circulators");
376 {
377  Board2D aBoard;
378  aBoard << SetMode("PointVector", "Grid") << fc;
379  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
380 
381  segmentationIntoDSSs<ConstCirculator,Board2D>
382  (c,c,
383  cstart,cstop,
384  "Truncate",aBoard);
385 
386  aBoard.saveEPS("PartOpenCurveWithCircMode1.eps");
387 }
388  trace.endBlock();
389 
390  trace.beginBlock("Segmentation of a subrange (mode2) with circulators");
391 {
392  Board2D aBoard;
393  aBoard << SetMode("PointVector", "Grid") << fc;
394  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
395 
396  segmentationIntoDSSs<ConstCirculator,Board2D>
397  (c,c,
398  cstart,cstop,
399  "Truncate+1",aBoard);
400 
401  aBoard.saveEPS("PartOpenCurveWithCircMode2.eps");
402 }
403  trace.endBlock();
404 
405 
406  trace.beginBlock("Segmentation of a subrange (mode3) with circulators");
407 {
408  Board2D aBoard;
409  aBoard << SetMode("PointVector", "Grid") << fc;
410  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
411 
412  segmentationIntoDSSs<ConstCirculator,Board2D>
413  (c,c,
414  cstart,cstop,
415  "DoNotTruncate",aBoard);
416 
417  aBoard.saveEPS("PartOpenCurveWithCircMode3.eps");
418 }
419  trace.endBlock();
420 
422 // closed digital curve
423 
424  std::stringstream ss(stringstream::in | stringstream::out);
425  ss << "31 16 1112121212121221212121221212212222232232323332333333332333332330333033003030000010001001001000100010101010111" << endl;
426 
427  // Construct the Freeman chain
428  FC fc2(ss);
429 
430  Curve vPts2;
431  vPts2.assign( fc2.begin(), fc2.end() );
432  vPts2.insert( vPts2.end(), fc2.begin(), fc2.end() );
433  vPts2.insert( vPts2.end(), fc2.begin(), fc2.end() );
434 
435 //copy ( vPts2.begin(), vPts2.end(), ostream_iterator<PointVector<2,Coordinate> >(cout,"\n") ) ;
436 
437  RAConstIterator start2 = vPts2.begin() + fc2.size()+1;
438  RAConstIterator stop2 = start2 + fc2.size()+1;
439 
440 trace.info() << *start2 << " " << *stop2 << endl;
441 
442  trace.beginBlock("Segmentation of a subrange of a duplicated range (mode1)");
443 {
444  Board2D aBoard;
445  aBoard << SetMode("PointVector", "Grid") << fc2;
446  aBoard << SetMode("PointVector", "Paving") << *start2 << *stop2;
447 
448  segmentationIntoDSSs<RAConstIterator,Board2D>
449  (vPts2.begin(),vPts2.end(),
450  start2,stop2,
451  "Truncate",aBoard);
452 
453  aBoard.saveEPS("DuplicatedCurveWithItMode1.eps");
454 }
455  trace.endBlock();
456 
457  trace.beginBlock("Segmentation of a subrange of a duplicated range (mode2)");
458 {
459  Board2D aBoard;
460  aBoard << SetMode("PointVector", "Grid") << fc2;
461  aBoard << SetMode("PointVector", "Paving") << *start2 << *stop2;
462 
463  segmentationIntoDSSs<RAConstIterator,Board2D>
464  (vPts2.begin(),vPts2.end(),
465  start2,stop2,
466  "Truncate+1",aBoard);
467 
468  aBoard.saveEPS("DuplicatedCurveWithItMode2.eps");
469 }
470  trace.endBlock();
471 
472 
473  trace.beginBlock("Segmentation of a subrange of a duplicated range (mode3)");
474 {
475  Board2D aBoard;
476  aBoard << SetMode("PointVector", "Grid") << fc2;
477  aBoard << SetMode("PointVector", "Paving") << *start2 << *stop2;
478 
479  segmentationIntoDSSs<RAConstIterator,Board2D>
480  (vPts2.begin(),vPts2.end(),
481  start2,stop2,
482  "DoNotTruncate",aBoard);
483 
484  aBoard.saveEPS("DuplicatedCurveWithItMode3.eps");
485 }
486  trace.endBlock();
487 
488 
490 // closed digital curve with circulators
491 
492  ConstCirculator c2(start2,start2,stop2);
493 
494  trace.beginBlock("Segmentation of a whole range (mode1) with circulators");
495 {
496  Board2D aBoard;
497  aBoard << SetMode("PointVector", "Grid") << fc2;
498 
499  segmentationIntoDSSs<ConstCirculator,Board2D>
500  (c2,c2,c2,c2,
501  "Truncate",aBoard);
502 
503  aBoard.saveEPS("ClosedCurveWithCircMode1.eps");
504 }
505  trace.endBlock();
506 
507  trace.beginBlock("Segmentation of a whole range (mode2) with circulators");
508 {
509  Board2D aBoard;
510  aBoard << SetMode("PointVector", "Grid") << fc2;
511 
512  segmentationIntoDSSs<ConstCirculator,Board2D>
513  (c2,c2,c2,c2,
514  "Truncate+1",aBoard);
515 
516  aBoard.saveEPS("ClosedCurveWithCircMode2.eps");
517 }
518  trace.endBlock();
519 
520 
521  trace.beginBlock("Segmentation of a whole range (mode3) with circulators");
522 {
523  Board2D aBoard;
524  aBoard << SetMode("PointVector", "Grid") << fc2;
525 
526  segmentationIntoDSSs<ConstCirculator,Board2D>
527  (c2,c2,c2,c2,
528  "DoNotTruncate",aBoard);
529 
530  aBoard.saveEPS("ClosedCurveWithCircMode3.eps");
531 }
532  trace.endBlock();
533 
534 
536  return true;
537 }
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
GridCurve< K2 > Curve
Definition: StdDefs.h:116
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 942 of file testSegmentation.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), greedySegmentationVisualTest(), DGtal::Trace::info(), SaturatedSegmentationTest(), SaturatedSegmentationVisualTest(), and DGtal::trace.

943 {
944 
945  trace.beginBlock ( "Testing class GreedyDecomposition and SaturatedSegmentation" );
946  trace.info() << "Args:";
947  for ( int i = 0; i < argc; ++i )
948  trace.info() << " " << argv[ i ];
949  trace.info() << endl;
950 
951  bool res = greedySegmentationVisualTest()
954 ;
955 
956  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
957  trace.endBlock();
958 
959  return res ? 0 : 1;
960 
961 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
bool greedySegmentationVisualTest()
double endBlock()
bool SaturatedSegmentationTest()
std::ostream & emphase()
bool SaturatedSegmentationVisualTest()
std::ostream & info()

◆ SaturatedSegmentationTest()

bool SaturatedSegmentationTest ( )

Simple visual test

Definition at line 890 of file testSegmentation.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

891 {
892 
893  typedef int Coordinate;
894  typedef FreemanChain<Coordinate> FC;
895 
896  std::string filename = testPath + "samples/BigBall2.fc";
897 
898  std::fstream fst;
899  fst.open (filename.c_str(), std::ios::in);
900  FC fc(fst);
901 
903 
904  vector<Point> vPts;
905  vPts.assign(fc.begin(),fc.end());
906 
907  typedef vector<Point>::const_iterator ConstIterator;
908  typedef Circulator<ConstIterator> ConstCirculator;
909 
910  Circulator<ConstIterator> c(vPts.begin(), vPts.begin(), vPts.end() );
911 
912  typedef ArithmeticalDSSComputer<ConstCirculator,Coordinate,4> RecognitionAlgorithm;
913  typedef SaturatedSegmentation<RecognitionAlgorithm> Segmentation;
914 
915  trace.beginBlock("saturated Segmentation");
916  trace.info() << filename << endl;
917 
918  RecognitionAlgorithm algo;
919  Segmentation s(c,c,algo);
920  s.setMode("First");
921 
922  Segmentation::SegmentComputerIterator begin = s.begin();
923  Segmentation::SegmentComputerIterator end = s.end();
924 
925  unsigned int compteur = 0;
926  for (Segmentation::SegmentComputerIterator i(begin); i != end; ++i) {
927  ++compteur;
928  }
929 
930  trace.info() << "# nbpts nbsegments " << endl;
931  trace.info() << fc.size()+1 << " " << compteur << endl;
932 
933  trace.endBlock();
934 
935  return (compteur == 4295);
936 }
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
double endBlock()
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...

◆ SaturatedSegmentationVisualTest()

bool SaturatedSegmentationVisualTest ( )

Simple visual test

Definition at line 549 of file testSegmentation.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::saveEPS(), and DGtal::trace.

Referenced by main().

550 {
551 
552  typedef int Coordinate;
553  typedef FreemanChain<Coordinate> FC;
555 
556  std::string filename = testPath + "samples/manche.fc";
557 
558  std::fstream fst;
559  fst.open (filename.c_str(), std::ios::in);
560  FC fc(fst);
561 
563 // whole open curve
564 
565  trace.beginBlock("Simple saturated Segmentation (mode=First)");
566 {
567  Board2D aBoard;
568  aBoard << SetMode("PointVector", "Grid") << fc;
569 
570  segmentationIntoMaximalDSSs<ConstIterator,Board2D>
571  (fc.begin(),fc.end(),
572  fc.begin(),fc.end(),
573  "First",aBoard);
574 
575  aBoard.saveEPS("MSOpenCurve2.eps");
576 }
577  trace.endBlock();
578 
579  trace.beginBlock("Simple saturated Segmentation (mode=MostCentered)");
580 {
581  Board2D aBoard;
582  aBoard << SetMode("PointVector", "Grid") << fc;
583 
584  segmentationIntoMaximalDSSs<ConstIterator,Board2D>
585  (fc.begin(),fc.end(),
586  fc.begin(),fc.end(),
587  "MostCentered",aBoard);
588 
589  aBoard.saveEPS("MSOpenCurve3.eps");
590 }
591  trace.endBlock();
592 
593  trace.beginBlock("Simple saturated Segmentation (mode=Last)");
594 {
595  Board2D aBoard;
596  aBoard << SetMode("PointVector", "Grid") << fc;
597 
598  segmentationIntoMaximalDSSs<ConstIterator,Board2D>
599  (fc.begin(),fc.end(),
600  fc.begin(),fc.end(),
601  "Last",aBoard);
602 
603  aBoard.saveEPS("MSOpenCurve4.eps");
604 }
605  trace.endBlock();
606 
608 // subrange
609 
610  typedef vector<PointVector<2,Coordinate> > Curve;
611  typedef Curve::const_iterator RAConstIterator;
612 
613  Curve vPts;
614  vPts.assign ( fc.begin(), fc.end() );
615 
616  RAConstIterator start = vPts.begin()+190;
617  RAConstIterator stop = vPts.begin()+400;
618 
619 trace.info() << *start << " " << *stop << endl;
620 
621 
622  trace.beginBlock("saturated Segmentation of a subrange (mode=First)");
623 {
624  Board2D aBoard;
625  aBoard << SetMode("PointVector", "Grid") << fc;
626  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
627 
628  segmentationIntoMaximalDSSs<RAConstIterator,Board2D>
629  (vPts.begin(),vPts.end(),
630  start,stop,
631  "First",aBoard);
632 
633  aBoard.saveEPS("MSOpenCurvePart2.eps");
634 }
635  trace.endBlock();
636 
637  trace.beginBlock("saturated Segmentation of a subrange (mode=MostCentered)");
638 {
639  Board2D aBoard;
640  aBoard << SetMode("PointVector", "Grid") << fc;
641  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
642 
643  segmentationIntoMaximalDSSs<RAConstIterator,Board2D>
644  (vPts.begin(),vPts.end(),
645  start,stop,
646  "MostCentered",aBoard);
647 
648  aBoard.saveEPS("MSOpenCurvePart3.eps");
649 }
650  trace.endBlock();
651 
652  trace.beginBlock("saturated Segmentation of a subrange (mode=Last)");
653 {
654  Board2D aBoard;
655  aBoard << SetMode("PointVector", "Grid") << fc;
656  aBoard << SetMode("PointVector", "Paving") << *start << *stop;
657 
658  segmentationIntoMaximalDSSs<RAConstIterator,Board2D>
659  (vPts.begin(),vPts.end(),
660  start,stop,
661  "Last",aBoard);
662 
663  aBoard.saveEPS("MSOpenCurvePart4.eps");
664 }
665  trace.endBlock();
666 
667 
669 // using circulators
670 
671  typedef Circulator<RAConstIterator> ConstCirculator;
672  ConstCirculator c(vPts.begin(),vPts.begin(),vPts.end());
673 
674 
675  trace.beginBlock("Segmentation of a range bounded by circulators (mode=First)");
676 {
677  Board2D aBoard;
678  aBoard << SetMode("PointVector", "Grid") << fc;
679 
680  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
681  (c,c,c,c,
682  "First",aBoard);
683 
684  aBoard.saveEPS("MSOpenCurveWithCirc2.eps");
685 }
686  trace.endBlock();
687 
688  trace.beginBlock("Segmentation of a range bounded by circulators (mode=MostCentered)");
689 {
690  Board2D aBoard;
691  aBoard << SetMode("PointVector", "Grid") << fc;
692 
693  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
694  (c,c,c,c,
695  "MostCentered",aBoard);
696 
697  aBoard.saveEPS("MSOpenCurveWithCirc3.eps");
698 }
699  trace.endBlock();
700 
701  trace.beginBlock("Segmentation of a range bounded by circulators (mode=Last)");
702 {
703  Board2D aBoard;
704  aBoard << SetMode("PointVector", "Grid") << fc;
705 
706  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
707  (c,c,c,c,
708  "Last",aBoard);
709 
710  aBoard.saveEPS("MSOpenCurveWithCirc4.eps");
711 }
712  trace.endBlock();
713 
714 
716 // subrange with circulators
717 
718  ConstCirculator cstart(start,vPts.begin(),vPts.end());
719  ConstCirculator cstop(stop,vPts.begin(),vPts.end());
720 
721 
722  trace.beginBlock("Segmentation of a subrange with circulators (mode=First)");
723 {
724  Board2D aBoard;
725  aBoard << SetMode("PointVector", "Grid") << fc;
726  aBoard << SetMode("PointVector", "Paving") << *cstart << *cstop;
727 
728  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
729  (c,c,cstart,cstop,
730  "First",aBoard);
731 
732  aBoard.saveEPS("MSOpenCurvePartWithCirc2.eps");
733 }
734  trace.endBlock();
735 
736  trace.beginBlock("Segmentation of a subrange with circulators (mode=MostCentered)");
737 {
738  Board2D aBoard;
739  aBoard << SetMode("PointVector", "Grid") << fc;
740  aBoard << SetMode("PointVector", "Paving") << *cstart << *cstop;
741 
742  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
743  (c,c,cstart,cstop,
744  "MostCentered",aBoard);
745 
746  aBoard.saveEPS("MSOpenCurvePartWithCirc3.eps");
747 }
748  trace.endBlock();
749 
750  trace.beginBlock("Segmentation of a subrange with circulators (mode=Last)");
751 {
752  Board2D aBoard;
753  aBoard << SetMode("PointVector", "Grid") << fc;
754  aBoard << SetMode("PointVector", "Paving") << *cstart << *cstop;
755 
756  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
757  (c,c,cstart,cstop,
758  "Last",aBoard);
759 
760  aBoard.saveEPS("MSOpenCurvePartWithCirc4.eps");
761 }
762  trace.endBlock();
763 
765 // closed digital curve with circulators
766 
767  std::stringstream ss(stringstream::in | stringstream::out);
768  ss << "31 16 1112121212121221212121221212212222232232323332333333332333332330333033003030000010001001001000100010101010111" << endl;
769 
770  // Construct the Freeman chain
771  FC fc2(ss);
772 
773  Curve vPts2;
774  vPts2.assign( fc2.begin(), fc2.end() );
775  vPts2.insert( vPts2.end(), fc2.begin(), fc2.end() );
776  vPts2.insert( vPts2.end(), fc2.begin(), fc2.end() );
777 
778  RAConstIterator start2 = vPts2.begin() + fc2.size()+1;
779  RAConstIterator stop2 = start2 + fc2.size()+1;
780 
781  trace.info() << *start2 << " " << *stop2 << endl;
782 
783  trace.beginBlock("Satured Segmentation of a duplicated range (mode2)");
784 {
785  Board2D aBoard;
786  aBoard << SetMode("PointVector", "Grid") << fc2;
787  aBoard << SetMode("PointVector", "Paving") << *start2 << *stop2;
788 
789  segmentationIntoMaximalDSSs<RAConstIterator,Board2D>
790  (vPts2.begin(),vPts2.end(),
791  start2,stop2,
792  "First",aBoard);
793 
794  aBoard.saveEPS("MSClosedCurveWithIt2.eps");
795 }
796  trace.endBlock();
797 
798  trace.beginBlock("Satured Segmentation of a duplicated range (mode3)");
799 {
800  Board2D aBoard;
801  aBoard << SetMode("PointVector", "Grid") << fc2;
802  aBoard << SetMode("PointVector", "Paving") << *start2 << *stop2;
803 
804  segmentationIntoMaximalDSSs<RAConstIterator,Board2D>
805  (vPts2.begin(),vPts2.end(),
806  start2,stop2,
807  "MostCentered",aBoard);
808 
809  aBoard.saveEPS("MSClosedCurveWithIt3.eps");
810 }
811  trace.endBlock();
812 
813 
814  trace.beginBlock("Satured Segmentation of a duplicated range (mode4)");
815 {
816  Board2D aBoard;
817  aBoard << SetMode("PointVector", "Grid") << fc2;
818  aBoard << SetMode("PointVector", "Paving") << *start2 << *stop2;
819 
820  segmentationIntoMaximalDSSs<RAConstIterator,Board2D>
821  (vPts2.begin(),vPts2.end(),
822  start2,stop2,
823  "Last",aBoard);
824 
825  aBoard.saveEPS("MSClosedCurveWithIt4.eps");
826 }
827  trace.endBlock();
828 
829 
832 
833  Curve vPts3;
834  vPts3.assign( fc2.begin(), fc2.end() );
835 
836  ConstCirculator c2(vPts3.begin(),vPts3.begin(),vPts3.end());
837 
838  trace.beginBlock("saturated Segmentation of a closed digital curve (mode=First)");
839 {
840  Board2D aBoard;
841  aBoard << SetMode("PointVector", "Grid") << fc2;
842  aBoard << SetMode("PointVector", "Paving") << *c2;
843 
844  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
845  (c2,c2,c2,c2,
846  "First",aBoard);
847 
848  aBoard.saveEPS("MSClosedCurveWithCirc2.eps");
849 }
850  trace.endBlock();
851 
852  trace.beginBlock("saturated Segmentation of a closed digital curve (mode=MostCentered)");
853 {
854  Board2D aBoard;
855  aBoard << SetMode("PointVector", "Grid") << fc2;
856  aBoard << SetMode("PointVector", "Paving") << *c2;
857 
858  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
859  (c2,c2,c2,c2,
860  "MostCentered",aBoard);
861 
862  aBoard.saveEPS("MSClosedCurveWithCirc3.eps");
863 }
864  trace.endBlock();
865 
866  trace.beginBlock("saturated Segmentation of a closed digital curve (mode=Last)");
867 {
868  Board2D aBoard;
869  aBoard << SetMode("PointVector", "Grid") << fc2;
870  aBoard << SetMode("PointVector", "Paving") << *c2;
871 
872  segmentationIntoMaximalDSSs<ConstCirculator,Board2D>
873  (c2,c2,c2,c2,
874  "Last",aBoard);
875 
876  aBoard.saveEPS("MSClosedCurveWithCirc4.eps");
877 }
878  trace.endBlock();
879 
881 
882  return true;
883 
884 }
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
GridCurve< K2 > Curve
Definition: StdDefs.h:116
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ segmentationIntoDSSs()

template<typename Iterator , typename Board >
void segmentationIntoDSSs ( const Iterator &  itb,
const Iterator &  ite,
const Iterator &  sitb,
const Iterator &  site,
const string &  aMode,
Board aBoard 
)

Greedy segmentation of a (sub)range

Definition at line 150 of file testSegmentation.cpp.

153 {
154  typedef typename IteratorCirculatorTraits<Iterator>::Value::Coordinate Coordinate;
155  typedef ArithmeticalDSSComputer<Iterator,Coordinate,4> RecognitionAlgorithm;
156  typedef GreedySegmentation<RecognitionAlgorithm> Segmentation;
157 
158  RecognitionAlgorithm algo;
159  Segmentation s(itb,ite,algo);
160  s.setSubRange(sitb,site);
161  s.setMode(aMode);
162 
163  typename Segmentation::SegmentComputerIterator i = s.begin();
164  typename Segmentation::SegmentComputerIterator end = s.end();
165 
166  draw<typename Segmentation::SegmentComputerIterator, Board>
167  (i,end,aBoard);
168 
169 }
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators. The last element of a given segment is the first one one of the next segment.
Aim: Provides nested types for both iterators and circulators: Type, Category, Value, Difference, Pointer and Reference.

◆ segmentationIntoMaximalDSSs()

template<typename Iterator , typename Board >
void segmentationIntoMaximalDSSs ( const Iterator &  itb,
const Iterator &  ite,
const Iterator &  sitb,
const Iterator &  site,
const string &  aMode,
Board aBoard 
)

saturated segmentation of a (sub)range

Examples:
geometry/curves/convex-and-concave-parts.cpp.

Definition at line 175 of file testSegmentation.cpp.

178 {
179  typedef typename IteratorCirculatorTraits<Iterator>::Value::Coordinate Coordinate;
180  typedef ArithmeticalDSSComputer<Iterator,Coordinate,4> RecognitionAlgorithm;
181  typedef SaturatedSegmentation<RecognitionAlgorithm> Segmentation;
182 
183  RecognitionAlgorithm algo;
184  Segmentation s(itb,ite,algo);
185  s.setSubRange(sitb,site);
186  s.setMode(aMode);
187 
188  typename Segmentation::SegmentComputerIterator i = s.begin();
189  typename Segmentation::SegmentComputerIterator end = s.end();
190 
191  drawCCP<typename Segmentation::SegmentComputerIterator, Board>
192  (i,end,aBoard);
193 
194 }
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Provides nested types for both iterators and circulators: Type, Category, Value, Difference, Pointer and Reference.
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...