Skip to content

Conversation

@petrasvestartas
Copy link
Collaborator

Mesh projection method using two meshes as a source and a target.
Optionally normals of the source mesh can be used.

Implementation details:

  • AABB tree is built
  • From the tree we find closest points to the target mesh faces
  • If normals are provided, then we perform positive and negative ray intersection

image

Copy link
Member

@tomvanmele tomvanmele left a 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

from compas_cgal.meshing import mesh_project


def main():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved

Comment on lines +77 to +106
// 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();
Copy link
Member

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...

Copy link
Collaborator Author

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?

Copy link
Member

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
  • ...

@petrasvestartas petrasvestartas closed this by deleting the head repository Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants