40 #ifndef GEOGRAM_MESH_MESH_SAMPLING
41 #define GEOGRAM_MESH_MESH_SAMPLING
47 #include <geogram/basic/logger.h>
68 template <index_t DIM>
83 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v1)),
84 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v2)),
85 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v3)),
92 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v1)),
93 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v2)),
94 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v3))
119 template <index_t DIM>
134 if(facets_begin_in != -1) {
135 facets_begin =
index_t(facets_begin_in);
137 if(facets_end_in != -1) {
138 facets_end =
index_t(facets_end_in);
148 for(
index_t i = 0; i < nb_points; i++) {
154 for(
index_t t = facets_begin; t < facets_end; ++t) {
155 double At = mesh_facet_mass<DIM>(mesh, t, weight);
164 mesh_facet_mass<DIM>(mesh, facets_begin, weight) / Atot;
165 for(
index_t i = 0; i < nb_points; i++) {
167 while(s[i] > cur_s && cur_t < facets_end - 1) {
170 cur_s += mesh_facet_mass<DIM>(mesh, cur_t, weight) / Atot;
184 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v1)),
185 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v2)),
186 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v3))
189 p[i * DIM + coord] = cur_p[coord];
192 if(mesh.facets.
nb() > 1 && last_t == first_t) {
193 Logger::warn(
"Sampler")
194 <<
"Did put all the points in the same triangle"
211 template <index_t DIM>
225 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v0)),
226 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v1)),
227 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v2)),
228 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v3))
244 template <index_t DIM>
250 double result = mesh_tetra_mass<DIM>(mesh, t);
258 weight[v0] + weight[v1] +
259 weight[v2] + weight[v3]
286 template <index_t DIM>
300 if(tets_begin_in != -1) {
301 tets_begin =
index_t(tets_begin_in);
303 if(tets_end_in != -1) {
304 tets_end =
index_t(tets_end_in);
314 for(
index_t i = 0; i < nb_points; i++) {
320 for(
index_t t = tets_begin; t < tets_end; ++t) {
321 double Vt = mesh_tetra_mass<DIM>(mesh, t, vertex_weight);
330 mesh_tetra_mass<DIM>(mesh, tets_begin, vertex_weight) / Vtot;
331 for(
index_t i = 0; i < nb_points; i++) {
333 while(s[i] > cur_s && cur_t < tets_end - 1) {
336 cur_s += mesh_tetra_mass<DIM>(
337 mesh, cur_t, vertex_weight
354 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v0)),
355 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v1)),
356 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v2)),
357 *
reinterpret_cast<const Point*
>(mesh.vertices.
point_ptr(v3))
360 p[i * DIM + coord] = cur_p[coord];
363 if(mesh.cells.
nb() > 1 && last_t == first_t) {
364 Logger::warn(
"Sampler")
365 <<
"Did put all the points in the same tetrahedron"
#define geo_assert(x)
Verifies that a condition is met.
#define geo_debug_assert(x)
Verifies that a condition is met.
bool is_bound() const
Tests whether an Attribute is bound.
index_t vertex(index_t c, index_t lv) const
Gets a vertex of a cell by local vertex index.
bool are_simplices() const
Tests whether all the facets are triangles.
index_t vertex(index_t f, index_t lv) const
Gets a vertex by facet and local vertex index.
index_t nb() const
Gets the number of (sub-)elements.
const double * point_ptr(index_t v) const
Gets a point.
index_t dimension() const
Gets the dimension of the vertices.
index_t size() const
Gets the number of elements.
Common include file, providing basic definitions. Should be included before anything else by all head...
Geometric functions in arbitrary dimension.
The class that represents a mesh.
Functions for accessing the geometry in a mesh.
vec3 random_point_in_triangle(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Generates a random point in a 3d triangle.
double tetra_volume(const vec3 &p1, const vec3 &p2, const vec3 &p3, const vec3 &p4)
Computes the volume of a 3d tetrahedron.
double triangle_mass(const vec3 &p, const vec3 &q, const vec3 &r, double a, double b, double c)
Computes the mass of a 3d triangle with weighted points.
double triangle_area(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Computes the area of a 3d triangle.
VEC random_point_in_tetra(const VEC &p1, const VEC &p2, const VEC &p3, const VEC &p4)
Generates a random point in a nd tetrahedron.
float64 random_float64()
Returns a 64 bits float between 0 and 1.
void random_reset()
Resets the random number generator.
Global Vorpaline namespace.
bool mesh_generate_random_samples_in_volume(const Mesh &mesh, double *p, index_t nb_points, Attribute< double > &vertex_weight, signed_index_t tets_begin_in=-1, signed_index_t tets_end_in=-1)
Generates a set of random samples in a volumetric mesh.
geo_signed_index_t signed_index_t
The type for storing and manipulating indices differences.
double mesh_tetra_mass(const Mesh &mesh, index_t t)
Computes the mass of a mesh tetrahedron.
bool mesh_generate_random_samples_on_surface(const Mesh &mesh, double *p, index_t nb_points, Attribute< double > &weight, signed_index_t facets_begin_in=-1, signed_index_t facets_end_in=-1)
Generates a set of random samples over a surfacic mesh.
geo_index_t index_t
The type for storing and manipulating indices.
void sort(const ITERATOR &begin, const ITERATOR &end)
Sorts elements in parallel.
double mesh_facet_mass(const Mesh &mesh, index_t f, Attribute< double > &vertex_weight)
Computes the mass of a mesh facet.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.