DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleBoundedLatticePolytopeCount4D.cpp
Go to the documentation of this file.
1
16
29
57
58
#include "DGtal/base/Common.h"
59
#include "DGtal/geometry/volumes/ConvexityHelper.h"
60
#include "DGtal/geometry/volumes/BoundedLatticePolytope.h"
61
62
int
main
(
int
argc,
char
* argv[] )
63
{
64
int
N = argc > 1 ? atoi( argv[ 1 ] ) : 10;
// nb of polytopes
65
int
nb = argc > 2 ? atoi( argv[ 2 ] ) : 10;
// nb points per polytope
66
int
R = argc > 3 ? atoi( argv[ 3 ] ) : 50;
// max diameter of shape
67
68
typedef
int64_t
Integer
;
69
typedef
DGtal::ConvexityHelper< 4, Integer >
Helper;
70
typedef
Helper::LatticePolytope Polytope;
71
typedef
Polytope::Point
Point
;
72
// Compute all polytopes
73
DGtal::trace
.
beginBlock
(
"Compute 4D polytopes"
);
74
std::vector< Polytope > polytopes;
75
int
sum_nb_facets = 0;
76
for
(
int
i = 0; i < N; i++ )
77
{
78
std::vector< Point > V;
79
for
(
int
j = 0; j < nb; j++ ) {
80
Point
p( rand() % (2*R+1) - R, rand() % (2*R+1) - R,
81
rand() % (2*R+1) - R, rand() % (2*R+1) - R );
82
V.push_back( p );
83
}
84
Polytope P = Helper::computeLatticePolytope( V );
85
sum_nb_facets += P.nbHalfSpaces();
86
polytopes.push_back( P );
87
}
88
double
t1 =
DGtal::trace
.
endBlock
();
89
DGtal::trace
.
info
() <<
"Computed "
<< N
90
<<
" 4D polytopes with "
<< ( sum_nb_facets / (double) N )
91
<<
" facets on average, in "
<< t1 <<
" ms."
<< std::endl;
92
// Count interior points (slow method)
93
DGtal::trace
.
beginBlock
(
"Compute number of lattice points within polytope (slow)"
);
94
std::size_t slow_nb = 0;
95
std::vector< Integer > slow_counts;
96
for
(
const
auto
& P : polytopes )
97
{
98
const
auto
nb2 = P.countByScanning();
99
slow_nb += nb2;
100
slow_counts.push_back( nb2 );
101
}
102
double
t2 =
DGtal::trace
.
endBlock
();
103
// Count interior points (fast method)
104
DGtal::trace
.
beginBlock
(
"Compute number of lattice points within polytope (fast)"
);
105
std::size_t fast_nb = 0;
106
std::vector< Integer > fast_counts;
107
for
(
const
auto
& P : polytopes )
108
{
109
const
auto
nb2 = P.count();
110
fast_nb += nb2;
111
fast_counts.push_back( nb2 );
112
}
113
double
t3 =
DGtal::trace
.
endBlock
();
114
bool
ok = std::equal( slow_counts.cbegin(), slow_counts.cend(), fast_counts.cbegin() );
115
DGtal::trace
.
info
() <<
"Computed inside points is "
<< ( ok ?
"OK"
:
"ERROR"
) << std::endl;
116
DGtal::trace
.
info
() <<
"Reference method computed "
<< slow_nb
117
<<
" points in "
<< t2 <<
" ms."
<< std::endl;
118
DGtal::trace
.
info
() <<
"Fast method computed "
<< fast_nb
119
<<
" points in "
<< t3 <<
" ms."
<< std::endl;
120
return
0;
121
}
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal::trace
Trace trace
DGtal::ConvexityHelper
Aim: Provides a set of functions to facilitate the computation of convex hulls and polytopes,...
Definition
ConvexityHelper.h:154
Point
MyPointD Point
Definition
testClone2.cpp:381
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
geometry
volumes
exampleBoundedLatticePolytopeCount4D.cpp
Generated on
for DGtal by
1.18.0