DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
greedy-dss-decomposition.cpp
Go to the documentation of this file.
1
16
30
48
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;
75
typedef
ArithmeticalDSSComputer<Contour4::ConstIterator,int,4>
DSS4;
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 DGTAL_WITH_CAIRO
116
aBoard.
saveCairo
(
"greedy-dss-decomposition.png"
);
117
#endif
118
119
trace
.
endBlock
();
120
121
return
0;
122
}
123
// //
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition
ArithmeticalDSSComputer.h:87
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Color::Blue
static const Color Blue
Definition
Color.h:428
DGtal::FreemanChain
Definition
FreemanChain.h:116
DGtal::GreedySegmentation
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Definition
GreedySegmentation.h:150
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::endBlock
double endBlock()
DGtal::Domain
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1138
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::CustomPenColor::CustomPenColor
CustomPenColor(const Color &penColor)
Definition
Board2D.h:321
DGtal::CustomStyle::CustomStyle
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition
Board2D.h:224
DGtal::SetMode::SetMode
SetMode(std::string classname, std::string mode)
Definition
Board2D.h:254
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
examples
geometry
curves
greedy-dss-decomposition.cpp
Generated on
for DGtal by
1.18.0