DGtal 1.4.0
Loading...
Searching...
No Matches
exampleLatticeBallQuickHull3D.cpp File Reference
#include "DGtal/base/Common.h"
#include "DGtal/geometry/tools/QuickHull.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
Include dependency graph for exampleLatticeBallQuickHull3D.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2021/01/01

An example file named exampleLatticeBallQuickHull3D.

This file is part of the DGtal library.

Definition in file exampleLatticeBallQuickHull3D.cpp.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

[QuickHull3D-Typedefs]

[QuickHull3D-Typedefs]

[QuickHull3D-Computation]

[QuickHull3D-Computation] [QuickHull3D-Timings]

[QuickHull3D-Timings]

[QuickHull3D-BuildMesh]

[QuickHull3D-BuildMesh]

[QuickHull3D-OutputMesh]

[QuickHull3D-OutputMesh]

Definition at line 61 of file exampleLatticeBallQuickHull3D.cpp.

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
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 QuickHull3D 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 );
104 SMesh mesh( positions.cbegin(), positions.cend(), facets.cbegin(), facets.cend() );
106 // (4) output result as OBJ file
108 std::ofstream out( "qhull.obj" );
110 out.close();
112 return 0;
113}
SurfaceMesh< RealPoint, RealVector > SMesh
Aim: a geometric kernel to compute the convex hull of digital points with integer-only arithmetic.
Aim: Implements the quickhull algorithm by Barber et al. barber1996, a famous arbitrary dimensional c...
Definition QuickHull.h:140
bool setInput(const std::vector< InputPoint > &input_points, bool remove_duplicates=true)
Definition QuickHull.h:382
bool getFacetVertices(std::vector< IndexRange > &facet_vertices) const
Definition QuickHull.h:666
Size nbVertices() const
Definition QuickHull.h:337
bool getVertexPositions(std::vector< OutputPoint > &vertex_positions)
Definition QuickHull.h:612
Size nbFacets() const
Definition QuickHull.h:328
bool computeConvexHull(Status target=Status::VerticesCompleted)
Definition QuickHull.h:460
std::vector< double > timings
Timings of the different phases: 0: init, 1: facets, 2: vertices.
Definition QuickHull.h:826
Size nbPoints() const
Definition QuickHull.h:323
static bool writeOBJ(std::ostream &output, const SurfaceMesh &smesh)
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition SurfaceMesh.h:92

References DGtal::QuickHull< TKernel >::computeConvexHull(), DGtal::QuickHull< TKernel >::getFacetVertices(), DGtal::QuickHull< TKernel >::getVertexPositions(), DGtal::QuickHull< TKernel >::nbFacets(), DGtal::QuickHull< TKernel >::nbPoints(), DGtal::QuickHull< TKernel >::nbVertices(), DGtal::QuickHull< TKernel >::setInput(), DGtal::QuickHull< TKernel >::timings, and DGtal::SurfaceMeshWriter< TRealPoint, TRealVector >::writeOBJ().