DGtal 1.3.0
Loading...
Searching...
No Matches
exampleRationalBallDelaunay3D.cpp
1
52#include "DGtal/base/Common.h"
53#include "DGtal/kernel/PointVector.h"
54#include "DGtal/shapes/SurfaceMesh.h"
55#include "DGtal/io/writers/SurfaceMeshWriter.h"
56#include "DGtal/geometry/volumes/ConvexityHelper.h"
57
58using namespace DGtal;
59using namespace DGtal::Z3i;
60int main( int argc, char* argv[] )
61{
62 int nb = argc > 1 ? atoi( argv[ 1 ] ) : 100; // nb points
63 double dR = argc > 2 ? atof( argv[ 2 ] ) : 10.; // radius of balla
64 double eps = argc > 3 ? atof( argv[ 3 ] ) : 0.1; // retraction
65 double precision = argc > 4 ? atof( argv[ 4 ] ) : 100.0; // precision
68 // (1) create range of random points in ball
69 std::vector< RealPoint > V;
70 const auto R2 = dR * dR;
71 for ( int i = 0; i < nb; ) {
72 RealPoint p( ( rand() / (double) RAND_MAX * 2.0 - 1.0 ) * dR,
73 ( rand() / (double) RAND_MAX * 2.0 - 1.0 ) * dR,
74 ( rand() / (double) RAND_MAX * 2.0 - 1.0 ) * dR );
75 if ( p.squaredNorm() <= R2 ) { V.push_back( p ); i++; }
76 }
77 // (2) compute convex hull
78 bool ok =
80 precision, true );
81 if ( ! ok )
82 {
83 trace.error() << "Input set of points is not full dimensional." << std::endl;
84 return 1;
85 }
86 dcomplex.requireFaceGeometry();
87 std::cout << dcomplex << std::endl;
88 // (3) build the mesh that is made of the exploded 3d cells
89 std::vector< RealPoint > positions;
90 std::vector< std::vector< Index > > facets;
91 Index idxv = 0;
92 for ( auto c = 0; c < dcomplex.nbCells(); ++c )
93 {
94 RealPoint b = dcomplex.cellBarycenter( c );
95 auto c_vtcs = dcomplex.cellVertices( c );
96 std::map< Index, Index > v2v;
97 for ( auto v : c_vtcs ) {
98 RealPoint x = dcomplex.position( v );
99 v2v[ v ] = idxv++;
100 positions.push_back( b + ( x - b ) * ( 1.0 - eps ) );
101 }
102 for ( const auto& f : dcomplex.cellFaces( c ) ) {
103 auto f_vtcs = dcomplex.faceVertices( f );
104 for ( auto& vertex : f_vtcs )
105 vertex = v2v[ vertex ];
106 facets.push_back( f_vtcs );
107 }
108 }
110 SMesh mesh( positions.cbegin(), positions.cend(),
111 facets.cbegin(), facets.cend() );
112 // (4) output result as OBJ file
113 std::ofstream out( "delaunay3d.obj" );
115 ::writeOBJ( out, mesh );
116 out.close();
117 return 0;
118}
119
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
std::ostream & error()
SurfaceMesh< RealPoint, RealVector > SMesh
SMesh::Index Index
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
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
static bool computeDelaunayCellComplex(ConvexCellComplex< Point > &cell_complex, const PointRange &input_points, bool remove_duplicates=true)
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 ...
Definition: SurfaceMesh.h:92
int main()
Definition: testBits.cpp:56