44#include "DGtal/base/Common.h"
45#include "DGtal/base/Exceptions.h"
47#include "DGtal/io/boards/Board2D.h"
48#include "DGtal/io/Color.h"
50#include "DGtal/base/Circulator.h"
52#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
53#include "DGtal/geometry/curves/FreemanChain.h"
54#include "DGtal/geometry/curves/GreedySegmentation.h"
55#include "DGtal/geometry/curves/SaturatedSegmentation.h"
58#include "ConfigTest.h"
74template <
typename Iterator,
typename Board>
75void draw(
const Iterator& itb,
const Iterator& ite,
Board& aBoard)
78 for (Iterator i(itb); i != ite; ++i) {
80 typename Iterator::SegmentComputer segment(*i);
82 aBoard <<
SetMode(segment.primitive().className(),
"BoundingBox" )
83 << segment.primitive();
92template <
typename Iterator,
typename Board>
93void drawCCP(
const Iterator& itb,
const Iterator& ite,
Board& aBoard)
96 typedef typename Iterator::SegmentComputer::ConstIterator PointIterator;
98 for (Iterator i(itb); i != ite; ++i) {
103 if ( !(i.intersectNext() && i.intersectPrevious()) ) {
111 PointIterator begin = i->begin(); --begin;
112 PointIterator end = i->end();
116 int omega = i->omega();
119 if ( (i->remainder(begin)<=mu-1)&&
120 (i->remainder(end)<=mu-1) ) {
122 }
else if ( (i->remainder(begin)>=mu+omega)&&
123 (i->remainder(end)>=mu+omega) ) {
125 }
else if ( (i->remainder(begin)>=mu+omega)&&
126 (i->remainder(end)<=mu-1) ) {
128 }
else if ( (i->remainder(begin)<=mu-1)&&
129 (i->remainder(end)>=mu+omega) ) {
138 aBoard <<
SetMode(i->primitive().className(),
"BoundingBox" )
139 <<
CustomStyle( i->primitive().className(), aPenColor )
149template <
typename Iterator,
typename Board>
151 const Iterator& sitb,
const Iterator& site,
152 const string& aMode,
Board& aBoard)
158 RecognitionAlgorithm algo;
160 s.setSubRange(sitb,site);
174template <
typename Iterator,
typename Board>
176 const Iterator& sitb,
const Iterator& site,
177 const string& aMode,
Board& aBoard)
183 RecognitionAlgorithm algo;
185 s.setSubRange(sitb,site);
203 typedef int Coordinate;
209 std::string filename = testPath +
"samples/manche.fc";
212 fst.open (filename.c_str(), std::ios::in);
221 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
224 (fc.begin(),fc.end(),
228 aBoard.
saveEPS(
"WholeOpenCurveWithItMode1.eps");
236 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
239 (fc.begin(),fc.end(),
241 "DoNotTruncate",aBoard);
243 aBoard.
saveEPS(
"WholeOpenCurveWithItMode3.eps");
250 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
253 (fc.begin(),fc.end(),
255 "Truncate+1",aBoard);
257 aBoard.
saveEPS(
"WholeOpenCurveWithItMode2.eps");
265 typedef vector<PointVector<2,Coordinate> > Curve;
266 typedef Curve::const_iterator RAConstIterator;
269 vPts.assign ( fc.begin(), fc.end() );
271 RAConstIterator start = vPts.begin()+15;
272 RAConstIterator stop = vPts.begin()+200;
274trace.
info() << *start <<
" " << *stop << endl;
279 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
280 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
283 (vPts.begin(),vPts.end(),
287 aBoard.
saveEPS(
"PartOpenCurveWithItMode1.eps");
294 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
295 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
298 (vPts.begin(),vPts.end(),
300 "Truncate+1",aBoard);
302 aBoard.
saveEPS(
"PartOpenCurveWithItMode2.eps");
310 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
311 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
314 (vPts.begin(),vPts.end(),
316 "DoNotTruncate",aBoard);
318 aBoard.
saveEPS(
"PartOpenCurveWithItMode3.eps");
327 ConstCirculator c(vPts.begin(),vPts.begin(),vPts.end());
329 trace.
beginBlock(
"Segmentation of a whole range (mode1) with circulators");
332 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
338 aBoard.
saveEPS(
"WholeOpenCurveWithCircMode1.eps");
342 trace.
beginBlock(
"Segmentation of a whole range (mode2) with circulators");
345 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
349 "Truncate+1",aBoard);
351 aBoard.
saveEPS(
"WholeOpenCurveWithCircMode2.eps");
356 trace.
beginBlock(
"Segmentation of a whole range (mode3) with circulators");
359 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
363 "DoNotTruncate",aBoard);
365 aBoard.
saveEPS(
"WholeOpenCurveWithCircMode3.eps");
372 ConstCirculator cstart(start,vPts.begin(),vPts.end());
373 ConstCirculator cstop(stop,vPts.begin(),vPts.end());
375 trace.
beginBlock(
"Segmentation of a subrange (mode1) with circulators");
378 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
379 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
386 aBoard.
saveEPS(
"PartOpenCurveWithCircMode1.eps");
390 trace.
beginBlock(
"Segmentation of a subrange (mode2) with circulators");
393 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
394 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
399 "Truncate+1",aBoard);
401 aBoard.
saveEPS(
"PartOpenCurveWithCircMode2.eps");
406 trace.
beginBlock(
"Segmentation of a subrange (mode3) with circulators");
409 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
410 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
415 "DoNotTruncate",aBoard);
417 aBoard.
saveEPS(
"PartOpenCurveWithCircMode3.eps");
424 std::stringstream ss(stringstream::in | stringstream::out);
425 ss <<
"31 16 1112121212121221212121221212212222232232323332333333332333332330333033003030000010001001001000100010101010111" << endl;
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() );
437 RAConstIterator start2 = vPts2.begin() + fc2.size()+1;
438 RAConstIterator stop2 = start2 + fc2.size()+1;
440trace.
info() << *start2 <<
" " << *stop2 << endl;
442 trace.
beginBlock(
"Segmentation of a subrange of a duplicated range (mode1)");
445 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
446 aBoard <<
SetMode(
"PointVector",
"Paving") << *start2 << *stop2;
449 (vPts2.begin(),vPts2.end(),
453 aBoard.
saveEPS(
"DuplicatedCurveWithItMode1.eps");
457 trace.
beginBlock(
"Segmentation of a subrange of a duplicated range (mode2)");
460 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
461 aBoard <<
SetMode(
"PointVector",
"Paving") << *start2 << *stop2;
464 (vPts2.begin(),vPts2.end(),
466 "Truncate+1",aBoard);
468 aBoard.
saveEPS(
"DuplicatedCurveWithItMode2.eps");
473 trace.
beginBlock(
"Segmentation of a subrange of a duplicated range (mode3)");
476 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
477 aBoard <<
SetMode(
"PointVector",
"Paving") << *start2 << *stop2;
480 (vPts2.begin(),vPts2.end(),
482 "DoNotTruncate",aBoard);
484 aBoard.
saveEPS(
"DuplicatedCurveWithItMode3.eps");
492 ConstCirculator c2(start2,start2,stop2);
494 trace.
beginBlock(
"Segmentation of a whole range (mode1) with circulators");
497 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
503 aBoard.
saveEPS(
"ClosedCurveWithCircMode1.eps");
507 trace.
beginBlock(
"Segmentation of a whole range (mode2) with circulators");
510 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
514 "Truncate+1",aBoard);
516 aBoard.
saveEPS(
"ClosedCurveWithCircMode2.eps");
521 trace.
beginBlock(
"Segmentation of a whole range (mode3) with circulators");
524 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
528 "DoNotTruncate",aBoard);
530 aBoard.
saveEPS(
"ClosedCurveWithCircMode3.eps");
552 typedef int Coordinate;
556 std::string filename = testPath +
"samples/manche.fc";
559 fst.open (filename.c_str(), std::ios::in);
568 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
571 (fc.begin(),fc.end(),
575 aBoard.
saveEPS(
"MSOpenCurve2.eps");
582 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
585 (fc.begin(),fc.end(),
587 "MostCentered",aBoard);
589 aBoard.
saveEPS(
"MSOpenCurve3.eps");
596 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
599 (fc.begin(),fc.end(),
603 aBoard.
saveEPS(
"MSOpenCurve4.eps");
610 typedef vector<PointVector<2,Coordinate> > Curve;
611 typedef Curve::const_iterator RAConstIterator;
614 vPts.assign ( fc.begin(), fc.end() );
616 RAConstIterator start = vPts.begin()+190;
617 RAConstIterator stop = vPts.begin()+400;
619trace.
info() << *start <<
" " << *stop << endl;
625 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
626 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
629 (vPts.begin(),vPts.end(),
633 aBoard.
saveEPS(
"MSOpenCurvePart2.eps");
637 trace.
beginBlock(
"saturated Segmentation of a subrange (mode=MostCentered)");
640 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
641 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
644 (vPts.begin(),vPts.end(),
646 "MostCentered",aBoard);
648 aBoard.
saveEPS(
"MSOpenCurvePart3.eps");
655 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
656 aBoard <<
SetMode(
"PointVector",
"Paving") << *start << *stop;
659 (vPts.begin(),vPts.end(),
663 aBoard.
saveEPS(
"MSOpenCurvePart4.eps");
672 ConstCirculator c(vPts.begin(),vPts.begin(),vPts.end());
675 trace.
beginBlock(
"Segmentation of a range bounded by circulators (mode=First)");
678 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
684 aBoard.
saveEPS(
"MSOpenCurveWithCirc2.eps");
688 trace.
beginBlock(
"Segmentation of a range bounded by circulators (mode=MostCentered)");
691 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
695 "MostCentered",aBoard);
697 aBoard.
saveEPS(
"MSOpenCurveWithCirc3.eps");
701 trace.
beginBlock(
"Segmentation of a range bounded by circulators (mode=Last)");
704 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
710 aBoard.
saveEPS(
"MSOpenCurveWithCirc4.eps");
718 ConstCirculator cstart(start,vPts.begin(),vPts.end());
719 ConstCirculator cstop(stop,vPts.begin(),vPts.end());
722 trace.
beginBlock(
"Segmentation of a subrange with circulators (mode=First)");
725 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
726 aBoard <<
SetMode(
"PointVector",
"Paving") << *cstart << *cstop;
732 aBoard.
saveEPS(
"MSOpenCurvePartWithCirc2.eps");
736 trace.
beginBlock(
"Segmentation of a subrange with circulators (mode=MostCentered)");
739 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
740 aBoard <<
SetMode(
"PointVector",
"Paving") << *cstart << *cstop;
744 "MostCentered",aBoard);
746 aBoard.
saveEPS(
"MSOpenCurvePartWithCirc3.eps");
750 trace.
beginBlock(
"Segmentation of a subrange with circulators (mode=Last)");
753 aBoard <<
SetMode(
"PointVector",
"Grid") << fc;
754 aBoard <<
SetMode(
"PointVector",
"Paving") << *cstart << *cstop;
760 aBoard.
saveEPS(
"MSOpenCurvePartWithCirc4.eps");
767 std::stringstream ss(stringstream::in | stringstream::out);
768 ss <<
"31 16 1112121212121221212121221212212222232232323332333333332333332330333033003030000010001001001000100010101010111" << endl;
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() );
778 RAConstIterator start2 = vPts2.begin() + fc2.size()+1;
779 RAConstIterator stop2 = start2 + fc2.size()+1;
781 trace.
info() << *start2 <<
" " << *stop2 << endl;
783 trace.
beginBlock(
"Satured Segmentation of a duplicated range (mode2)");
786 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
787 aBoard <<
SetMode(
"PointVector",
"Paving") << *start2 << *stop2;
790 (vPts2.begin(),vPts2.end(),
794 aBoard.
saveEPS(
"MSClosedCurveWithIt2.eps");
798 trace.
beginBlock(
"Satured Segmentation of a duplicated range (mode3)");
801 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
802 aBoard <<
SetMode(
"PointVector",
"Paving") << *start2 << *stop2;
805 (vPts2.begin(),vPts2.end(),
807 "MostCentered",aBoard);
809 aBoard.
saveEPS(
"MSClosedCurveWithIt3.eps");
814 trace.
beginBlock(
"Satured Segmentation of a duplicated range (mode4)");
817 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
818 aBoard <<
SetMode(
"PointVector",
"Paving") << *start2 << *stop2;
821 (vPts2.begin(),vPts2.end(),
825 aBoard.
saveEPS(
"MSClosedCurveWithIt4.eps");
834 vPts3.assign( fc2.begin(), fc2.end() );
836 ConstCirculator c2(vPts3.begin(),vPts3.begin(),vPts3.end());
838 trace.
beginBlock(
"saturated Segmentation of a closed digital curve (mode=First)");
841 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
842 aBoard <<
SetMode(
"PointVector",
"Paving") << *c2;
848 aBoard.
saveEPS(
"MSClosedCurveWithCirc2.eps");
852 trace.
beginBlock(
"saturated Segmentation of a closed digital curve (mode=MostCentered)");
855 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
856 aBoard <<
SetMode(
"PointVector",
"Paving") << *c2;
860 "MostCentered",aBoard);
862 aBoard.
saveEPS(
"MSClosedCurveWithCirc3.eps");
866 trace.
beginBlock(
"saturated Segmentation of a closed digital curve (mode=Last)");
869 aBoard <<
SetMode(
"PointVector",
"Grid") << fc2;
870 aBoard <<
SetMode(
"PointVector",
"Paving") << *c2;
876 aBoard.
saveEPS(
"MSClosedCurveWithCirc4.eps");
893 typedef int Coordinate;
896 std::string filename = testPath +
"samples/BigBall2.fc";
899 fst.open (filename.c_str(), std::ios::in);
905 vPts.assign(fc.begin(),fc.end());
918 RecognitionAlgorithm algo;
925 unsigned int compteur = 0;
930 trace.
info() <<
"# nbpts nbsegments " << endl;
931 trace.
info() << fc.size()+1 <<
" " << compteur << endl;
935 return (compteur == 4295);
945 trace.
beginBlock (
"Testing class GreedyDecomposition and SaturatedSegmentation" );
947 for (
int i = 0; i < argc; ++i )
956 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
static const Color Yellow
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: Specific iterator to visit all the maximal segments of a saturated segmentation.
const ConstIterator end() const
const ConstIterator begin() const
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
void beginBlock(const std::string &keyword="")
Class for EPS, FIG or SVG drawings.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Aim: Provides nested types for both iterators and circulators: Type, Category, Value,...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
SaturatedSegmentation< SegmentComputer > Segmentation
bool greedySegmentationVisualTest()
void segmentationIntoMaximalDSSs(const Iterator &itb, const Iterator &ite, const Iterator &sitb, const Iterator &site, const string &aMode, Board &aBoard)
bool SaturatedSegmentationVisualTest()
bool SaturatedSegmentationTest()
void drawCCP(const Iterator &itb, const Iterator &ite, Board &aBoard)
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
void segmentationIntoDSSs(const Iterator &itb, const Iterator &ite, const Iterator &sitb, const Iterator &site, const string &aMode, Board &aBoard)