DGtal  0.9.2
greedy-dss-decomposition.cpp
1
31 #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"
39 #include "DGtal/shapes/Shapes.h"
40 #include "DGtal/helpers/StdDefs.h"
41 #include "DGtal/geometry/curves/ArithmeticalDSSComputer.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
70  // Draw the domain and the contour
71  Point p1( 0, 0 );
72  Point p2( 31, 31 );
73  Domain domain( p1, p2 );
74  Board2D aBoard;
75  aBoard << SetMode( domain.className(), "Grid" )
76  << domain
77  << SetMode( "PointVector", "Grid" );
78
79  // Draw each segment
80  string styleName = "";
81  for ( Decomposition4::SegmentComputerIterator
82  it = theDecomposition.begin(),
83  itEnd = theDecomposition.end();
84  it != itEnd; ++it )
85  {
86  aBoard << SetMode( "ArithmeticalDSS", "Points" )
87  << it->primitive();
88  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" )
89  << CustomStyle( "ArithmeticalDSS/BoundingBox",
90  new CustomPenColor( Color::Blue ) )
91  << it->primitive();
92  }
93
94
95  aBoard.saveSVG("greedy-dss-decomposition.svg");
96  aBoard.saveEPS("greedy-dss-decomposition.eps");
97  #ifdef WITH_CAIRO
98  aBoard.saveCairo("greedy-dss-decomposition.png");
99  #endif
100
101  trace.endBlock();
102
103  return 0;
104 }
105 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
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.
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
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
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70