DGtal  1.3.beta
geometry/tools/exampleRationalBallDelaunay3D.cpp

Computation of the Delaunay complex of a set of rational points in 3D by Quick Hull algorithm.

./examples/geometry/tools/exampleRationalBallDelaunay3D 100 10 0.25 100

outputs

Compute convex hull in higher dimension
assign ridges/faces to cell and conversely
takes care of vertex positions
[ConvexCellComplex<3> #C=456 #F=955 #V=99 hasFaceGeometry ]
Delaunay cell decomposition of 100 randomly chosen points in a 3D ball with radius 10, with precision 100 and retraction 0.25
See also
QuickHull algorithm in arbitrary dimension for convex hull and Delaunay cell complex computation
#include "DGtal/base/Common.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/shapes/SurfaceMesh.h"
#include "DGtal/io/writers/SurfaceMeshWriter.h"
#include "DGtal/geometry/volumes/ConvexityHelper.h"
using namespace DGtal;
using namespace DGtal::Z3i;
int main( int argc, char* argv[] )
{
int nb = argc > 1 ? atoi( argv[ 1 ] ) : 100; // nb points
double dR = argc > 2 ? atof( argv[ 2 ] ) : 10.; // radius of balla
double eps = argc > 3 ? atof( argv[ 3 ] ) : 0.1; // retraction
double precision = argc > 4 ? atof( argv[ 4 ] ) : 100.0; // precision
// (1) create range of random points in ball
std::vector< RealPoint > V;
const auto R2 = dR * dR;
for ( int i = 0; i < nb; ) {
RealPoint p( ( rand() / (double) RAND_MAX * 2.0 - 1.0 ) * dR,
( rand() / (double) RAND_MAX * 2.0 - 1.0 ) * dR,
( rand() / (double) RAND_MAX * 2.0 - 1.0 ) * dR );
if ( p.squaredNorm() <= R2 ) { V.push_back( p ); i++; }
}
// (2) compute convex hull
bool ok =
precision, true );
if ( ! ok )
{
trace.error() << "Input set of points is not full dimensional." << std::endl;
return 1;
}
dcomplex.requireFaceGeometry();
std::cout << dcomplex << std::endl;
// (3) build the mesh that is made of the exploded 3d cells
std::vector< RealPoint > positions;
std::vector< std::vector< Index > > facets;
Index idxv = 0;
for ( auto c = 0; c < dcomplex.nbCells(); ++c )
{
RealPoint b = dcomplex.cellBarycenter( c );
auto c_vtcs = dcomplex.cellVertices( c );
std::map< Index, Index > v2v;
for ( auto v : c_vtcs ) {
RealPoint x = dcomplex.position( v );
v2v[ v ] = idxv++;
positions.push_back( b + ( x - b ) * ( 1.0 - eps ) );
}
for ( const auto& f : dcomplex.cellFaces( c ) ) {
auto f_vtcs = dcomplex.faceVertices( f );
for ( auto& vertex : f_vtcs )
vertex = v2v[ vertex ];
facets.push_back( f_vtcs );
}
}
SMesh mesh( positions.cbegin(), positions.cend(),
facets.cbegin(), facets.cend() );
// (4) output result as OBJ file
std::ofstream out( "delaunay3d.obj" );
::writeOBJ( out, mesh );
out.close();
return 0;
}
DGtal::ConvexCellComplex::Index
std::size_t Index
Definition: ConvexCellComplex.h:89
DGtal::ConvexCellComplex::position
Point position(const Vertex v) const
Definition: ConvexCellComplex.h:256
DGtal::ConvexCellComplex::cellVertices
const VertexRange & cellVertices(const Cell c) const
Definition: ConvexCellComplex.h:169
DGtal::Trace::error
std::ostream & error()
Index
SMesh::Index Index
Definition: fullConvexitySphereGeodesics.cpp:117
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::SurfaceMesh
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition: SurfaceMesh.h:91
DGtal::ConvexCellComplex::requireFaceGeometry
void requireFaceGeometry()
Forces the computation of face geometry.
Definition: ConvexCellComplex.h:354
DGtal::ConvexCellComplex
Aim: represents a d-dimensional complex in a d-dimensional space with the following properties and re...
Definition: ConvexCellComplex.h:85
DGtal::ConvexityHelper::computeDelaunayCellComplex
static bool computeDelaunayCellComplex(ConvexCellComplex< Point > &cell_complex, const std::vector< Point > &input_points, bool remove_duplicates=true)
DGtal::ConvexCellComplex::cellFaces
const FaceRange & cellFaces(const Cell c) const
Definition: ConvexCellComplex.h:161
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::ConvexCellComplex::faceVertices
VertexRange faceVertices(const Face f) const
Definition: ConvexCellComplex.h:193
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
DGtal::ConvexCellComplex::cellBarycenter
RealPoint cellBarycenter(const Cell c) const
Definition: ConvexCellComplex.h:286
DGtal::ConvexCellComplex::nbCells
Size nbCells() const
Definition: ConvexCellComplex.h:129
DGtal::SurfaceMeshWriter::writeOBJ
static bool writeOBJ(std::ostream &output, const SurfaceMesh &smesh)
SMesh
SurfaceMesh< RealPoint, RealVector > SMesh
Definition: fullConvexitySphereGeodesics.cpp:115