DGtal  0.9.3
greedy-dss-decomposition.cpp
Go to the documentation of this file.
1 
49 #include <cmath>
51 #include <iostream>
52 #include <sstream>
53 #include "DGtal/base/Common.h"
54 #include "DGtal/io/boards/Board2D.h"
55 #include "DGtal/io/Color.h"
56 #include "DGtal/io/colormaps/GradientColorMap.h"
57 #include "DGtal/shapes/Shapes.h"
58 #include "DGtal/helpers/StdDefs.h"
59 #include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
60 #include "DGtal/geometry/curves/FreemanChain.h"
61 #include "DGtal/geometry/curves/GreedySegmentation.h"
63 
64 using namespace std;
65 using namespace DGtal;
66 using namespace Z2i;
67 
69 
70 int main( )
71 {
72  trace.beginBlock ( "Example dgtalboard-5-greedy-dss" );
73 
74  typedef FreemanChain<int> Contour4;
76  typedef GreedySegmentation<DSS4> Decomposition4;
77 
78  // A Freeman chain code is a string composed by the coordinates of the first pixel, and the list of elementary displacements.
79  std::stringstream ss(stringstream::in | stringstream::out);
80  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
81 
82  // Construct the Freeman chain
83  Contour4 theContour( ss );
84 
85  // Segmentation
86  Decomposition4 theDecomposition( theContour.begin(),theContour.end(),DSS4() );
87 
88  // Draw the domain and the contour
89  Point p1( 0, 0 );
90  Point p2( 31, 31 );
91  Domain domain( p1, p2 );
92  Board2D aBoard;
93  aBoard << SetMode( domain.className(), "Grid" )
94  << domain
95  << SetMode( "PointVector", "Grid" );
96 
97  // Draw each segment
98  string styleName = "";
99  for ( Decomposition4::SegmentComputerIterator
100  it = theDecomposition.begin(),
101  itEnd = theDecomposition.end();
102  it != itEnd; ++it )
103  {
104  aBoard << SetMode( "ArithmeticalDSS", "Points" )
105  << it->primitive();
106  aBoard << SetMode( "ArithmeticalDSS", "BoundingBox" )
107  << CustomStyle( "ArithmeticalDSS/BoundingBox",
108  new CustomPenColor( Color::Blue ) )
109  << it->primitive();
110  }
111 
112 
113  aBoard.saveSVG("greedy-dss-decomposition.svg");
114  aBoard.saveEPS("greedy-dss-decomposition.eps");
115  #ifdef WITH_CAIRO
116  aBoard.saveCairo("greedy-dss-decomposition.png");
117  #endif
118 
119  trace.endBlock();
120 
121  return 0;
122 }
123 // //
void beginBlock(const std::string &keyword="")
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
STL namespace.
double endBlock()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
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.
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
std::string className() const
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
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 &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70