From b8f7ee6d4680bdcb961d469e1203ab1b936730d0 Mon Sep 17 00:00:00 2001 From: pv Date: Tue, 2 Sep 2025 10:40:46 +0200 Subject: [PATCH 1/4] Fix align libigl barycentrioc coordinates to compas. --- CHANGELOG.md | 1 + docs/examples/example_intersections.py | 12 ++- .../example_intersections_barycentric.py | 46 ++++++++++ docs/examples/example_mapping.py | 6 +- docs/examples/example_mapping_patterns.py | 4 +- pyproject.toml | 35 ++++--- src/compas_libigl/intersections.py | 92 ++++++++++++++++++- 7 files changed, 170 insertions(+), 26 deletions(-) create mode 100644 docs/examples/example_intersections_barycentric.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c38de..823ed15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * Fixed `compas_libigl` plugins are not detected. +* Align barycentric coordinates of libigl to COMPAS. ### Removed diff --git a/docs/examples/example_intersections.py b/docs/examples/example_intersections.py index 301384d..e8e3196 100644 --- a/docs/examples/example_intersections.py +++ b/docs/examples/example_intersections.py @@ -7,6 +7,7 @@ from compas_viewer import Viewer from compas_libigl.intersections import intersection_rays_mesh +from compas_libigl.intersections import barycenter_to_point # ============================================================================== # Input geometry @@ -56,11 +57,12 @@ intersections = [] for ray, hits in zip(rays, hits_per_ray): if hits: - base, vector = ray - index = hits[0][0] - distance = hits[0][3] - face = index_face[index] - point = base + vector * distance + idx, u, v, w = hits[0] + vertices = mesh.face_vertices(idx) + p1 = mesh.vertex_coordinates(vertices[0]) + p2 = mesh.vertex_coordinates(vertices[1]) + p3 = mesh.vertex_coordinates(vertices[2]) + point = barycenter_to_point(u, v, w, p1, p2, p3) intersections.append(point) # ============================================================================== diff --git a/docs/examples/example_intersections_barycentric.py b/docs/examples/example_intersections_barycentric.py new file mode 100644 index 0000000..f72e3b0 --- /dev/null +++ b/docs/examples/example_intersections_barycentric.py @@ -0,0 +1,46 @@ +import compas.geometry +import compas.datastructures +from compas_libigl.intersections import intersection_rays_mesh, intersection_ray_mesh +from compas_libigl.intersections import barycenter_to_point +from compas_viewer import Viewer +from compas.colors import Color +from compas.geometry import Line +import compas + + +p0 = compas.geometry.Point(2, 0, 0) +p1 = compas.geometry.Point(3 + 2, 0 - 2, 13) +p2 = compas.geometry.Point(0 - 2, 0 - 2, 10) +p3 = compas.geometry.Point(0 - 2, 2 + 2, 10) + +mesh = compas.datastructures.Mesh.from_points([[p1.x, p1.y, p1.z], [p2.x, p2.y, p2.z], [p3.x, p3.y, p3.z]]) + +ray = (p0, compas.geometry.Vector(0, 0, 1)) +hits_per_ray = intersection_ray_mesh(ray, mesh.to_vertices_and_faces()) + +idx, u, v, w = hits_per_ray[0][0], hits_per_ray[0][1], hits_per_ray[0][2], hits_per_ray[0][3] + +index_face = {index: face for index, face in enumerate(mesh.faces())} + +intersections = [] +for hit in hits_per_ray: + idx, u, v, w = hit + point = barycenter_to_point(u, v, w, p1, p2, p3) + intersections.append(point) + +bary_coords = compas.geometry.barycentric_coordinates(intersections[0], [p1, p2, p3]) +print("libigl barycentric coordinates: ", u, v, w) +print("compas barycentric coordinates: ", *bary_coords) + +# ============================================================================== +# Visualisation +# ============================================================================== + +viewer = Viewer(width=1600, height=900) + +viewer.scene.add(mesh, opacity=0.7, show_points=False) + +for intersection in intersections: + viewer.scene.add(Line(p0, intersection), linecolor=Color.blue(), linewidth=3) + +viewer.show() diff --git a/docs/examples/example_mapping.py b/docs/examples/example_mapping.py index 3a080a8..4bc585a 100644 --- a/docs/examples/example_mapping.py +++ b/docs/examples/example_mapping.py @@ -61,8 +61,8 @@ # Offset mesh by normals, normals are interpolated from the original mesh. # ============================================================================== mesh_mapped_offset = mesh_mapped.copy() -for i in range(mesh_mapped.number_of_vertices()): - mesh_mapped_offset.vertex_attributes(i, "xyz", mesh_mapped.vertex_attributes(i, "xyz") - mn[i]*0.001) +for i in range(mesh_mapped.number_of_vertices()): + mesh_mapped_offset.vertex_attributes(i, "xyz", mesh_mapped.vertex_attributes(i, "xyz") - mn[i] * 0.001) # ============================================================================== # Get Boundary Polylines @@ -74,7 +74,7 @@ points = [] for j in range(len(mf[i])): id = mf[i][j] - points.append(mesh_mapped.vertex_attributes(id, "xyz") + mn[id]*0.002) + points.append(mesh_mapped.vertex_attributes(id, "xyz") + mn[id] * 0.002) points.append(points[0]) polyline = Polyline(points) boundaries.append(polyline) diff --git a/docs/examples/example_mapping_patterns.py b/docs/examples/example_mapping_patterns.py index 64db92b..01f84ee 100644 --- a/docs/examples/example_mapping_patterns.py +++ b/docs/examples/example_mapping_patterns.py @@ -9,7 +9,6 @@ from compas_libigl.mapping import map_pattern_to_mesh - # ============================================================================== # Input geometry: 3D Mesh # ============================================================================== @@ -17,7 +16,6 @@ mesh = Mesh.from_obj(Path(__file__).parent.parent.parent / "data" / "minimal_surface.obj") - for vertex in mesh.vertices(): x, y, z = mesh.vertex_attributes(vertex, "xyz") # type: ignore mesh.vertex_attributes(vertex, "xyz", [x, -z, y]) @@ -32,7 +30,7 @@ for vertex in mesh.vertices(): x, y, z = mesh.vertex_attributes(vertex, "xyz") # type: ignore - if abs(z-aabb.zmin) < 1e-3 or abs(z-aabb.zmax) < 1e-3: + if abs(z - aabb.zmin) < 1e-3 or abs(z - aabb.zmax) < 1e-3: fixed_vertices.append(vertex) # ============================================================================== diff --git a/pyproject.toml b/pyproject.toml index e078d8d..dc0c68f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,18 +12,31 @@ authors = [ { name = "Petras Vestartas", email = "petrasvestartas@gmail.com" }, ] classifiers = ["License :: OSI Approved :: BSD License"] -dynamic = ['dependencies', 'optional-dependencies', 'version'] +dynamic = ['version'] +dependencies = [ + "compas >=2.0.0", + "tessagon", +] [project.urls] Homepage = "https://compas.dev/compas_libigl/latest/" -# ============================================================================ -# setuptools config -# ============================================================================ - -[tool.setuptools.dynamic] -dependencies = { file = "requirements.txt" } -optional-dependencies = { dev = { file = "requirements-dev.txt" } } +[dependency-groups] +dev = [ + "ruff", + "pre-commit", + "build", + { include-group = "tests" }, + { include-group = "docs" }, +] +tests = [ + "pytest", + "numpy", +] +docs = [ + "sphinx", + "sphinx-compas-theme", +] # ============================================================================ # pytest configuration @@ -83,8 +96,8 @@ CMAKE_POLICY_DEFAULT_CMP0135 = "NEW" [tool.cibuildwheel] build-verbosity = 3 -test-requires = ["numpy", "compas", "pytest", "build", "tessagon"] -test-command = "pip install numpy compas && pip list && pytest {project}/tests" +test-groups = ["tests"] +test-command = "pytest {project}/tests" build-frontend = "pip" manylinux-x86_64-image = "manylinux2014" skip = ["*_i686", "*-musllinux_*", "*-win32", "pp*"] @@ -143,4 +156,4 @@ max-doc-length = 179 [tool.ruff.format] docstring-code-format = true -docstring-code-line-length = "dynamic" +docstring-code-line-length = "dynamic" \ No newline at end of file diff --git a/src/compas_libigl/intersections.py b/src/compas_libigl/intersections.py index 05fb692..f45b7ce 100644 --- a/src/compas_libigl/intersections.py +++ b/src/compas_libigl/intersections.py @@ -4,6 +4,69 @@ from compas_libigl import _intersections +def _conversion_libigl_to_compas(hits_per_ray): + """Convert libigl barycentric coordinates to COMPAS barycentric coordinates. + + Parameters + ---------- + hits_per_ray : list[tuple[int, float, float, float]] + Tuples of (face_index, u, v, distance) from libigl ray intersection + + Returns + ------- + list[tuple[int, float, float, float]] + Tuples of (face_index, w, u, v) in COMPAS barycentric coordinate ordering + + Note + ---- + libigl uses: P = (1-u-v)*v0 + u*v1 + v*v2 + This function returns [w, u, v] = [1-u-v, u, v] to match COMPAS ordering + """ + + hits_compas = [] + for h in hits_per_ray: + idx, u, v, _ = h + w = 1.0 - u - v + hits_compas.append([idx, w, v, u]) + return hits_compas + + +def barycenter_to_point(u, v, w, p1, p2, p3): + """Convert COMPAS barycentric coordinates to a point. + + Parameters + ---------- + u : float + The u coordinate + v : float + The v coordinate + w : float + The w coordinate + p1 : tuple[float, float, float] + The first point + p2 : tuple[float, float, float] + The second point + p3 : tuple[float, float, float] + The third point + + + Returns + ------- + list[float] + The point at the intersection of the ray and the mesh + + Note + ---- + libigl uses: P = (1-u-v)*v0 + u*v1 + v*v2 + This function returns [w, u, v] = [1-u-v, u, v] to match COMPAS ordering + """ + w = 1 - u - v # barycentric coordinates + + phit = [u * p1[0] + v * p2[0] + w * p3[0], u * p1[1] + v * p2[1] + w * p3[1], u * p1[2] + v * p2[2] + w * p3[2]] + + return phit + + @plugin(category="intersections") def intersection_ray_mesh(ray, M): """Compute the intersection(s) between a ray and a mesh. @@ -24,8 +87,15 @@ def intersection_ray_mesh(ray, M): 0. the index of the intersected face 1. the u coordinate of the intersection in the barycentric coordinates of the face - 2. the u coordinate of the intersection in the barycentric coordinates of the face + 2. the v coordinate of the intersection in the barycentric coordinates of the face 3. the distance between the ray origin and the hit + + Note + ---- + The barycentric coordinates (u, v) follow the libigl convention where: + - For a triangle with vertices (v0, v1, v2) at face indices F[face_id] + - The intersection point P = (1-u-v)*v0 + u*v1 + v*v2 + - This differs from COMPAS barycentric_coordinates which uses a different vertex ordering """ point, vector = ray vertices, faces = M @@ -33,7 +103,13 @@ def intersection_ray_mesh(ray, M): D = np.asarray(vector, dtype=np.float64) V = np.asarray(vertices, dtype=np.float64) F = np.asarray(faces, dtype=np.int32) - return _intersections.intersection_ray_mesh(P, D, V, F) + + hits_per_ray = _intersections.intersection_ray_mesh(P, D, V, F) + + # Convert libigl barycentric coordinates to COMPAS convention + hits_compas = _conversion_libigl_to_compas(hits_per_ray) + + return hits_compas def intersection_rays_mesh(rays, M): @@ -55,7 +131,7 @@ def intersection_rays_mesh(rays, M): 0. the index of the intersected face 1. the u coordinate of the intersection in the barycentric coordinates of the face - 2. the u coordinate of the intersection in the barycentric coordinates of the face + 2. the v coordinate of the intersection in the barycentric coordinates of the face 3. the distance between the ray origin and the hit """ points, vectors = zip(*rays) @@ -64,4 +140,12 @@ def intersection_rays_mesh(rays, M): D = np.asarray(vectors, dtype=np.float64) V = np.asarray(vertices, dtype=np.float64) F = np.asarray(faces, dtype=np.int32) - return _intersections.intersection_rays_mesh(P, D, V, F) + + hits_per_ray = _intersections.intersection_rays_mesh(P, D, V, F) + + # Convert libigl barycentric coordinates to COMPAS convention + hits_per_ray_compas = [] + for hit in hits_per_ray: + hits_per_ray_compas.append(_conversion_libigl_to_compas(hit)) + + return hits_per_ray_compas From de6033a6f4e1e6d53f13d7adfedb30bbb71022fb Mon Sep 17 00:00:00 2001 From: pv Date: Fri, 5 Sep 2025 18:19:35 +0200 Subject: [PATCH 2/4] FIX barycentric coordinates and output a point --- CHANGELOG.md | 1 + docs/examples/example_intersections.py | 33 ++++--- .../example_intersections_barycentric.py | 11 ++- src/compas_libigl/intersections.py | 98 +++++++++++-------- 4 files changed, 85 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 823ed15..e326d2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed `compas_libigl` plugins are not detected. * Align barycentric coordinates of libigl to COMPAS. +* Ray mesh intersection now returns a point. ### Removed diff --git a/docs/examples/example_intersections.py b/docs/examples/example_intersections.py index e8e3196..3940897 100644 --- a/docs/examples/example_intersections.py +++ b/docs/examples/example_intersections.py @@ -17,7 +17,6 @@ trimesh = mesh.copy() trimesh.quads_to_triangles() - # ============================================================================== # Rays # ============================================================================== @@ -25,8 +24,8 @@ base = Point(*mesh.centroid()) base.z = 0 -theta = np.linspace(0, np.pi, 20, endpoint=False) -phi = np.linspace(0, 2 * np.pi, 20, endpoint=False) +theta = np.linspace(0, np.pi, 5, endpoint=False) +phi = np.linspace(0, 2 * np.pi, 5, endpoint=False) theta, phi = np.meshgrid(theta, phi) theta = theta.ravel() phi = phi.ravel() @@ -39,11 +38,13 @@ mask = xyz[:, 2] > 0 hemi = xyz[mask] +lines = [] rays = [] for x, y, z in hemi: point = Point(x, y, z) vector = point - base vector.unitize() + lines.append(Line(base, base + vector)) rays.append((base, vector)) # ============================================================================== @@ -52,18 +53,13 @@ index_face = {index: face for index, face in enumerate(mesh.faces())} -hits_per_ray = intersection_rays_mesh(rays, mesh.to_vertices_and_faces()) +hits_per_rays = intersection_rays_mesh(rays, trimesh.to_vertices_and_faces()) -intersections = [] -for ray, hits in zip(rays, hits_per_ray): - if hits: - idx, u, v, w = hits[0] - vertices = mesh.face_vertices(idx) - p1 = mesh.vertex_coordinates(vertices[0]) - p2 = mesh.vertex_coordinates(vertices[1]) - p3 = mesh.vertex_coordinates(vertices[2]) - point = barycenter_to_point(u, v, w, p1, p2, p3) - intersections.append(point) +intersection_points = [] +for hit in hits_per_rays: + if hit: + pt, idx, u, v, w = hit[0] + intersection_points.append(pt) # ============================================================================== # Visualisation @@ -73,7 +69,12 @@ viewer.scene.add(mesh, opacity=0.7, show_points=False) -for intersection in intersections: - viewer.scene.add(Line(base, intersection), linecolor=Color.blue(), linewidth=3) +for point in intersection_points: + viewer.scene.add(Line(base, point), linecolor=Color.blue(), linewidth=3) + viewer.scene.add(point, pointcolor=Color.red(), pointsize=10) + +for line in lines: + for i in range(20): + viewer.scene.add(line.point_at(i / 20), pointcolor=Color.red(), pointsize=5) viewer.show() diff --git a/docs/examples/example_intersections_barycentric.py b/docs/examples/example_intersections_barycentric.py index f72e3b0..e6e75c8 100644 --- a/docs/examples/example_intersections_barycentric.py +++ b/docs/examples/example_intersections_barycentric.py @@ -18,20 +18,23 @@ ray = (p0, compas.geometry.Vector(0, 0, 1)) hits_per_ray = intersection_ray_mesh(ray, mesh.to_vertices_and_faces()) -idx, u, v, w = hits_per_ray[0][0], hits_per_ray[0][1], hits_per_ray[0][2], hits_per_ray[0][3] +point, idx, u, v, w = hits_per_ray[0][0], hits_per_ray[0][1], hits_per_ray[0][2], hits_per_ray[0][3], hits_per_ray[0][4] index_face = {index: face for index, face in enumerate(mesh.faces())} intersections = [] for hit in hits_per_ray: - idx, u, v, w = hit + point, idx, w, u, v = hit point = barycenter_to_point(u, v, w, p1, p2, p3) intersections.append(point) bary_coords = compas.geometry.barycentric_coordinates(intersections[0], [p1, p2, p3]) -print("libigl barycentric coordinates: ", u, v, w) +print("libigl barycentric coordinates: ", w, u, v) print("compas barycentric coordinates: ", *bary_coords) +print(barycenter_to_point(bary_coords[0], bary_coords[1], bary_coords[2], p1, p2, p3)) +print(barycenter_to_point(w, u, v, p1, p2, p3)) + # ============================================================================== # Visualisation # ============================================================================== @@ -43,4 +46,6 @@ for intersection in intersections: viewer.scene.add(Line(p0, intersection), linecolor=Color.blue(), linewidth=3) +viewer.scene.add(point, pointcolor=Color.red(), pointsize=10) + viewer.show() diff --git a/src/compas_libigl/intersections.py b/src/compas_libigl/intersections.py index f45b7ce..b1ab715 100644 --- a/src/compas_libigl/intersections.py +++ b/src/compas_libigl/intersections.py @@ -1,70 +1,86 @@ import numpy as np +from compas.geometry import Point from compas.plugins import plugin from compas_libigl import _intersections -def _conversion_libigl_to_compas(hits_per_ray): +def _conversion_libigl_to_compas(hits_per_ray, M): """Convert libigl barycentric coordinates to COMPAS barycentric coordinates. Parameters ---------- hits_per_ray : list[tuple[int, float, float, float]] Tuples of (face_index, u, v, distance) from libigl ray intersection + M : tuple[list[list[float]], list[list[int]]] + A mesh represented by a tuple of (vertices, faces) + where vertices are 3D points and faces are triangles Returns ------- - list[tuple[int, float, float, float]] - Tuples of (face_index, w, u, v) in COMPAS barycentric coordinate ordering + list[tuple[list[float], int, float, float, float]] + Tuples of (point, face_index, u, v, w) in COMPAS barycentric coordinate ordering Note ---- libigl uses: P = (1-u-v)*v0 + u*v1 + v*v2 - This function returns [w, u, v] = [1-u-v, u, v] to match COMPAS ordering + COMPAS uses: P = u*v0 + v*v1 + w*v2 where u + v + w = 1 + This function converts libigl coordinates to match COMPAS barycentric coordinate ordering """ + vertices = M[0] + faces = M[1] hits_compas = [] for h in hits_per_ray: - idx, u, v, _ = h - w = 1.0 - u - v - hits_compas.append([idx, w, v, u]) + idx, u_libigl, v_libigl, _ = h + w = 1.0 - u_libigl - v_libigl # libigl's (1-u-v) coefficient + u = u_libigl # libigl's u coefficient + v = v_libigl # libigl's v coefficient + + face = faces[idx] + p1, p2, p3 = vertices[face[0]], vertices[face[1]], vertices[face[2]] + point = barycenter_to_point(u, v, w, p1, p2, p3) + + # To match COMPAS barycentric coordinates exactly: + # COMPAS expects coordinates in order [p1_weight, p2_weight, p3_weight] + # Our formula is P = w*p1 + u*p2 + v*p3, so COMPAS order should be [w, u, v] + hits_compas.append([point, idx, u, v, w]) return hits_compas def barycenter_to_point(u, v, w, p1, p2, p3): - """Convert COMPAS barycentric coordinates to a point. + """Convert barycentric coordinates to a point using the working interpolation formula. Parameters ---------- u : float - The u coordinate + The u coordinate (weight for p2) v : float - The v coordinate + The v coordinate (weight for p3) w : float - The w coordinate + The w coordinate (weight for p1) p1 : tuple[float, float, float] - The first point + The first vertex p2 : tuple[float, float, float] - The second point + The second vertex p3 : tuple[float, float, float] - The third point - + The third vertex Returns ------- - list[float] - The point at the intersection of the ray and the mesh + Point + The interpolated point Note ---- - libigl uses: P = (1-u-v)*v0 + u*v1 + v*v2 - This function returns [w, u, v] = [1-u-v, u, v] to match COMPAS ordering + Uses barycentric interpolation: P = w*p1 + u*p2 + v*p3 + where w + u + v = 1 """ - w = 1 - u - v # barycentric coordinates - - phit = [u * p1[0] + v * p2[0] + w * p3[0], u * p1[1] + v * p2[1] + w * p3[1], u * p1[2] + v * p2[2] + w * p3[2]] + phit = [w * p1[0] + u * p2[0] + v * p3[0], + w * p1[1] + u * p2[1] + v * p3[1], + w * p1[2] + u * p2[2] + v * p3[2]] - return phit + return Point(*phit) @plugin(category="intersections") @@ -81,21 +97,23 @@ def intersection_ray_mesh(ray, M): Returns ------- - list[tuple[int, float, float, float]] + list[tuple[list[float], int, float, float, float]] The array contains a tuple per intersection of the ray with the mesh. Each tuple contains: - 0. the index of the intersected face - 1. the u coordinate of the intersection in the barycentric coordinates of the face - 2. the v coordinate of the intersection in the barycentric coordinates of the face - 3. the distance between the ray origin and the hit + 0. the point of intersection + 1. the index of the intersected face + 2. the u coordinate of the intersection in COMPAS barycentric coordinates + 3. the v coordinate of the intersection in COMPAS barycentric coordinates + 4. the w coordinate of the intersection in COMPAS barycentric coordinates + Note ---- - The barycentric coordinates (u, v) follow the libigl convention where: - - For a triangle with vertices (v0, v1, v2) at face indices F[face_id] - - The intersection point P = (1-u-v)*v0 + u*v1 + v*v2 - - This differs from COMPAS barycentric_coordinates which uses a different vertex ordering + The returned barycentric coordinates follow COMPAS convention where: + - For a triangle with vertices (p1, p2, p3) at face indices F[face_id] + - The intersection point P = u*p1 + v*p2 + w*p3 where u + v + w = 1 + - These coordinates match those returned by compas.geometry.barycentric_coordinates """ point, vector = ray vertices, faces = M @@ -107,7 +125,7 @@ def intersection_ray_mesh(ray, M): hits_per_ray = _intersections.intersection_ray_mesh(P, D, V, F) # Convert libigl barycentric coordinates to COMPAS convention - hits_compas = _conversion_libigl_to_compas(hits_per_ray) + hits_compas = _conversion_libigl_to_compas(hits_per_ray, M) return hits_compas @@ -125,14 +143,16 @@ def intersection_rays_mesh(rays, M): Returns ------- - list[list[tuple[int, float, float, float]]] + list[list[tuple[list[float], int, float, float, float]]] List of intersection results, one per ray. Each intersection result contains tuples with: - 0. the index of the intersected face - 1. the u coordinate of the intersection in the barycentric coordinates of the face - 2. the v coordinate of the intersection in the barycentric coordinates of the face - 3. the distance between the ray origin and the hit + 0. the point of intersection + 1. the index of the intersected face + 2. the u coordinate of the intersection in COMPAS barycentric coordinates + 3. the v coordinate of the intersection in COMPAS barycentric coordinates + 4. the w coordinate of the intersection in COMPAS barycentric coordinates + """ points, vectors = zip(*rays) vertices, faces = M @@ -146,6 +166,6 @@ def intersection_rays_mesh(rays, M): # Convert libigl barycentric coordinates to COMPAS convention hits_per_ray_compas = [] for hit in hits_per_ray: - hits_per_ray_compas.append(_conversion_libigl_to_compas(hit)) + hits_per_ray_compas.append(_conversion_libigl_to_compas(hit, M)) return hits_per_ray_compas From b0939c132d3fa235bc1309c9112c74567009e5ac Mon Sep 17 00:00:00 2001 From: pv Date: Fri, 5 Sep 2025 18:21:33 +0200 Subject: [PATCH 3/4] Fix example file --- docs/examples/example_intersections.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/examples/example_intersections.py b/docs/examples/example_intersections.py index 3940897..4811c19 100644 --- a/docs/examples/example_intersections.py +++ b/docs/examples/example_intersections.py @@ -56,10 +56,11 @@ hits_per_rays = intersection_rays_mesh(rays, trimesh.to_vertices_and_faces()) intersection_points = [] -for hit in hits_per_rays: - if hit: - pt, idx, u, v, w = hit[0] - intersection_points.append(pt) +for hits_per_ray in hits_per_rays: + if hits_per_ray: + for hit in hits_per_ray: + pt, idx, u, v, w = hit + intersection_points.append(pt) # ============================================================================== # Visualisation From 2cfc18872df25e034b8c81efba6526a3af13bcdd Mon Sep 17 00:00:00 2001 From: pv Date: Fri, 5 Sep 2025 18:22:47 +0200 Subject: [PATCH 4/4] CLEANUP --- docs/examples/example_intersections.py | 2 -- docs/examples/example_intersections_barycentric.py | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/examples/example_intersections.py b/docs/examples/example_intersections.py index 4811c19..df735b8 100644 --- a/docs/examples/example_intersections.py +++ b/docs/examples/example_intersections.py @@ -51,8 +51,6 @@ # Intersections # ============================================================================== -index_face = {index: face for index, face in enumerate(mesh.faces())} - hits_per_rays = intersection_rays_mesh(rays, trimesh.to_vertices_and_faces()) intersection_points = [] diff --git a/docs/examples/example_intersections_barycentric.py b/docs/examples/example_intersections_barycentric.py index e6e75c8..903cc8e 100644 --- a/docs/examples/example_intersections_barycentric.py +++ b/docs/examples/example_intersections_barycentric.py @@ -1,6 +1,6 @@ import compas.geometry import compas.datastructures -from compas_libigl.intersections import intersection_rays_mesh, intersection_ray_mesh +from compas_libigl.intersections import intersection_ray_mesh from compas_libigl.intersections import barycenter_to_point from compas_viewer import Viewer from compas.colors import Color @@ -20,8 +20,6 @@ point, idx, u, v, w = hits_per_ray[0][0], hits_per_ray[0][1], hits_per_ray[0][2], hits_per_ray[0][3], hits_per_ray[0][4] -index_face = {index: face for index, face in enumerate(mesh.faces())} - intersections = [] for hit in hits_per_ray: point, idx, w, u, v = hit