-
Notifications
You must be signed in to change notification settings - Fork 2
Implicit function clipping #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lachlangrose
commented
Nov 4, 2025
- Add option to clip surface with implicit function.
- Also change predicate for clipping to exact kernel to avoid infinite hangs
this is interpreted as a signed distance function and could be evaluated on the triangle nodes from an implicit function. Note if the surface is remeshed the property values will need to be re-evaluated on the new nodes.
…p3D/loop-cgal into fix/adding-implicit-function-cutting
Set VCPKG_ROOT environment variable for package build.
…ging ci: change name of tester to testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds several significant features to the loop_cgal library:
- Implements
cut_with_implicit_functionto cut meshes based on vertex properties - Adds exact kernel support for improved numerical robustness in mesh operations
- Introduces comprehensive test coverage for mesh operations
- Refactors validation logic into separate utils module
Reviewed Changes
Copilot reviewed 14 out of 17 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| src/mesh.cpp | Adds cut_with_implicit_function implementation and exact kernel support for cutWithSurface |
| src/mesh.h | Declares new methods and exact kernel types |
| src/meshutils.cpp | Implements conversion functions between exact and double precision meshes |
| src/meshutils.h | Declares mesh conversion functions |
| src/meshenums.h | Defines ImplicitCutMode enum for cut operations |
| loop_cgal/init.py | Refactors validation logic and adds new helper methods |
| loop_cgal/utils.py | Extracts validation functions into separate module |
| loop_cgal/bindings.cpp | Exposes new C++ functionality to Python |
| tests/test_mesh_operations.py | Adds comprehensive test suite for mesh operations |
| tests/test_degenerate.py | Refactors degenerate mesh tests into proper pytest format |
| pyproject.toml | Adds vtk dependency and test optional dependencies |
| CMakeLists.txt | Updates build configuration for cross-platform support |
| .github/workflows/ci.yml | Adds CI workflow for automated testing |
| examples/*.py | Adds example scripts demonstrating new features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/meshutils.h
Outdated
| const std::array<double, 3> &v3); | ||
| Exact_Mesh convert_to_exact(const TriMesh& input); | ||
| TriangleMesh convert_to_double_mesh(const Exact_Mesh& input); | ||
|
|
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace on line 13 should be removed to maintain consistent code formatting.
src/mesh.cpp
Outdated
| bool preserve_intersection_clipper, | ||
| bool use_exact_kernel) | ||
| { | ||
|
|
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace on line 297 should be removed to maintain consistent code formatting.
loop_cgal/__init__.py
Outdated
| degen_idx = np.where(m.sum(axis=0) != 3)[1] | ||
| raise ValueError(f"Surface contains degenerate triangles: {degen_idx} (each triangle must have exactly 3 vertices)") | ||
|
|
||
| if (not validate_vertices_and_faces(verts, faces)): |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary parentheses around the boolean expression. Python style guides recommend removing them unless needed for line continuation or grouping.
| if (not validate_vertices_and_faces(verts, faces)): | |
| if not validate_vertices_and_faces(verts, faces): |
loop_cgal/__init__.py
Outdated
| The created TriMesh object. | ||
| """ | ||
| # Create a temporary PyVista PolyData object for validation | ||
| if (not validate_vertices_and_faces(vertices, triangles)): |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Unnecessary parentheses around the boolean expression. Python style guides recommend removing them unless needed for line continuation or grouping.
| if (not validate_vertices_and_faces(vertices, triangles)): | |
| if not validate_vertices_and_faces(vertices, triangles): |
pyproject.toml
Outdated
| optional-dependencies = { test = ['pytest'] } | ||
|
|
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TOML syntax for optional-dependencies should use nested table format for better compatibility with TOML parsers. Should be: [project.optional-dependencies]\ntest = ['pytest']
| optional-dependencies = { test = ['pytest'] } | |
| [project.optional-dependencies] | |
| test = ['pytest'] |
loop_cgal/utils.py
Outdated
| def validate_vertices_and_faces(verts, faces) -> bool: | ||
| """Validate vertices and faces arrays. | ||
| Parameters | ||
| ---------- | ||
| verts : np.ndarray | ||
| An array of shape (n_vertices, 3) containing the vertex coordinates. | ||
| faces : np.ndarray | ||
| An array of shape (n_faces, 3) containing the triangle vertex indices. | ||
| Returns | ||
| ------- | ||
| bool | ||
| True if valid, False otherwise. |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function's return type annotation claims it returns bool, but the function actually raises ValueError on validation failures and only returns True on success. The docstring correctly documents that it raises ValueError, so the return type should be either removed or the function should be refactored to return bool consistently.
| def validate_vertices_and_faces(verts, faces) -> bool: | |
| """Validate vertices and faces arrays. | |
| Parameters | |
| ---------- | |
| verts : np.ndarray | |
| An array of shape (n_vertices, 3) containing the vertex coordinates. | |
| faces : np.ndarray | |
| An array of shape (n_faces, 3) containing the triangle vertex indices. | |
| Returns | |
| ------- | |
| bool | |
| True if valid, False otherwise. | |
| def validate_vertices_and_faces(verts, faces): | |
| """Validate vertices and faces arrays. | |
| Parameters | |
| ---------- | |
| verts : np.ndarray | |
| An array of shape (n_vertices, 3) containing the vertex coordinates. | |
| faces : np.ndarray | |
| An array of shape (n_faces, 3) containing the triangle vertex indices. |
tests/test_mesh_operations.py
Outdated
|
|
||
|
|
||
|
|
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace on line 13 should be removed to maintain consistent code formatting.
.github/workflows/ci.yml
Outdated
| - if: matrix.os == 'ubuntu-latest' | ||
| run: | | ||
| sudo apt-get install -y libgl1-mesa-dev libeigen3-dev libcgal-dev | ||
| - if: matrix.os == 'macos-latest' || matrix.os == 'macos-14' |
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub Actions conditional expressions should use proper YAML syntax. The condition should be: if: matrix.os == 'macos-latest' || matrix.os == 'macos-14' (wrapped in quotes if needed), or better yet, use: if: startsWith(matrix.os, 'macos')
| - if: matrix.os == 'macos-latest' || matrix.os == 'macos-14' | |
| - if: ${{ startsWith(matrix.os, 'macos') }} |
examples/cut_example.py
Outdated
| @@ -0,0 +1,36 @@ | |||
| import numpy as np | |||
| import pyvista as pv | |||
Copilot
AI
Nov 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'pv' is not used.
| import pyvista as pv |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@lachlangrose I've opened a new pull request, #17, to work on those changes. Once the pull request is ready, I'll request review from you. |
* Initial plan * Address code review comments Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com>