Skip to content
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

fix alpha shape reconstruction if alpha too small for point scale #6998

Merged
merged 2 commits into from
Oct 13, 2024

Conversation

rxba
Copy link
Contributor

@rxba rxba commented Oct 4, 2024

Type

Motivation and Context

Surface reconstruction with alpha shapes by calling create_from_point_cloud_alpha_shape fails if the alpha value is too small for the internal constraint to become true.

double r = std::sqrt(dx * dx + dy * dy + dz * dz - 4 * a * c) /
(2 * std::abs(a));
if (r <= alpha) {
mesh->triangles_.push_back(TriangleMesh::GetOrderedTriangle(
tetra(0), tetra(1), tetra(2)));

There is currently no check if the reconstructed mesh is empty, thus the following call to

auto tmesh2 = t::geometry::vtkutils::ComputeNormals(
tmesh, /*vertex_normals=*/true, /*face_normals=*/false,
/*consistency=*/true, /*auto_orient_normals=*/true,
/*splitting=*/false);

leads to a non-descriptive unordered_map key error.

To reproduce, an easy test is to attempt surface reconstruction with the Bunny and the Armadillo Mesh.
While the bunny mesh works fine with the tutorial alpha shape values (e.g. 0.03), the Armadillo mesh fails.
This is a point scale issue, i.e. max_bound (Armadillo) is [62.1 96.4 56.8] and max_bound (Bunny) is [0.061 0.187 0.058]. If the alpha is large enough (e.g. 10), or the points are scaled down, it works again for the Armadillo.

To reproduce the error:

bunny = o3d.data.BunnyMesh()
arma = o3d.data.ArmadilloMesh()
for m in [bunny, arma]:
    mesh = o3d.io.read_triangle_mesh(m.path)
    pcd = mesh.sample_points_poisson_disk(300)
    alpha = 0.03
    mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape(pcd, alpha)
    mesh.compute_vertex_normals()
    o3d.visualization.draw_geometries([mesh], mesh_show_back_face=True)

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

To prevent the error, I've added a check if the mesh is empty after the alpha shape reconstruction is completed. If it is empty, a warning is logged and the empty mesh gets returned.

Copy link

update-docs bot commented Oct 4, 2024

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@ssheorey ssheorey self-requested a review October 9, 2024 15:55
Copy link
Member

@ssheorey ssheorey left a comment

Choose a reason for hiding this comment

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

Thanks @rxba looks good!

@ssheorey ssheorey merged commit 1a98853 into isl-org:main Oct 13, 2024
35 of 39 checks passed
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.

Unable to perform alpha surface reconstruction on Apple Silicon
2 participants