DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleLatticeBallDelaunay3D.cpp
Go to the documentation of this file.
1
16
29
51
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
58
using namespace
DGtal
;
59
using namespace
DGtal::Z3i
;
60
int
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
typedef
ConvexCellComplex< Point >::Index
Index
;
66
ConvexCellComplex< Point >
dcomplex;
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 =
77
ConvexityHelper< 3 >::computeDelaunayCellComplex
( dcomplex, V,
true
);
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
(
size_t
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
}
106
typedef
DGtal::SurfaceMesh< Z3::RealPoint, Z3::RealVector>
SMesh
;
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"
);
111
DGtal::SurfaceMeshWriter< Z3::RealPoint, Z3::RealVector >
112
::writeOBJ
( out, mesh );
113
out.close();
114
return
0;
115
}
DGtal::Point
DGtal::Trace::error
std::ostream & error()
SMesh
SurfaceMesh< RealPoint, RealVector > SMesh
Definition
fullConvexitySphereGeodesics.cpp:115
Index
SMesh::Index Index
Definition
fullConvexitySphereGeodesics.cpp:117
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal::Z3i::RealPoint
Space::RealPoint RealPoint
Definition
StdDefs.h:170
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
DGtal::ConvexCellComplex
Aim: represents a d-dimensional complex in a d-dimensional space with the following properties and re...
Definition
ConvexCellComplex.h:85
DGtal::ConvexCellComplex::Index
std::size_t Index
Definition
ConvexCellComplex.h:89
DGtal::ConvexCellComplex::cellVertices
const VertexRange & cellVertices(const Cell c) const
Definition
ConvexCellComplex.h:169
DGtal::ConvexCellComplex::nbCells
Size nbCells() const
Definition
ConvexCellComplex.h:129
DGtal::ConvexCellComplex::position
Point position(const Vertex v) const
Definition
ConvexCellComplex.h:256
DGtal::ConvexCellComplex::faceVertices
VertexRange faceVertices(const Face f) const
Definition
ConvexCellComplex.h:193
DGtal::ConvexCellComplex::toReal
RealPoint toReal(const Point p) const
Definition
ConvexCellComplex.h:263
DGtal::ConvexCellComplex::cellBarycenter
RealPoint cellBarycenter(const Cell c) const
Definition
ConvexCellComplex.h:286
DGtal::ConvexCellComplex::requireFaceGeometry
void requireFaceGeometry()
Forces the computation of face geometry.
Definition
ConvexCellComplex.h:354
DGtal::ConvexCellComplex::cellFaces
const FaceRange & cellFaces(const Cell c) const
Definition
ConvexCellComplex.h:161
DGtal::ConvexityHelper::computeDelaunayCellComplex
static bool computeDelaunayCellComplex(ConvexCellComplex< Point > &cell_complex, const PointRange &input_points, bool remove_duplicates=true)
DGtal::SurfaceMeshWriter
Aim: An helper class for writing mesh file formats (Waverfront OBJ at this point) and creating a Surf...
Definition
SurfaceMeshWriter.h:65
DGtal::SurfaceMesh
Aim: Represents an embedded mesh as faces and a list of vertices. Vertices may be shared among faces ...
Definition
SurfaceMesh.h:92
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
examples
geometry
tools
exampleLatticeBallDelaunay3D.cpp
Generated on
for DGtal by
1.18.0