BRL-CAD
Loading...
Searching...
No Matches
trimesh.h
Go to the documentation of this file.
1/* T R I M E S H . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2026 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21/*----------------------------------------------------------------------*/
22/* @file trimesh.h */
23/** @addtogroup bg_trimesh */
24/** @{ */
25
26/**
27 * @brief
28 * Algorithms related to 3D meshes built from triangles.
29 */
30
31#ifndef BG_TRIMESH_H
32#define BG_TRIMESH_H
33
34#include "common.h"
35#include "vmath.h"
36#include "bg/defines.h"
37#include "bu/vls.h"
38
39__BEGIN_DECLS
40
42 int va, vb;
44};
45
46/* every pair of contiguous elements is the start and end vertex index of an edge */
48 int count;
49 int *edges;
50};
51
53 int count;
54 int *faces;
55};
56
63
64#define BG_TRIMESH_EDGES_INIT_NULL {0, NULL}
65#define BG_TRIMESH_FACES_INIT_NULL {0, NULL}
66#define BG_TRIMESH_SOLID_ERRORS_INIT_NULL {BG_TRIMESH_FACES_INIT_NULL, BG_TRIMESH_EDGES_INIT_NULL, BG_TRIMESH_EDGES_INIT_NULL, BG_TRIMESH_EDGES_INIT_NULL}
67
68BG_EXPORT extern void bg_free_trimesh_edges(struct bg_trimesh_edges *edges);
69BG_EXPORT extern void bg_free_trimesh_faces(struct bg_trimesh_faces *faces);
70BG_EXPORT extern void bg_free_trimesh_solid_errors(struct bg_trimesh_solid_errors *errors);
71
72/**
73 * Check if a mesh is topologically closed and manifold. True if for
74 * every edge, there is exactly one other edge with the same two end
75 * vertices.
76 */
77BG_EXPORT extern int bg_trimesh_manifold_closed(int vcnt, int fcnt, fastf_t *v, int *f);
78
79/**
80 * Check if a mesh is consistently oriented. True if for every edge
81 * that has exactly one matching edge, the two edges have opposite
82 * orientations. Note that an open mesh can be oriented, but a
83 * non-manifold mesh cannot.
84 */
85BG_EXPORT extern int bg_trimesh_oriented(int vcnt, int fcnt, fastf_t *v, int *f);
86
87/**
88 * Check if a mesh is topologically solid. Returns 1 if the mesh is NOT SOLID
89 * and 0 if the mesh is SOLID. A SOLID (0) outcome indicates the mesh satisfies
90 * all three criteria: Closed, Manifold, Oriented
91 */
92BG_EXPORT extern int bg_trimesh_solid(int vcnt, int fcnt, fastf_t *v, int *f, int **bedges);
93
94/* The below functions are for use as arguments to error tests. Given
95 * a face/edge, they return true if the caller should continue
96 * iterating through faces/edges, and false otherwise.
97 *
98 * The *_exit and *_continue functions just return false and true
99 * respectively. The *_gather functions expect the data argument to
100 * be a struct bg_trimesh_faces or struct bg_trimesh_edges with
101 * pre-allocated members of the correct size and count members set to
102 * 0, that they will populate.
103 */
104typedef int (*bg_face_error_func_t)(int face_idx, void *data);
105typedef int (*bg_edge_error_funct_t)(struct bg_trimesh_halfedge *edge, void *data);
106
107BG_EXPORT extern int bg_trimesh_face_exit(int face_idx, void *data);
108BG_EXPORT extern int bg_trimesh_face_continue(int face_idx, void *data);
109BG_EXPORT extern int bg_trimesh_face_gather(int face_idx, void *data);
110BG_EXPORT extern int bg_trimesh_edge_exit(struct bg_trimesh_halfedge *edge, void *data);
111BG_EXPORT extern int bg_trimesh_edge_continue(struct bg_trimesh_halfedge *edge, void *data);
112BG_EXPORT extern int bg_trimesh_edge_gather(struct bg_trimesh_halfedge *edge, void *data);
113
114/* These functions return 0 if no instances of the error are found.
115 * Otherwise, they return the number of instances of the error found
116 * before the error function argument returned false (at least 1).
117 */
118BG_EXPORT extern int bg_trimesh_degenerate_faces(int num_faces, int *fpoints, bg_face_error_func_t degenerate_func, void *data);
119BG_EXPORT extern int bg_trimesh_unmatched_edges(int num_edges, struct bg_trimesh_halfedge *edge_list, bg_edge_error_funct_t error_edge_func, void *data);
120BG_EXPORT extern int bg_trimesh_misoriented_edges(int num_edges, struct bg_trimesh_halfedge *edge_list, bg_edge_error_funct_t error_edge_func, void *data);
121BG_EXPORT extern int bg_trimesh_excess_edges(int num_edges, struct bg_trimesh_halfedge *edge_list, bg_edge_error_funct_t error_edge_func, void *data);
122BG_EXPORT extern int bg_trimesh_solid2(int vcnt, int fcnt, fastf_t *v, int *f, struct bg_trimesh_solid_errors *errors);
123BG_EXPORT extern int bg_trimesh_hanging_nodes(int num_vertices, int num_faces, fastf_t *vertices, int *faces, struct bg_trimesh_solid_errors *errors);
124
125BG_EXPORT extern struct bg_trimesh_halfedge * bg_trimesh_generate_edge_list(int fcnt, int *f);
126
127/**
128 * @brief
129 * Calculate an axis aligned bounding box (RPP) for a triangle mesh.
130 *
131 * NOTE: This routine bounds only those points that are active in the triangle
132 * mesh, not all points present in the supplied points array.
133 *
134 * @param[out] min XYZ coordinate defining the minimum bbox point
135 * @param[out] max XYZ coordinate defining the maximum bbox point
136 * @param[in] faces array of trimesh faces
137 * @param[in] num_faces size of faces array
138 * @param[in] p array that holds the points defining the trimesh
139 * @param[in] num_pnts size of pnts array
140 */
141BG_EXPORT extern int
142bg_trimesh_aabb(point_t *min, point_t *max, const int *faces, size_t num_faces, const point_t *p, size_t num_pnts);
143
144/**
145 * @brief
146 * Calculate the surface area of a triangle mesh.
147 *
148 * @param[in] faces array of trimesh faces
149 * @param[in] num_faces size of faces array
150 * @param[in] p array that holds the points defining the trimesh
151 * @param[in] num_pnts size of pnts array
152 *
153 * @return -1 if error, else area of mesh in millimeters
154 */
155BG_EXPORT extern fastf_t
156bg_trimesh_area(const int *faces, size_t num_faces, const point_t *p, size_t num_pnts);
157
158
159/**
160 * Calculate the volume enclosed by a closed, consistently-oriented triangle
161 * mesh using the divergence theorem (signed-tetrahedra method).
162 *
163 * The mesh must be closed and consistently oriented (all face normals pointing
164 * outward or all inward). Consistent orientation is guaranteed for meshes
165 * that pass bg_trimesh_solid2() with zero unmatched edges. The function
166 * returns the absolute value of the signed result, so it works correctly
167 * regardless of whether normals point inward or outward.
168 *
169 * @param[in] faces flat array of triangle indices (3 ints per face)
170 * @param[in] num_faces number of triangles
171 * @param[in] p array of vertex positions
172 * @param[in] num_pnts number of vertices
173 *
174 * @return -1 if inputs are invalid, else volume in cubic millimeters
175 */
176BG_EXPORT extern fastf_t
177bg_trimesh_volume(const int *faces, size_t num_faces, const point_t *p, size_t num_pnts);
178
179
180/* Structure holding user-adjustable decimation settings */
182 int method; // Select decimation method to use
183 fastf_t feature_size; // Smallest feature size (mm) to leave undecimated
184 fastf_t max_runtime; // If the decimation takes more than max_runtime seconds, abort
185 size_t max_threads; // Don't use more than max_threads when processing.
186 struct bu_vls msgs; // Messages reported during decimation
187};
188#define BG_TRIMESH_DECIMATION_METHOD_DEFAULT 0
189#define BG_TRIMESH_DECIMATION_SETTINGS_INIT {BG_TRIMESH_DECIMATION_METHOD_DEFAULT, 0.0, 0.0, 0, BU_VLS_INIT_ZERO}
190
191/**
192 * @brief
193 * Decimate a mesh and return the decimated faces.
194 *
195 * @param[out] ofaces faces array for the new output mesh
196 * @param[out] n_ofaces length of ofaces array
197 * @param[in] ifaces array of input trimesh
198 * @param[in] n_ifaces size of input faces array
199 * @param[in] p array that holds the points defining the trimesh
200 * @param[in] n_p size of points array
201 * @param[in] s decimation settings
202 *
203 * NOTE: This routine will not produce a points array that includes only the
204 * points used in the decimated mesh - to generate that output, use the
205 * bg_trimesh_3d_gc routine with the ofaces set produced by this function.
206 *
207 * @return -1 if error, 0 if successful */
208BG_EXPORT extern int bg_trimesh_decimate(int **ofaces, int *n_ofaces,
209 int *ifaces, int n_ifaces, point_t *p, int n_p, struct bg_trimesh_decimation_settings *s);
210
211
212/* Make an attempt at a trimesh intersection calculator that returns the sets
213 * of faces intersecting and inside the other for each mesh. Doesn't attempt
214 * a boolean evaluation, just characterizes faces */
215BG_EXPORT extern int
217 int **faces_inside_1, int *num_faces_inside_1, int **faces_inside_2, int *num_faces_inside_2,
218 int **faces_isect_1, int *num_faces_isect_1, int **faces_isect_2, int *num_faces_isect_2,
219 int *faces_1, int num_faces_1, point_t *vertices_1, int num_vertices_1,
220 int *faces_2, int num_faces_2, point_t *vertices_2, int num_vertices_2);
221
222/**
223 * @brief
224 * Compute vertex normals for a mesh based on the connected faces.
225 *
226 * @param[out] onorms array of normals - will have the same length as the input points array
227 * @param[in] ifaces array of input trimesh
228 * @param[in] n_ifaces size of input faces array
229 * @param[in] p array that holds the points defining the trimesh
230 * @param[in] n_p size of points array
231 *
232 * NOTE: Any vertex point not used by the triangles in the trimesh will have a
233 * zero normal in the onorms array. This routine does not repack the data to
234 * eliminate unused vertices - for that use bg_trimesh_optimize
235 *
236 * @return -1 if error, 0 if successful */
237BG_EXPORT extern int bg_trimesh_normals(vect_t **onorms, int *ifaces, int n_ifaces, point_t *p, int n_p);
238
239
240/* Various additional mesh optimization steps that can be enabled
241 * NOTE: If we want to look at exposing the capabilities of something like
242 * https://github.com/zeux/meshoptimizer this would be the place to start... */
244 int collapse_degenerate; // Remove degenerate faces
245 fastf_t degenerate_edge_length; // If near zero and collapse_degenerate is set, only collapse triangles with two or more uses of the exact same vertex
246 fastf_t max_runtime; // If the optimization takes more than max_runtime seconds, abort
247 size_t max_threads; // Don't use more than max_threads when processing.
248};
249
250#define BG_TRIMESH_OPTIMIZATION_SETTINGS_INIT {0, 0.0, 0.0, 0}
251
252/**
253 * @brief
254 * Return trimesh information for a 3D mesh that contains just the date needed
255 * to represent in the mesh. Used to finalize intermediate processing meshes
256 * to generate a compact mesh for export or storage.
257 *
258 * @param[out] ofaces faces array for the new output mesh with new indices based on opnts array.
259 * @param[out] n_ofaces length of ofaces array
260 * @param[out] opnts compact points array for the new output mesh.
261 * @param[out] onorms (optional) compact normals array for the output mesh's points.
262 * @param[out] n_opnts length of opnts array.
263 * @param[in] ifaces array of input trimesh
264 * @param[in] n_ifaces size of input faces array
265 * @param[in] ipnts array that holds the points defining the original trimesh
266 * @param[in] inorms (optional) array that holds the normals for the mesh vertices
267 * @param[in] s (optional) settings to enable various additional processing steps
268 *
269 * @return -1 if error, number of faces in new trimesh if successful
270 */
271BG_EXPORT extern int bg_trimesh_optimize(
272 int **ofaces, int *n_ofaces,
273 point_t **opnts, vect_t **onorms, int *n_opnts,
274 const int *ifaces, int n_ifaces,
275 const point_t *ipnts, const vect_t *inorms,
277
278
279/**
280 * @brief
281 * Return trimesh information for a planar (2D) mesh that contains just the set
282 * of points active in the mesh.
283 *
284 * @param[out] ofaces faces array for the new output mesh
285 * @param[out] n_ofaces length of ofaces array
286 * @param[out] opnts points array for the new output mesh
287 * @param[out] n_opnts length of opnts array
288 * @param[in] ifaces array of input trimesh
289 * @param[in] n_ifaces size of input faces array
290 * @param[in] ipnts array that holds the points defining the original trimesh
291 *
292 * @return -1 if error, number of faces in new trimesh if successful (should
293 * match the original face count)
294 */
295BG_EXPORT extern int bg_trimesh_2d_gc(int **ofaces, int *n_ofaces, point2d_t **opnts, int *n_opnts,
296 const int *ifaces, int n_ifaces, const point2d_t *ipnts);
297
298/**
299 * @brief
300 * Return trimesh information for a 3D mesh that contains just the set
301 * of points active in the mesh.
302 *
303 * @param[out] ofaces faces array for the new output mesh.
304 * @param[out] opnts points array for the new output mesh.
305 * @param[out] n_opnts length of opnts array.
306 * @param[in] faces array of input trimesh
307 * @param[in] num_faces size of input faces array
308 * @param[in] in_pts holds the points defining the original trimesh
309 *
310 * @return -1 if error, number of faces in new trimesh if successful (should
311 * match the original face count)
312 */
313BG_EXPORT extern int bg_trimesh_3d_gc(int **ofaces, point_t **opnts, int *n_opnts,
314 const int *faces, int num_faces, const point_t *in_pts);
315
316/**
317 * @brief
318 * Return a face set where all topologically connected faces are oriented
319 * consistently relative to their neighbors.
320 *
321 * @param[out] of faces array for the new output mesh (of==f is valid).
322 * @param[in] f input set of faces.
323 * @param[in] fcnt input face count
324 *
325 * @return -1 if error, otherwise return the number of times a face flipping
326 * operation was performed
327 */
328BG_EXPORT extern int
329bg_trimesh_sync(int *of, int *f, int fcnt);
330
331/**
332 * @brief
333 * Return a set of face sets where all topologically connected faces are
334 * grouped into common sets.
335 *
336 * @param[out] ofs array of faces arrays containing the new output face sets.
337 * @param[out] ofc array of face counts for the new output face sets.
338 * @param[in] f input set of faces.
339 * @param[in] fcnt input face count
340 *
341 * @return -1 if error, otherwise return the number of face sets created
342 */
343BG_EXPORT extern int
344bg_trimesh_split(int ***ofs, int **ofc, int *f, int fcnt);
345
346/**
347 * @brief
348 * Return a set of face sets where all topologically connected faces are
349 * grouped into common sets.
350 *
351 * @param[in] fname plot file name
352 * @param[in] faces face index array
353 * @param[in] num_faces number of faces
354 * @param[in] pnts points array
355 * @param[in] num_pnts number of points
356 *
357 * @return BRLCAD_ERROR if error, otherwise return BRLCAD_OK
358 */
359BG_EXPORT extern int
360bg_trimesh_2d_plot3(const char *fname, const int *faces, size_t num_faces, const point2d_t *pnts, size_t num_pnts);
361
362/**
363 * @brief
364 * Compare two trimeshes to determine if they (within tolerance) define the
365 * same mesh.
366 *
367 * This is a fairly focused function whose purpose is to spot meshes that have
368 * potentially gone through numerical or topological reordering but still
369 * define the same volume (for example, meshes that have been rotated or
370 * translated and then returned to an origin with PCA.) By design it does not
371 * analyze the differences to report on why two meshes differ - it simply
372 * returns a yes/no decision. Different vertex or face counts are grounds
373 * for immediate declaration the meshes differ - no effort is made to look for
374 * duplicate vertices or degenerate faces. Any such clean-ups must be performed
375 * before calling this function.
376 *
377 * The specification of a distance tolerance is used for vertex comparisons.
378 * Below the specified threshold, vertices that would otherwise be considered
379 * rejection criteria for being different will be considered the same.
380 * HOWEVER, that tolerance does NOT merge vertices - rather, when vertices are
381 * organized and sorted for comparison the candidate pairing vertices in the
382 * arrays are compared using the tolerance.
383 *
384 * Both vertex positions and face topology must be compatible - faces may use a
385 * different starting vertex (i.e. 0->1->2 and 1->2->0 are considered to be the
386 * same) but the ordering must be consistent (i.e. 0->2->1 would not be
387 * considered the same.)
388 *
389 * @param[in] f1 face index array referencing points in p1
390 * @param[in] num_f1 number of faces in f1
391 * @param[in] p1 first points array
392 * @param[in] num_p1 number of points in p1
393 * @param[in] f2 face index array referencing points in p2
394 * @param[in] num_f2 number of faces in f2
395 * @param[in] p2 second points array
396 * @param[in] num_p2 number of points in p2
397 * @param[in] dist_tol distance in mm below which points are considered the same
398 *
399 * @return 0 if same, otherwise return 1.
400 */
401BG_EXPORT extern int
403 const int *f1, size_t num_f1, const point_t *p1, size_t num_p1,
404 const int *f2, size_t num_f2, const point_t *p2, size_t num_p2,
405 fastf_t dist_tol
406 );
407
408/**
409 * @brief
410 * Generate a hash from the mesh data, using the tolerance parameter to
411 * clamp the numerical values. Both vertex positions and face topology
412 * are considered, in a style similar to bg_trimesh_diff.
413 *
414 * The clamping needed to generate a hash value will increase the chances of
415 * two similar meshes having the same hash, but the nature of numerical
416 * clamping results in some very close but not exact values clamping in
417 * opposite directions. Without global awareness of all vertex points at play
418 * in a database it is not possible to establish a binning that will work for
419 * all meshes in the same way (and there are no guarantees it is possible even
420 * with that knowledge, strictly speaking.) For a proper distance-based
421 * comparison of two meshes, bg_trimesh_diff should be used rather than
422 * comparing hash values. However, if mesh hash values DO match then the
423 * associated meshes should be quite close to being the same geometry per the
424 * specified tolerance - and in practice there are situations where we can get
425 * enough matching hashes to be useful - trial runs of PCA oriented BoT object
426 * grouping on a large database were able to identify matching hashes for
427 * about 80% of the cases were bg_trimesh_diff was able to geometrically
428 * identify fuzzy matches.
429 *
430 * Applications for this hash include looking up data associated with meshes
431 * via hash keys - if a large majority of duplicate meshes can be spotted in a
432 * .g database and indexed this way, it makes it possible to reduce the amount
433 * of duplicate data being stored. It is also possible to associated meshes
434 * with their hashes and then use a bg_trimesh_diff result to further map those
435 * hashes to unique data copies.
436 *
437 * TODO - look into whether some form of similarity hash might do better for
438 * our purposes here:
439 * https://github.com/seomoz/simhash-cpp
440 * https://github.com/FALCONN-LIB/FALCONN
441 * https://github.com/trendmicro/tlsh
442 *
443 * @param[in] f face index array referencing points in p
444 * @param[in] num_f number of faces in f
445 * @param[in] p points array
446 * @param[in] num_p number of points in p
447 * @param[in] dist_tol tolerance used when clamping points
448 *
449 * @return the bu_data_hash value of the mesh.
450 */
451BG_EXPORT extern unsigned long long
453 const int *f, size_t num_f, const point_t *p, size_t num_p,
454 fastf_t dist_tol
455 );
456
457
458
459
460/**
461 * Options governing triangle mesh repair operations.
462 *
463 * Repair attempts to produce a closed, consistently-oriented, manifold
464 * mesh from a defective input by colocating near-duplicate vertices,
465 * removing degenerate / duplicate faces, and filling boundary holes up
466 * to the caller-specified size limit.
467 */
469 fastf_t max_hole_area; /**< Largest hole area (mm^2) eligible for filling; 0 = use percentage */
470 fastf_t max_hole_area_percent; /**< Largest hole area as percentage of total mesh area; ignored when max_hole_area > 0 */
472
473/** Default repair options: fill holes up to 5% of the total mesh area. */
474#define BG_TRIMESH_REPAIR_OPTS_DEFAULT {0.0, 5.0}
476/**
477 * @brief
478 * Attempt to repair a non-manifold triangle mesh so that it becomes a
479 * closed, consistently-oriented solid.
480 *
481 * The function:
482 * 1. Colocates near-duplicate vertices (epsilon derived from bounding-box
483 * diagonal), removes degenerate and duplicate faces.
484 * 2. Removes small disconnected components (< 3% of total surface area).
485 * 3. Fills boundary holes whose area is at most the limit set in @p opts.
486 *
487 * @param[out] ofaces output face index array (caller must bu_free)
488 * @param[out] n_ofaces number of faces in @p ofaces
489 * @param[out] opnts output point array (caller must bu_free)
490 * @param[out] n_opnts number of points in @p opnts
491 * @param[in] ifaces input face index array (3 ints per face)
492 * @param[in] n_ifaces number of faces in @p ifaces
493 * @param[in] ipnts input point array
494 * @param[in] n_ipnts number of points in @p ipnts
495 * @param[in] opts repair options; NULL uses @c BG_TRIMESH_REPAIR_OPTS_DEFAULT
496 *
497 * @return 1 input mesh was already solid – @p ofaces / @p opnts are not set
498 * @return 0 repair succeeded – caller owns @p ofaces / @p opnts
499 * @return -1 error or repair failed to produce a valid result
500 */
501BG_EXPORT extern int
503 int **ofaces, int *n_ofaces,
504 point_t **opnts, int *n_opnts,
505 const int *ifaces, int n_ifaces,
506 const point_t *ipnts, int n_ipnts,
507 struct bg_trimesh_repair_opts *opts);
508
509
510/**
511 * Options governing triangle mesh remeshing operations.
512 *
513 * Remeshing regenerates the connectivity of a mesh so that its triangles
514 * are more uniform in size and shape while preserving the overall surface.
515 * The Geogram CVT (Centroidal Voronoi Tessellation) algorithm is used
516 * internally.
517 */
519 int target_count; /**< Desired vertex count in output; 0 = use count_multiplier */
520 fastf_t count_multiplier; /**< Multiply input vertex count by this to obtain target (default 10.0) */
521 fastf_t anisotropy; /**< Anisotropy weight for surface-normal direction; 0.0 = isotropic remesh (default 0.04) */
522 int lloyd_iters; /**< Number of Lloyd relaxation iterations (default 5) */
523 int newton_iters; /**< Number of Newton iterations for CVT optimization (default 30) */
525
526/** Default remesh options: 10× input vertex density, moderate anisotropy. */
527#define BG_TRIMESH_REMESH_OPTS_DEFAULT {0, 10.0, 0.04, 5, 30}
529/**
530 * @brief
531 * Remesh a triangle mesh to improve element quality and/or change density.
532 *
533 * A Geogram-based pre-repair pass is run on the input before remeshing so
534 * that degenerate or near-duplicate geometry does not confuse the CVT solver.
535 * The output mesh is a new triangulation of the same surface.
536 *
537 * @param[out] ofaces output face index array (caller must bu_free)
538 * @param[out] n_ofaces number of faces in @p ofaces
539 * @param[out] opnts output point array (caller must bu_free)
540 * @param[out] n_opnts number of points in @p opnts
541 * @param[in] ifaces input face index array (3 ints per face)
542 * @param[in] n_ifaces number of faces in @p ifaces
543 * @param[in] ipnts input point array
544 * @param[in] n_ipnts number of points in @p ipnts
545 * @param[in] opts remesh options; NULL uses @c BG_TRIMESH_REMESH_OPTS_DEFAULT
546 *
547 * @return 0 on success – caller owns @p ofaces / @p opnts
548 * @return -1 on error
549 */
550BG_EXPORT extern int
552 int **ofaces, int *n_ofaces,
553 point_t **opnts, int *n_opnts,
554 const int *ifaces, int n_ifaces,
555 const point_t *ipnts, int n_ipnts,
556 struct bg_trimesh_remesh_opts *opts);
557
558
559__END_DECLS
560
561#endif /* BG_TRIMESH_H */
562/** @} */
563/*
564 * Local Variables:
565 * mode: C
566 * tab-width: 8
567 * indent-tabs-mode: t
568 * c-file-style: "stroustrup"
569 * End:
570 * ex: shiftwidth=4 tabstop=8
571 */
Header file for the BRL-CAD common definitions.
int bg_trimesh_hanging_nodes(int num_vertices, int num_faces, fastf_t *vertices, int *faces, struct bg_trimesh_solid_errors *errors)
int bg_trimesh_misoriented_edges(int num_edges, struct bg_trimesh_halfedge *edge_list, bg_edge_error_funct_t error_edge_func, void *data)
int bg_trimesh_aabb(point_t *min, point_t *max, const int *faces, size_t num_faces, const point_t *p, size_t num_pnts)
Calculate an axis aligned bounding box (RPP) for a triangle mesh.
int bg_trimesh_face_gather(int face_idx, void *data)
int bg_trimesh_sync(int *of, int *f, int fcnt)
Return a face set where all topologically connected faces are oriented consistently relative to their...
int bg_trimesh_diff(const int *f1, size_t num_f1, const point_t *p1, size_t num_p1, const int *f2, size_t num_f2, const point_t *p2, size_t num_p2, fastf_t dist_tol)
Compare two trimeshes to determine if they (within tolerance) define the same mesh.
int bg_trimesh_degenerate_faces(int num_faces, int *fpoints, bg_face_error_func_t degenerate_func, void *data)
int bg_trimesh_face_continue(int face_idx, void *data)
int bg_trimesh_edge_gather(struct bg_trimesh_halfedge *edge, void *data)
int bg_trimesh_excess_edges(int num_edges, struct bg_trimesh_halfedge *edge_list, bg_edge_error_funct_t error_edge_func, void *data)
int bg_trimesh_decimate(int **ofaces, int *n_ofaces, int *ifaces, int n_ifaces, point_t *p, int n_p, struct bg_trimesh_decimation_settings *s)
Decimate a mesh and return the decimated faces.
fastf_t bg_trimesh_area(const int *faces, size_t num_faces, const point_t *p, size_t num_pnts)
Calculate the surface area of a triangle mesh.
int bg_trimesh_edge_exit(struct bg_trimesh_halfedge *edge, void *data)
int bg_trimesh_oriented(int vcnt, int fcnt, fastf_t *v, int *f)
int bg_trimesh_manifold_closed(int vcnt, int fcnt, fastf_t *v, int *f)
int bg_trimesh_2d_gc(int **ofaces, int *n_ofaces, point2d_t **opnts, int *n_opnts, const int *ifaces, int n_ifaces, const point2d_t *ipnts)
Return trimesh information for a planar (2D) mesh that contains just the set of points active in the ...
int bg_trimesh_optimize(int **ofaces, int *n_ofaces, point_t **opnts, vect_t **onorms, int *n_opnts, const int *ifaces, int n_ifaces, const point_t *ipnts, const vect_t *inorms, struct bg_trimesh_optimization_settings *s)
Return trimesh information for a 3D mesh that contains just the date needed to represent in the mesh....
int bg_trimesh_edge_continue(struct bg_trimesh_halfedge *edge, void *data)
void bg_free_trimesh_edges(struct bg_trimesh_edges *edges)
int bg_trimesh_unmatched_edges(int num_edges, struct bg_trimesh_halfedge *edge_list, bg_edge_error_funct_t error_edge_func, void *data)
int bg_trimesh_3d_gc(int **ofaces, point_t **opnts, int *n_opnts, const int *faces, int num_faces, const point_t *in_pts)
Return trimesh information for a 3D mesh that contains just the set of points active in the mesh.
int bg_trimesh_isect(int **faces_inside_1, int *num_faces_inside_1, int **faces_inside_2, int *num_faces_inside_2, int **faces_isect_1, int *num_faces_isect_1, int **faces_isect_2, int *num_faces_isect_2, int *faces_1, int num_faces_1, point_t *vertices_1, int num_vertices_1, int *faces_2, int num_faces_2, point_t *vertices_2, int num_vertices_2)
int bg_trimesh_2d_plot3(const char *fname, const int *faces, size_t num_faces, const point2d_t *pnts, size_t num_pnts)
Return a set of face sets where all topologically connected faces are grouped into common sets.
int bg_trimesh_split(int ***ofs, int **ofc, int *f, int fcnt)
Return a set of face sets where all topologically connected faces are grouped into common sets.
int bg_trimesh_remesh(int **ofaces, int *n_ofaces, point_t **opnts, int *n_opnts, const int *ifaces, int n_ifaces, const point_t *ipnts, int n_ipnts, struct bg_trimesh_remesh_opts *opts)
Remesh a triangle mesh to improve element quality and/or change density.
int(* bg_face_error_func_t)(int face_idx, void *data)
Definition trimesh.h:104
fastf_t bg_trimesh_volume(const int *faces, size_t num_faces, const point_t *p, size_t num_pnts)
struct bg_trimesh_halfedge * bg_trimesh_generate_edge_list(int fcnt, int *f)
int bg_trimesh_solid2(int vcnt, int fcnt, fastf_t *v, int *f, struct bg_trimesh_solid_errors *errors)
int bg_trimesh_face_exit(int face_idx, void *data)
int bg_trimesh_normals(vect_t **onorms, int *ifaces, int n_ifaces, point_t *p, int n_p)
Compute vertex normals for a mesh based on the connected faces.
void bg_free_trimesh_solid_errors(struct bg_trimesh_solid_errors *errors)
int bg_trimesh_repair(int **ofaces, int *n_ofaces, point_t **opnts, int *n_opnts, const int *ifaces, int n_ifaces, const point_t *ipnts, int n_ipnts, struct bg_trimesh_repair_opts *opts)
Attempt to repair a non-manifold triangle mesh so that it becomes a closed, consistently-oriented sol...
int(* bg_edge_error_funct_t)(struct bg_trimesh_halfedge *edge, void *data)
Definition trimesh.h:105
void bg_free_trimesh_faces(struct bg_trimesh_faces *faces)
unsigned long long bg_trimesh_hash(const int *f, size_t num_f, const point_t *p, size_t num_p, fastf_t dist_tol)
Generate a hash from the mesh data, using the tolerance parameter to clamp the numerical values....
int bg_trimesh_solid(int vcnt, int fcnt, fastf_t *v, int *f, int **bedges)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:348
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:333
fastf_t point2d_t[ELEMENTS_PER_POINT2D]
2-tuple point
Definition vmath.h:342
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:354
Algorithms related to 3D meshes built from triangles.
Definition trimesh.h:41
fastf_t max_hole_area_percent
Definition trimesh.h:471
struct bg_trimesh_edges excess
Definition trimesh.h:60
struct bg_trimesh_edges misoriented
Definition trimesh.h:61
struct bg_trimesh_faces degenerate
Definition trimesh.h:58
struct bg_trimesh_edges unmatched
Definition trimesh.h:59
Definition vls.h:53
NMG topological edge.
Definition topology.h:144
fundamental vector, matrix, quaternion math macros