Computation of the Delaunay complex of a set of rational points in 3D by Quick Hull algorithm.
#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"
int main(
int argc,
char* argv[] )
{
int nb = argc > 1 ? atoi( argv[ 1 ] ) : 100;
double dR = argc > 2 ? atof( argv[ 2 ] ) : 10.;
double eps = argc > 3 ? atof( argv[ 3 ] ) : 0.1;
double precision = argc > 4 ? atof( argv[ 4 ] ) : 100.0;
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++; }
}
bool ok =
precision, true );
if ( ! ok )
{
trace.
error() <<
"Input set of points is not full dimensional." << std::endl;
return 1;
}
std::cout << dcomplex << std::endl;
std::vector< RealPoint > positions;
std::vector< std::vector< Index > > facets;
for (
auto c = 0; c < dcomplex.
nbCells(); ++c )
{
std::map< Index, Index > v2v;
for ( auto v : c_vtcs ) {
v2v[ v ] = idxv++;
positions.push_back( b + ( x - b ) * ( 1.0 - eps ) );
}
for (
const auto& f : dcomplex.
cellFaces( c ) ) {
for ( auto& vertex : f_vtcs )
vertex = v2v[ vertex ];
facets.push_back( f_vtcs );
}
}
SMesh mesh( positions.cbegin(), positions.cend(),
facets.cbegin(), facets.cend() );
std::ofstream out( "delaunay3d.obj" );
out.close();
return 0;
}
SurfaceMesh< RealPoint, RealVector > SMesh
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: represents a d-dimensional complex in a d-dimensional space with the following properties and re...
const VertexRange & cellVertices(const Cell c) const
Point position(const Vertex v) const
VertexRange faceVertices(const Face f) const
RealPoint cellBarycenter(const Cell c) const
void requireFaceGeometry()
Forces the computation of face geometry.
const FaceRange & cellFaces(const Cell c) const
Aim: Provides a set of functions to facilitate the computation of convex hulls and polytopes,...
Aim: An helper class for writing mesh file formats (Waverfront OBJ at this point) and creating a Surf...
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
PointVector< 3, double > RealPoint