DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
greedy-dss-decomposition.cpp
1 
31 
32 #include <cmath>
33 #include <iostream>
34 #include <sstream>
35 #include "DGtal/base/Common.h"
36 #include "DGtal/io/boards/Board2D.h"
37 #include "DGtal/io/Color.h"
38 #include "DGtal/io/colormaps/GradientColorMap.h"
39 #include "DGtal/shapes/Shapes.h"
40 #include "DGtal/helpers/StdDefs.h"
41 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
42 #include "DGtal/geometry/curves/FreemanChain.h"
43 #include "DGtal/geometry/curves/GreedySegmentation.h"
45 
46 using namespace std;
47 using namespace DGtal;
48 using namespace Z2i;
49 
51 
52 int main( )
53 {
54  trace.beginBlock ( "Example dgtalboard-5-greedy-dss" );
55 
56  typedef FreemanChain<int> Contour4;
58  typedef GreedySegmentation<DSS4> Decomposition4;
59 
60  // A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements.
61  std::stringstream ss(stringstream::in | stringstream::out);
62  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
63 
64  // Construct the Freeman chain
65  Contour4 theContour( ss );
66 
67  //Segmentation
68  Decomposition4 theDecomposition( theContour.begin(),theContour.end(),DSS4() );
69  Point p1( 0, 0 );
70  Point p2( 31, 31 );
71  Domain domain( p1, p2 );
72  Board2D aBoard;
73  aBoard << SetMode( domain.className(), "Grid" )
74  << domain
75  << SetMode( "PointVector", "Grid" )
76  << theContour;
77  //for each segment
78  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" );
79  string className = "ArithmeticalDSS/BoundingBox";
80  for ( Decomposition4::SegmentComputerIterator i = theDecomposition.begin();
81  i != theDecomposition.end(); ++i )
82  {
83  DSS4 segment(*i);
84  std::cout << segment << std::endl;
85  aBoard << CustomStyle( className,
86  new CustomPenColor( Color::Blue ) )
87  << segment; // draw each segment
88 
89  }
90  aBoard.saveSVG("dgtalboard-5-greedy-dss.svg");
91  aBoard.saveSVG("dgtalboard-5-greedy-dss.eps");
92 
93  trace.endBlock();
94 
95  return 0;
96 }
97 // //