DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleLatticeBallDelaunay2D.cpp
Go to the documentation of this file.
1
16
29
52
53
#include "DGtal/base/Common.h"
55
#include "DGtal/geometry/tools/QuickHull.h"
57
#include "DGtal/shapes/SurfaceMesh.h"
58
#include "DGtal/io/writers/SurfaceMeshWriter.h"
59
60
using namespace
DGtal::Z2i
;
61
int
main
(
int
argc,
char
* argv[] )
62
{
63
int
nb = argc > 1 ? atoi( argv[ 1 ] ) : 100;
// nb points
64
double
dR = argc > 2 ? atof( argv[ 2 ] ) : 10.0;
// radius of ball
65
// (0) typedefs
67
typedef
DGtal::DelaunayIntegralKernel< 2 >
Kernel2D;
68
typedef
DGtal::QuickHull< Kernel2D >
Delaunay2D;
70
// (1) create range of random points in ball
71
std::vector< Point > V;
72
const
double
R2 = dR * dR;
73
const
int
R = (int) ceil( dR );
74
for
(
int
i = 0; i < nb; ) {
75
Point
p( rand() % (2*R+1) - R, rand() % (2*R+1) - R, rand() % (2*R+1) - R );
76
if
( p.
squaredNorm
() < R2 ) { V.push_back( p ); i++; }
77
}
78
// (2) compute convex hull
80
Delaunay2D hull;
81
hull.
setInput
( V );
82
hull.computeConvexHull();
83
std::cout <<
"#points="
<< hull.nbPoints()
84
<<
" #vertices="
<< hull.nbVertices()
85
<<
" #facets="
<< hull.nbFacets() << std::endl;
88
double
total_time = 0;
89
std::for_each( hull.timings.cbegin(), hull.timings.cend(),
90
[&total_time] (
double
t ) { total_time += t; } );
91
std::cout <<
"purge duplicates= "
<< round(hull.timings[ 0 ]) <<
" ms."
<< std::endl;
92
std::cout <<
"init simplex = "
<< round(hull.timings[ 1 ]) <<
" ms."
<< std::endl;
93
std::cout <<
"quickhull core = "
<< round(hull.timings[ 2 ]) <<
" ms."
<< std::endl;
94
std::cout <<
"compute vertices= "
<< round(hull.timings[ 3 ]) <<
" ms."
<< std::endl;
95
std::cout <<
"total time = "
<< round(total_time) <<
" ms."
<< std::endl;
97
// (3) build mesh
99
std::vector< RealPoint > positions;
100
hull.getVertexPositions( positions );
101
std::vector< std::vector< std::size_t > > facets;
102
hull.getFacetVertices( facets );
103
// Finite facets precede infinite facets => keep only finite facets
104
facets.resize( hull.nbFiniteFacets() );
105
// To visualize the result, we build a surface mesh in R3 lying in
106
// the plane z=0 and composed of the Delaunay cells.
107
typedef
DGtal::SpaceND< 3, int >
Z3;
108
std::vector< Z3::RealPoint > positions3d;
109
for
(
auto
p : positions )
110
positions3d.push_back( Z3::RealPoint( p[ 0 ], p[ 1 ], 0.0 ) );
111
typedef
DGtal::SurfaceMesh< Z3::RealPoint, Z3::RealVector>
SMesh
;
112
SMesh
mesh( positions3d.cbegin(), positions3d.cend(),
113
facets.cbegin(), facets.cend() );
115
// (4) output result as OBJ file
117
std::ofstream out(
"delaunay.obj"
);
118
DGtal::SurfaceMeshWriter< Z3::RealPoint, Z3::RealVector >::writeOBJ
( out, mesh );
119
out.close();
121
return
0;
122
}
DGtal::PointVector::squaredNorm
double squaredNorm() const
DGtal::SpaceND
Definition
SpaceND.h:96
SMesh
SurfaceMesh< RealPoint, RealVector > SMesh
Definition
fullConvexitySphereGeodesics.cpp:115
DGtal::Z2i
Z2i this namespace gathers the standard of types for 2D imagery.
DGtal::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::DelaunayIntegralKernel
Aim: a geometric kernel to compute the Delaunay triangulation of digital points with integer-only ari...
Definition
QuickHullKernels.h:504
DGtal::QuickHull
Aim: Implements the quickhull algorithm by Barber et al. barber1996, a famous arbitrary dimensional c...
Definition
QuickHull.h:141
DGtal::QuickHull::setInput
bool setInput(const std::vector< InputPoint > &input_points, bool remove_duplicates=true)
Definition
QuickHull.h:383
DGtal::SurfaceMeshWriter::writeOBJ
static bool writeOBJ(std::ostream &output, const SurfaceMesh &smesh)
DGtal::SurfaceMesh
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition
SurfaceMesh.h:92
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
geometry
tools
exampleLatticeBallDelaunay2D.cpp
Generated on
for DGtal by
1.18.0