DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleRationalBallQuickHull3D.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
double
rand01
() {
return
(
double
) rand() / (double) RAND_MAX; }
61
62
using namespace
DGtal::Z3i
;
63
int
main
(
int
argc,
char
* argv[] )
64
{
65
int
nb = argc > 1 ? atoi( argv[ 1 ] ) : 100;
// nb points
66
double
R = argc > 2 ? atof( argv[ 2 ] ) : 10.0;
// radius of ball
67
double
precision = argc > 3 ? atof( argv[ 3 ] ) : 1024.0;
// precision
68
// (0) typedefs
70
typedef
DGtal::ConvexHullRationalKernel< 3 >
Kernel3D;
71
typedef
DGtal::QuickHull< Kernel3D >
QuickHull3D;
73
// (1) create range of random points in ball
74
std::vector< RealPoint > V;
75
const
double
R2 = R * R;
76
for
(
int
i = 0; i < nb; ) {
77
RealPoint
p(
rand01
()*2.0*R - R,
rand01
()*2.0*R - R,
rand01
()*2.0*R - R );
78
if
( p.
squaredNorm
() < R2 ) { V.push_back( p ); i++; }
79
}
80
// (2) compute convex hull
82
Kernel3D kernel( precision );
83
QuickHull3D hull( kernel );
84
hull.
setInput
( V );
85
hull.
computeConvexHull
();
86
std::cout <<
"#points="
<< hull.
nbPoints
()
87
<<
" #vertices="
<< hull.
nbVertices
()
88
<<
" #facets="
<< hull.
nbFacets
() << std::endl;
91
double
total_time = 0;
92
std::for_each( hull.
timings
.cbegin(), hull.
timings
.cend(),
93
[&total_time] (
double
t ) { total_time += t; } );
94
std::cout <<
"purge duplicates= "
<< round(hull.
timings
[ 0 ]) <<
" ms."
<< std::endl;
95
std::cout <<
"init simplex = "
<< round(hull.
timings
[ 1 ]) <<
" ms."
<< std::endl;
96
std::cout <<
"quickhull core = "
<< round(hull.
timings
[ 2 ]) <<
" ms."
<< std::endl;
97
std::cout <<
"compute vertices= "
<< round(hull.
timings
[ 3 ]) <<
" ms."
<< std::endl;
98
std::cout <<
"total time = "
<< round(total_time) <<
" ms."
<< std::endl;
100
// (3) build mesh
102
std::vector< RealPoint > positions;
103
hull.
getVertexPositions
( positions );
104
std::vector< std::vector< std::size_t > > facets;
105
hull.
getFacetVertices
( facets );
106
typedef
DGtal::SurfaceMesh< RealPoint, RealVector>
SMesh
;
107
SMesh
mesh( positions.cbegin(), positions.cend(), facets.cbegin(), facets.cend() );
109
// (4) output result as OBJ file
111
std::ofstream out(
"qhull.obj"
);
112
DGtal::SurfaceMeshWriter< RealPoint, RealVector >::writeOBJ
( out, mesh );
113
out.close();
115
return
0;
116
}
DGtal::PointVector::squaredNorm
double squaredNorm() const
SMesh
SurfaceMesh< RealPoint, RealVector > SMesh
Definition
fullConvexitySphereGeodesics.cpp:115
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal::Z3i::RealPoint
Space::RealPoint RealPoint
Definition
StdDefs.h:170
rand01
double rand01()
Definition
pConvexity-benchmark.cpp:70
DGtal::ConvexHullRationalKernel
Aim: a geometric kernel to compute the convex hull of floating points with integer-only arithmetic....
Definition
QuickHullKernels.h:656
DGtal::QuickHull< Kernel3D >
DGtal::QuickHull::setInput
bool setInput(const std::vector< InputPoint > &input_points, bool remove_duplicates=true)
Definition
QuickHull.h:383
DGtal::QuickHull::getFacetVertices
bool getFacetVertices(std::vector< IndexRange > &facet_vertices) const
Definition
QuickHull.h:667
DGtal::QuickHull::nbVertices
Size nbVertices() const
Definition
QuickHull.h:338
DGtal::QuickHull::getVertexPositions
bool getVertexPositions(std::vector< OutputPoint > &vertex_positions)
Definition
QuickHull.h:613
DGtal::QuickHull::nbFacets
Size nbFacets() const
Definition
QuickHull.h:329
DGtal::QuickHull::computeConvexHull
bool computeConvexHull(Status target=Status::VerticesCompleted)
Definition
QuickHull.h:461
DGtal::QuickHull::timings
std::vector< double > timings
Timings of the different phases: 0: init, 1: facets, 2: vertices.
Definition
QuickHull.h:827
DGtal::QuickHull::nbPoints
Size nbPoints() const
Definition
QuickHull.h:324
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
exampleRationalBallQuickHull3D.cpp
Generated on
for DGtal by
1.18.0