DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleLatticeBallDelaunay3D.cpp File Reference
#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"

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/02/06

An example file named exampleLatticeBallDelaunay3D.

This file is part of the DGtal library.

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/02/06

An example file named exampleRationalBallDelaunay3D.

This file is part of the DGtal library.

Definition in file exampleLatticeBallDelaunay3D.cpp.

Function Documentation

◆ main()

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

Definition at line 60 of file exampleLatticeBallDelaunay3D.cpp.

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
67 // (1) create range of random points in ball
68 std::vector< Point > V;
69 const auto R2 = dR * dR;
70 const int R = ceil( dR );
71 for ( int i = 0; i < nb; ) {
72 Point p( rand() % (2*R+1) - R, rand() % (2*R+1) - R, rand() % (2*R+1) - R );
73 if ( p.squaredNorm() <= R2 ) { V.push_back( p ); i++; }
74 }
75 // (2) compute convex hull
76 bool ok =
78 if ( ! ok )
79 {
80 trace.error() << "Input set of points is not full dimensional." << std::endl;
81 return 1;
82 }
83 dcomplex.requireFaceGeometry();
84 std::cout << dcomplex << std::endl;
85 // (3) build the mesh that is made of the exploded 3d cells
86 std::vector< RealPoint > positions;
87 std::vector< std::vector< Index > > facets;
88 Index idxv = 0;
89 for ( auto c = 0; c < dcomplex.nbCells(); ++c )
90 {
91 RealPoint b = dcomplex.cellBarycenter( c );
92 auto c_vtcs = dcomplex.cellVertices( c );
93 std::map< Index, Index > v2v;
94 for ( auto v : c_vtcs ) {
95 RealPoint x = dcomplex.toReal( dcomplex.position( v ) );
96 v2v[ v ] = idxv++;
97 positions.push_back( b + ( x - b ) * ( 1.0 - eps ) );
98 }
99 for ( const auto& f : dcomplex.cellFaces( c ) ) {
100 auto f_vtcs = dcomplex.faceVertices( f );
101 for ( auto& vertex : f_vtcs )
102 vertex = v2v[ vertex ];
103 facets.push_back( f_vtcs );
104 }
105 }
107 SMesh mesh( positions.cbegin(), positions.cend(),
108 facets.cbegin(), facets.cend() );
109 // (4) output result as OBJ file
110 std::ofstream out( "delaunay3d.obj" );
112 ::writeOBJ( out, mesh );
113 out.close();
114 return 0;
115}
std::ostream & error()
SurfaceMesh< RealPoint, RealVector > SMesh
SMesh::Index Index
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 toReal(const Point p) 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

References DGtal::ConvexCellComplex< TPoint >::cellBarycenter(), DGtal::ConvexCellComplex< TPoint >::cellFaces(), DGtal::ConvexCellComplex< TPoint >::cellVertices(), DGtal::ConvexityHelper< dim, TInteger, TInternalInteger >::computeDelaunayCellComplex(), DGtal::Trace::error(), DGtal::ConvexCellComplex< TPoint >::faceVertices(), DGtal::ConvexCellComplex< TPoint >::nbCells(), DGtal::ConvexCellComplex< TPoint >::position(), DGtal::ConvexCellComplex< TPoint >::requireFaceGeometry(), DGtal::ConvexCellComplex< TPoint >::toReal(), and DGtal::trace.