Skip to content

Commit cb02445

Browse files
committed
Add MESH geometric object type for arbitrary triangulated 3D surfaces
Implement a new MESH primitive alongside SPHERE, CYLINDER, BLOCK, and PRISM. A mesh is defined by a vertex array and triangle index array, with a BVH (bounding volume hierarchy) for O(log N) queries. Core operations implemented: - point_in_mesh: ray casting with parity counting and deduplication - normal_to_mesh: BVH-accelerated closest-face search - get_mesh_bounding_box: from BVH root node - get_mesh_volume: divergence theorem (signed tetrahedron volumes) - intersect_line_segment_with_mesh: for subpixel smoothing integration - init_mesh: validates geometry, computes normals, fixes winding, builds BVH BVH uses SAH (surface area heuristic) binned construction with flat array layout. Ray-triangle intersection uses Moller-Trumbore algorithm. Closest-point queries use Eberly's algorithm with BVH pruning. Also adds make_mesh/make_mesh_with_center constructors, mesh copy/equal/destroy in geom-ctl-io.c, and 11 unit tests covering point-in, volume, bbox, normals, line-segment intersection, and comparison against the Block primitive.
1 parent 5699493 commit cb02445

5 files changed

Lines changed: 1193 additions & 2 deletions

File tree

utils/Makefile.am

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ geomtst_SOURCES = geomtst.c
2020
geomtst_LDADD = libctlgeom.la
2121
geomtst_CPPFLAGS = -I$(top_srcdir)/src
2222

23-
check_PROGRAMS = test-prism
23+
check_PROGRAMS = test-prism test-mesh
2424

2525
test_prism_SOURCES = test-prism.c
2626
test_prism_LDADD = libctlgeom.la
2727
test_prism_CPPFLAGS = -I$(top_srcdir)/src
2828

29-
TESTS = test-prism
29+
test_mesh_SOURCES = test-mesh.c
30+
test_mesh_LDADD = libctlgeom.la
31+
test_mesh_CPPFLAGS = -I$(top_srcdir)/src
32+
33+
TESTS = test-prism test-mesh
3034

3135
dist_man_MANS = gen-ctl-io.1
3236

utils/ctlgeom.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ GEOMETRIC_OBJECT make_slanted_prism_with_center(MATERIAL_TYPE material, vector3
173173
const vector3 *vertices, int num_vertices, double height,
174174
vector3 axis, double sidewall_angle);
175175

176+
// mesh with center computed as centroid of vertices
177+
GEOMETRIC_OBJECT make_mesh(MATERIAL_TYPE material, const vector3 *vertices, int num_vertices,
178+
const int *triangles, int num_triangles);
179+
180+
// mesh with explicit center (vertices shifted so centroid = center)
181+
GEOMETRIC_OBJECT make_mesh_with_center(MATERIAL_TYPE material, vector3 center,
182+
const vector3 *vertices, int num_vertices,
183+
const int *triangles, int num_triangles);
184+
176185
int vector3_nearly_equal(vector3 v1, vector3 v2, double tolerance);
177186

178187
/**************************************************************************/

0 commit comments

Comments
 (0)