-
Notifications
You must be signed in to change notification settings - Fork 9
Mesh Projection #48
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
Mesh Projection #48
Conversation
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.
LGTM just a few comments
docs/examples/example_projection.py
Outdated
| from compas_cgal.meshing import mesh_project | ||
|
|
||
|
|
||
| def main(): |
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.
why?
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.
Solved
| // After scaling, use proper AABB tree for projection | ||
| // Define triangle type | ||
| typedef CGAL::Kernel_traits<CGAL::Point_3<compas::Kernel>>::Kernel K; | ||
| typedef CGAL::Triangle_3<K> Triangle; | ||
| typedef std::vector<Triangle>::iterator Iterator; | ||
| typedef CGAL::Ray_3<K> Ray; | ||
|
|
||
| // Build a list of triangles from the mesh | ||
| std::vector<Triangle> triangles; | ||
| for(auto face : mesh_a.faces()) { | ||
| auto halfedge = mesh_a.halfedge(face); | ||
| auto v0 = mesh_a.source(halfedge); | ||
| auto v1 = mesh_a.target(halfedge); | ||
| auto v2 = mesh_a.target(mesh_a.next(halfedge)); | ||
|
|
||
| // Add the triangle | ||
| triangles.push_back(Triangle( | ||
| mesh_a.point(v0), | ||
| mesh_a.point(v1), | ||
| mesh_a.point(v2) | ||
| )); | ||
| } | ||
|
|
||
| // Create the AABB tree | ||
| typedef CGAL::AABB_triangle_primitive_3<K, Iterator> Primitive; | ||
| typedef CGAL::AABB_traits_3<K, Primitive> Traits; | ||
| typedef CGAL::AABB_tree<Traits> Tree; | ||
|
|
||
| Tree tree(triangles.begin(), triangles.end()); | ||
| tree.accelerate_distance_queries(); |
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.
not now, but perhaps we could add this as a helper function somewhere, since we probably need this quite often...
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.
I will make for this a separate pull request, what would be the most common use case?
- Mesh-PointCloud closest-points
- Lines Collection closest-points
- Polyline Colllection closest-points
What else?
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.
- mesh ray intersections
- bvh construction
- closest point
- ...
Mesh projection method using two meshes as a source and a target.
Optionally normals of the source mesh can be used.
Implementation details: