Geogram Version 1.9.6-rc
A programming library of geometric algorithms
Loading...
Searching...
No Matches
mesh_geometry.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_MESH_MESH_GEOMETRY
41#define GEOGRAM_MESH_MESH_GEOMETRY
42
44#include <geogram/mesh/mesh.h>
47
53namespace GEO {
54
55 namespace Geom {
56
65 [[deprecated("use M.vertices.point(v) instead")]]
66 inline const vec3& mesh_vertex(const Mesh& M, index_t v) {
67 return M.vertices.point(v);
68 }
69
78 [[deprecated("use M.vertices.point(v) instead")]]
79 inline const vec3& mesh_vertex_ref(const Mesh& M, index_t v) {
80 return M.vertices.point(v);
81 }
82
91 [[deprecated("use M.vertices.point(v) instead")]]
93 return M.vertices.point(v);
94 }
95
104 [[deprecated("use M.facet_corners.point(c) instead")]]
105 inline const vec3& mesh_corner_vertex(const Mesh& M, index_t c) {
106 return M.facet_corners.point(c);
107 }
108
117 [[deprecated("use M.facet_corners.point(c) instead")]]
119 return M.facet_corners.point(c);
120 }
121
129 inline const vec3& mesh_vertex_normal(const Mesh& M, index_t v) {
130 geo_debug_assert(M.vertices.dimension() >= 6);
131 return *(const vec3*) (M.vertices.point_ptr(v) + 3);
132 }
133
142 geo_debug_assert(M.vertices.dimension() >= 6);
143 return *(vec3*) (M.vertices.point_ptr(v) + 3);
144 }
145
153 inline const vec3& mesh_vertex_normal_ref(const Mesh& M, index_t v) {
154 geo_debug_assert(M.vertices.dimension() >= 6);
155 return *(vec3 const *) (M.vertices.point_ptr(v) + 3);
156 }
157
166 inline double mesh_facet_area(const Mesh& M, index_t f, index_t dim=0) {
167 geo_debug_assert(dim <= M.vertices.dimension());
168 if(dim == 0) {
169 dim = M.vertices.dimension();
170 }
171 double result = 0.0;
172 // Check for empty facet, should not happen.
173 if(M.facets.corners_end(f) == M.facets.corners_begin(f)) {
174 return result;
175 }
176 const double* p0 = M.vertices.point_ptr(
177 M.facet_corners.vertex(M.facets.corners_begin(f))
178 );
179 for(
180 index_t i = M.facets.corners_begin(f) + 1;
181 i + 1 < M.facets.corners_end(f); i++
182 ) {
183 result += GEO::Geom::triangle_area(
184 p0,
185 M.vertices.point_ptr(M.facet_corners.vertex(i)),
186 M.vertices.point_ptr(M.facet_corners.vertex(i + 1)),
187 coord_index_t(dim)
188 );
189 }
190 return result;
191 }
192
201 vec3 GEOGRAM_API mesh_facet_normal(const Mesh& M, index_t f);
202
209 inline vec3 mesh_facet_center(const Mesh& M, index_t f) {
210 vec3 result(0.0, 0.0, 0.0);
211 double count = 0.0;
212 for(index_t c = M.facets.corners_begin(f);
213 c < M.facets.corners_end(f); ++c) {
214 result += M.facet_corners.point(c);
215 count += 1.0;
216 }
217 return (1.0 / count) * result;
218 }
219
226 inline vec3 mesh_cell_center(const Mesh& M, index_t c) {
227 vec3 result(0.0, 0.0, 0.0);
228 for(index_t lv=0; lv<M.cells.nb_vertices(c); ++lv) {
229 index_t v = M.cells.vertex(c,lv);
230 result += M.vertices.point(v);
231 }
232 return (1.0 / double(M.cells.nb_vertices(c))) * result;
233 }
234
235
242 inline vec3 mesh_tet_center(const Mesh& M, index_t t) {
243 const vec3& v1 = M.cells.point(t,0);
244 const vec3& v2 = M.cells.point(t,1);
245 const vec3& v3 = M.cells.point(t,2);
246 const vec3& v4 = M.cells.point(t,3);
247 return 0.25 * (v1 + v2 + v3 + v4);
248 }
249
259 inline vec3 mesh_corner_vector(const Mesh& M, index_t c1) {
261 index_t c2 = M.facets.next_corner_around_facet(c1/3, c1);
262 return M.facet_corners.point(c2) - M.facet_corners.point(c1);
263 }
264
274 double GEOGRAM_API mesh_normal_angle(const Mesh& M, index_t c);
275
283 double GEOGRAM_API mesh_unsigned_normal_angle(
284 const Mesh& M, index_t f1, index_t f2
285 );
286
295 double GEOGRAM_API mesh_area(const Mesh& M, index_t dim);
296
302 inline double mesh_area(const Mesh& M) {
303 return mesh_area(M, M.vertices.dimension());
304 }
305
311 double GEOGRAM_API mesh_enclosed_volume(const Mesh& M);
312 }
313
319 void GEOGRAM_API compute_normals(Mesh& M);
320
330 void GEOGRAM_API simple_Laplacian_smooth(
331 Mesh& M, index_t nb_iter, bool normals_only
332 );
333
340 void GEOGRAM_API get_bbox(const Mesh& M, double* xyzmin, double* xyzmax);
341
347 double GEOGRAM_API bbox_diagonal(const Mesh& M);
348
356 void GEOGRAM_API set_anisotropy(Mesh& M, double s);
357
362 void GEOGRAM_API unset_anisotropy(Mesh& M);
363
374 void GEOGRAM_API compute_sizing_field(
375 Mesh& M, double gradation = 1.0, index_t nb_lfs_samples = 0
376 );
377
386 void GEOGRAM_API normalize_embedding_area(Mesh& M);
387
395 double GEOGRAM_API mesh_cell_volume(
396 const Mesh& M, index_t c
397 );
398
404 double GEOGRAM_API mesh_cells_volume(const Mesh& M);
405
406
417 const Mesh& M, index_t c, index_t lf
418 );
419
425 double GEOGRAM_API surface_average_edge_length(
426 const Mesh& M
427 );
428}
429
430#endif
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:196
index_t nb_vertices(index_t c) const
Gets the number of vertices of a cell.
Definition mesh.h:2231
const vecng< DIM, double > & point(index_t c, index_t lv) const
Gets a point by cell and local vertex index.
Definition mesh.h:2263
index_t vertex(index_t c, index_t lv) const
Gets a vertex of a cell by local vertex index.
Definition mesh.h:2241
vecng< DIM, double > & point(index_t c)
Gets the point associated with a corner.
Definition mesh.h:1050
index_t vertex(index_t c) const
Gets the vertex that a corner is incident to.
Definition mesh.h:940
index_t corners_end(index_t f) const
Gets the upper limit for iterating over the corners of a facet.
Definition mesh.h:838
bool are_simplices() const
Tests whether all the facets are triangles.
Definition mesh.h:873
index_t corners_begin(index_t f) const
Gets the first element for iterating over the corners of a facet.
Definition mesh.h:827
index_t next_corner_around_facet(index_t f, index_t c) const
Gets the successor of a corner around a facet.
Definition mesh.h:1264
const double * point_ptr(index_t v) const
Gets a point.
Definition mesh.h:477
vecng< DIM, double > & point(index_t v)
Gets a point.
Definition mesh.h:504
index_t dimension() const
Gets the dimension of the vertices.
Definition mesh.h:449
Represents a mesh.
Definition mesh.h:3050
Common include file, providing basic definitions. Should be included before anything else by all head...
Geometric functions in 2d and 3d.
Geometric functions in arbitrary dimension.
The class that represents a mesh.
vec3 mesh_corner_vector(const Mesh &M, index_t c1)
Gets a vector by a mesh corner.
double mesh_unsigned_normal_angle(const Mesh &M, index_t f1, index_t f2)
Computes the angle between the normal vectors of two mesh facets sharing an edge.
double mesh_normal_angle(const Mesh &M, index_t c)
Computes the angle between the normal vectors of two mesh facets sharing an edge.
const vec3 & mesh_vertex_ref(const Mesh &M, index_t v)
Gets a mesh vertex by its index.
const vec3 & mesh_corner_vertex(const Mesh &M, index_t c)
Gets a mesh vertex by an incident corner index.
double mesh_area(const Mesh &M, index_t dim)
Computes the total surface area of a mesh in arbitrary dimension.
vec3 mesh_cell_center(const Mesh &M, index_t c)
Gets the centroid of the vertices of a cell in a mesh.
double triangle_area(const vec3 &p1, const vec3 &p2, const vec3 &p3)
Computes the area of a 3d triangle.
Definition geometry.h:368
vec3 & mesh_corner_vertex_ref(Mesh &M, index_t c)
Gets a mesh vertex by an incident corner index.
vec3 mesh_facet_center(const Mesh &M, index_t f)
Gets the centroid of the vertices of a facet in a mesh.
const vec3 & mesh_vertex(const Mesh &M, index_t v)
Gets a mesh vertex by its index.
vec3 mesh_tet_center(const Mesh &M, index_t t)
Gets the centroid of a tetrahedron in a mesh.
const vec3 & mesh_vertex_normal(const Mesh &M, index_t v)
Gets a mesh vertex normal by vertex index.
double mesh_enclosed_volume(const Mesh &M)
Computes the volume enclosed by a surfacic mesh.
double mesh_facet_area(const Mesh &M, index_t f, index_t dim=0)
Computes the area of a facet.
vec3 & mesh_vertex_normal_ref(Mesh &M, index_t v)
Gets a mesh vertex normal by vertex index.
vec3 mesh_facet_normal(const Mesh &M, index_t f)
Computes the normal to a mesh facet.
Global Vorpaline namespace.
Definition basic.h:55
void simple_Laplacian_smooth(Mesh &M, index_t nb_iter, bool normals_only)
Smoothes a mesh.
double surface_average_edge_length(const Mesh &M)
Computes the average edge length in a surface.
void get_bbox(const Mesh &M, double *xyzmin, double *xyzmax)
Gets the bounding box of a mesh.
void compute_sizing_field(Mesh &M, double gradation=1.0, index_t nb_lfs_samples=0)
Computes a sizing field using an estimate of lfs (local feature size).
double bbox_diagonal(const Mesh &M)
Computes the length of the bounding box diagonal of a mesh.
void compute_normals(Mesh &M)
Computes the normals to the vertices, and stores them as additional coordinates.
double mesh_cells_volume(const Mesh &M)
Computes the volume of the cells of a mesh.
double mesh_cell_volume(const Mesh &M, index_t c)
Computes the volume of a cell in a mesh.
void normalize_embedding_area(Mesh &M)
Computes vertices weights in such a way that triangle areas are normalized.
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329
void set_anisotropy(Mesh &M, double s)
Normalizes and scales the stored vertex normals by a factor.
void unset_anisotropy(Mesh &M)
Normalizes the stored vertex normals.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:363
vec3 mesh_cell_facet_normal(const Mesh &M, index_t c, index_t lf)
Computes the normal of a cell facet.