DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleDigitalConvexity.cpp
Go to the documentation of this file.
1
16
29
30
41
42
44
#include <iostream>
45
46
#include "DGtal/base/Common.h"
47
#include "DGtal/helpers/StdDefs.h"
48
#include "ConfigExamples.h"
49
50
#include "DGtal/geometry/curves/FreemanChain.h"
51
#include "DGtal/geometry/curves/GridCurve.h"
52
#include "DGtal/geometry/volumes/DigitalConvexity.h"
53
54
#include "DGtal/io/boards/Board2D.h"
55
57
58
using namespace
std
;
59
using namespace
DGtal
;
60
using namespace
Z2i
;
61
62
64
int
main
( )
65
{
66
trace
.
beginBlock
(
"Example for 2d gridcurves"
);
67
string
S = examplesPath +
"samples/contourS.fc"
;
68
69
// domain
70
const
Point
lowerBound( -200, -200 );
71
const
Point
upperBound( 200, 200 );
72
73
fstream inputStream( S.c_str(), ios::in );
74
FreemanChain<int>
fc(inputStream);
75
inputStream.close();
76
Curve
c;
77
c.
initFromPointsRange
( fc.
begin
(), fc.
end
() );
78
auto
points = c.
getPointsRange
();
79
std::vector<Point> T( points.begin(), points.end() );
80
Board2D
aBoard;
81
aBoard.
setUnit
(
Board2D::UCentimeter
);
82
DigitalConvexity<KSpace>
dconv( lowerBound, upperBound );
83
auto
c_cover = dconv.makeCellCover( T.begin(), T.end(), 1, 1 );
84
const
float
sx = -0.5;
85
const
float
sy = -0.5;
86
trace
.
beginBlock
(
"Compute fully subconvex sets"
);
87
for
(
size_t
i = 0; i < T.size(); ++i )
88
for
(
size_t
j = i+2; j < T.size(); ++j )
89
{
90
aBoard.
setPenColorRGBi
( rand() % 255, rand() % 255, rand() % 255 );
91
size_t
k = (i+j)/2;
92
if
( ! dconv.isSimplexFullDimensional( { T[i], T[j], T[k] } ) )
continue
;
93
auto
triangle = dconv.makeSimplex( { T[i], T[j], T[k] } );
94
if
( dconv.isFullySubconvex( triangle, c_cover ) )
95
{
96
aBoard.
drawLine
( sx+(
float
)T[i][0], sy+(
float
)T[i][1],
97
sx+(
float
)T[j][0], sy+(
float
)T[j][1] );
98
aBoard.
drawLine
( sx+(
float
)T[i][0], sy+(
float
)T[i][1],
99
sx+(
float
)T[k][0], sy+(
float
)T[k][1] );
100
aBoard.
drawLine
( sx+(
float
)T[k][0], sy+(
float
)T[k][1],
101
sx+(
float
)T[j][0], sy+(
float
)T[j][1] );
102
}
103
else
104
j = T.size();
105
}
106
trace
.
endBlock
();
107
aBoard.
setPenColor
(
Color::Black
);
108
aBoard << c;
109
aBoard.
saveEPS
(
"myGridCurve.eps"
,
Board2D::BoundingBox
);
//, 5000 );
110
trace
.
endBlock
();
111
return
0;
112
}
113
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Color::Black
static const Color Black
Definition
Color.h:422
DGtal::DigitalConvexity
Aim: A helper class to build polytopes from digital sets and to check digital k-convexity and full co...
Definition
DigitalConvexity.h:78
DGtal::FreemanChain
Definition
FreemanChain.h:116
DGtal::FreemanChain::end
ConstIterator end() const
DGtal::FreemanChain::begin
ConstIterator begin() const
DGtal::GridCurve::getPointsRange
PointsRange getPointsRange() const
Definition
GridCurve.h:418
DGtal::GridCurve::initFromPointsRange
bool initFromPointsRange(const TIterator &itb, const TIterator &ite)
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::endBlock
double endBlock()
LibBoard::Board::setPenColor
Board & setPenColor(const DGtal::Color &color)
Definition
Board.cpp:297
LibBoard::Board::UCentimeter
@ UCentimeter
Definition
Board.h:43
LibBoard::Board::drawLine
void drawLine(double x1, double y1, double x2, double y2, int depthValue=-1)
Definition
Board.cpp:367
LibBoard::Board::BoundingBox
@ BoundingBox
Definition
Board.h:42
LibBoard::Board::setPenColorRGBi
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition
Board.cpp:277
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition
Board.cpp:239
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal::Z2i::Curve
GridCurve< K2 > Curve
Definition
StdDefs.h:116
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.
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
geometry
curves
exampleDigitalConvexity.cpp
Generated on
for DGtal by
1.18.0