40#ifndef GEOGRAM_MESH_MESH_SAMPLING
41#define GEOGRAM_MESH_MESH_SAMPLING
68 template <index_t DIM>
83 mesh.vertices.
point<DIM>(v1),
84 mesh.vertices.
point<DIM>(v2),
85 mesh.vertices.
point<DIM>(v3),
92 mesh.vertices.
point<DIM>(v1),
93 mesh.vertices.
point<DIM>(v2),
94 mesh.vertices.
point<DIM>(v3)
119 template <index_t DIM>
125 index_t facets_begin_in = NO_INDEX,
126 index_t facets_end_in = NO_INDEX
134 if(facets_begin_in != NO_INDEX) {
135 facets_begin = facets_begin_in;
137 if(facets_end_in != NO_INDEX) {
138 facets_end = facets_end_in;
148 for(
index_t i = 0; i < nb_points; i++) {
151 std::sort(s.begin(), s.end());
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;
172 if(first_t == NO_INDEX) {
175 last_t = std::max(last_t, cur_t);
184 mesh.vertices.
point<DIM>(v1),
185 mesh.vertices.
point<DIM>(v2),
186 mesh.vertices.
point<DIM>(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>
219 mesh.cells.
point<DIM>(t,0),
220 mesh.cells.
point<DIM>(t,1),
221 mesh.cells.
point<DIM>(t,2),
222 mesh.cells.
point<DIM>(t,3)
238 template <index_t DIM>
244 double result = mesh_tetra_mass<DIM>(mesh, t);
252 weight[v0] + weight[v1] + weight[v2] + weight[v3]
279 template <index_t DIM>
285 index_t tets_begin_in = NO_INDEX,
293 if(tets_begin_in != NO_INDEX) {
294 tets_begin = tets_begin_in;
296 if(tets_end_in != NO_INDEX) {
297 tets_end = tets_end_in;
307 for(
index_t i = 0; i < nb_points; i++) {
310 std::sort(s.begin(), s.end());
313 for(
index_t t = tets_begin; t < tets_end; ++t) {
314 double Vt = mesh_tetra_mass<DIM>(mesh, t, vertex_weight);
323 mesh_tetra_mass<DIM>(mesh, tets_begin, vertex_weight) / Vtot;
324 for(
index_t i = 0; i < nb_points; i++) {
326 while(s[i] > cur_s && cur_t < tets_end - 1) {
329 cur_s += mesh_tetra_mass<DIM>(
330 mesh, cur_t, vertex_weight
333 if(first_t == NO_INDEX) {
336 last_t = std::max(last_t, cur_t);
347 mesh.vertices.
point<DIM>(v0),
348 mesh.vertices.
point<DIM>(v1),
349 mesh.vertices.
point<DIM>(v2),
350 mesh.vertices.
point<DIM>(v3)
353 p[i * DIM + coord] = cur_p[coord];
356 if(mesh.cells.
nb() > 1 && last_t == first_t) {
357 Logger::warn(
"Sampler")
358 <<
"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.
Manages an attribute attached to a set of object.
const vecng< DIM, double > & point(index_t c, index_t lv) const
Gets a point by cell and local vertex index.
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.
vecng< DIM, double > & point(index_t v)
Gets a point.
index_t dimension() const
Gets the dimension of the vertices.
Vector with aligned memory allocation.
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.
Generic logging mechanism.
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.
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, index_t facets_begin_in=NO_INDEX, index_t facets_end_in=NO_INDEX)
Generates a set of random samples over a surfacic mesh.
geo_index_t index_t
The type for storing and manipulating indices.
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.
bool mesh_generate_random_samples_in_volume(const Mesh &mesh, double *p, index_t nb_points, Attribute< double > &vertex_weight, index_t tets_begin_in=NO_INDEX, index_t tets_end_in=NO_INDEX)
Generates a set of random samples in a volumetric mesh.