DGtal  1.5.beta
greedy-dss-decomposition.cpp
Go to the documentation of this file.
1 
50 #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 // //
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 <<)....
Definition: Board2D.h:71
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
std::string className() const
void beginBlock(const std::string &keyword="")
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1138
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:313
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Domain domain