DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
convex-and-concave-parts.cpp
Go to the documentation of this file.
1
16
52
54
#include <cmath>
55
#include <iostream>
56
#include <sstream>
57
#include <fstream>
58
#include "DGtal/base/Common.h"
59
#include "DGtal/io/boards/Board2D.h"
60
#include "DGtal/io/Color.h"
61
#include "DGtal/shapes/Shapes.h"
62
#include "DGtal/helpers/StdDefs.h"
63
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
64
#include "DGtal/geometry/curves/FreemanChain.h"
65
#include "DGtal/geometry/curves/SaturatedSegmentation.h"
67
#include "ConfigExamples.h"
68
69
using namespace
std
;
70
using namespace
DGtal
;
71
using namespace
Z2i
;
72
74
75
77
94
template
<
typename
Iterator,
typename
Board>
95
void
drawCCP
(
const
Iterator
& itb,
const
Iterator
& ite, Board& aBoard)
96
{
97
98
//choose the drawing mode
99
aBoard <<
SetMode
(
"ArithmeticalDSS"
,
"BoundingBox"
);
100
//prepare the drawing style and the pen color
101
string
aStyleName =
"ArithmeticalDSS/BoundingBox"
;
102
CustomPenColor
* aPenColor;
103
104
//for each maximal segment
105
for
(
Iterator
i(itb); i != ite; ++i) {
106
107
//get the current maximal segment
108
typedef
typename
Iterator::SegmentComputer::Primitive DSS;
109
DSS maximalDSS = i->primitive();
110
111
//if located at the end of a connected part
112
if
( !(i.intersectNext() && i.intersectPrevious()) ) {
113
114
aPenColor =
new
CustomPenColor
(
Color::Black
);
115
116
//otherwise
117
}
else
{
118
119
//get the points located before and after the maximal segment
120
typedef
typename
DSS::Point
Point
;
121
Point
beforeFirst = *(--(i->begin()));
122
Point
afterLast = *(i->end());
123
124
//remainders and bounds
125
typedef
typename
DSS::Integer
Integer
;
126
Integer
r1 = maximalDSS.remainder(beforeFirst);
127
Integer
r2 = maximalDSS.remainder(afterLast);
128
Integer
mu = maximalDSS.mu();
129
Integer
omega = maximalDSS.omega();
130
131
//configurations
132
if
( (r1<=mu-1)&&(r2<=mu-1) ) {
//concave
133
aPenColor =
new
CustomPenColor
(
Color::Green
);
134
}
else
if
( (r1>=mu+omega)&&(r2>=mu+omega) ) {
//convex
135
aPenColor =
new
CustomPenColor
(
Color::Blue
);
136
}
else
if
( (r1>=mu+omega)&&(r2<=mu-1) ) {
//convex to concave
137
aPenColor =
new
CustomPenColor
(
Color::Yellow
);
138
}
else
if
( (r1<=mu-1)&&(r2>=mu+omega) ) {
//concave to convex
139
aPenColor =
new
CustomPenColor
(
Color::Yellow
);
140
}
else
{
//pb
141
aPenColor =
new
CustomPenColor
(
Color::Red
);
142
}
143
144
}
145
146
// draw the maximal segment on the board
147
aBoard <<
CustomStyle
( aStyleName, aPenColor )
148
<< maximalDSS;
149
150
}
151
152
}
153
166
template
<
typename
Iterator,
typename
Board>
167
void
segmentationIntoMaximalDSSs
(
const
Iterator
& itb,
const
Iterator
& ite,
168
Board& aBoard)
169
{
170
typedef
typename
IteratorCirculatorTraits<Iterator>::Value::Coordinate
Coordinate
;
171
172
//choose the primitive computer and the segmentation
173
typedef
ArithmeticalDSSComputer<Iterator,Coordinate,4>
RecognitionAlgorithm;
174
typedef
SaturatedSegmentation<RecognitionAlgorithm>
Segmentation
;
175
176
//create the segmentation
177
RecognitionAlgorithm algo;
178
Segmentation
s(itb,ite,algo);
179
180
//draw the result
181
drawCCP
(s.
begin
(), s.
end
(), aBoard);
182
}
183
184
194
int
main
(
int
argc,
char
** argv )
195
{
196
197
trace
.
beginBlock
(
"Example convex-and-concave-parts"
);
198
199
Board2D
aBoard;
//create a board
200
201
//create a chain code
202
string
codes;
203
if
(argc >= 2) codes = argv[1];
204
else
codes =
"030030330303303030300001010101101011010000030330303303030300001010110101011010000033"
;
205
206
stringstream ss(stringstream::in | stringstream::out);
207
ss <<
"0 0 "
<< codes << endl;
208
FreemanChain<int>
theContour( ss );
209
210
trace
.
info
() <<
"Processing of "
<< ss.str() << endl;
211
212
//draw the digital contour
213
aBoard
214
<<
SetMode
(
"PointVector"
,
"Grid"
)
215
<< theContour;
216
217
//draw the maximal segments
218
segmentationIntoMaximalDSSs
(theContour.
begin
(), theContour.
end
(), aBoard);
219
220
//save the drawing
221
aBoard.
saveSVG
(
"convex-and-concave-parts.svg"
);
222
#ifdef DGTAL_WITH_CAIRO
223
aBoard.
saveCairo
(
"convex-and-concave-parts.png"
);
224
#endif
225
226
trace
.
endBlock
();
227
228
return
0;
229
}
230
// //
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::Red
static const Color Red
Definition
Color.h:425
DGtal::Color::Black
static const Color Black
Definition
Color.h:422
DGtal::Color::Blue
static const Color Blue
Definition
Color.h:428
DGtal::Color::Yellow
static const Color Yellow
Definition
Color.h:431
DGtal::Color::Green
static const Color Green
Definition
Color.h:426
DGtal::FreemanChain
Definition
FreemanChain.h:116
DGtal::FreemanChain::end
ConstIterator end() const
DGtal::FreemanChain::begin
ConstIterator begin() const
DGtal::Iterator
DGtal::SaturatedSegmentation
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
Definition
SaturatedSegmentation.h:154
DGtal::SaturatedSegmentation::end
SaturatedSegmentation::SegmentComputerIterator end() const
DGtal::SaturatedSegmentation::begin
SaturatedSegmentation::SegmentComputerIterator begin() const
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
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::Z2i::Integer
DGtal::int32_t Integer
Definition
StdDefs.h:74
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
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color.
Definition
Board2D.h:313
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::IteratorCirculatorTraits
Aim: Provides nested types for both iterators and circulators: Type, Category, Value,...
Definition
IteratorCirculatorTraits.h:294
DGtal::SetMode::SetMode
SetMode(std::string classname, std::string mode)
Definition
Board2D.h:254
Segmentation
SaturatedSegmentation< SegmentComputer > Segmentation
Definition
testArithmeticalDSSComputerOnSurfels.cpp:56
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
segmentationIntoMaximalDSSs
void segmentationIntoMaximalDSSs(const Iterator &itb, const Iterator &ite, const Iterator &sitb, const Iterator &site, const string &aMode, Board &aBoard)
Definition
testSegmentation.cpp:175
drawCCP
void drawCCP(const Iterator &itb, const Iterator &ite, Board &aBoard)
Definition
testSegmentation.cpp:93
examples
geometry
curves
convex-and-concave-parts.cpp
Generated on
for DGtal by
1.18.0