Open3D
Open3D copied to clipboard
Open3D crashes when using boolean_intersection with non-overlapping meshes
Checklist
- [X] I have searched for similar issues.
- [X] For Python issues, I have tested with the latest development wheel.
- [X] I have checked the release documentation and the latest documentation (for
masterbranch).
Describe the issue
I want to compute the intersection between two TriangleMesh with boolean_intersection. I assume that the result would be a TriangleMesh with zero or more vertices.
However, when there is no overlap between the two meshes, Open3D crashes with the error message below.
Steps to reproduce the bug
import open3d as o3d
mesh1 = o3d.t.geometry.TriangleMesh.create_sphere(radius=1.0,resolution=20)
mesh1.translate([0,0,2])
mesh2 = o3d.t.geometry.TriangleMesh.create_sphere(radius=1.0,resolution=20)
mesh2.translate([0,0,-2])
intersection = mesh1.boolean_intersection(mesh2)
Error message
ERROR: In /home/runner/work/Open3D/Open3D/build/vtk/src/ext_vtk/Common/DataModel/vtkPointLocator.cxx, line 845
vtkPointLocator (0x21d1800): No points to subdivide
Generic Warning: In /home/runner/work/Open3D/Open3D/build/vtk/src/ext_vtk/Filters/General/vtkIntersectionPolyDataFilter.cxx, line 2410
No Intersection between objects
ERROR: In /home/runner/work/Open3D/Open3D/build/vtk/src/ext_vtk/Filters/General/vtkDistancePolyDataFilter.cxx, line 81
vtkDistancePolyDataFilter (0x2a2ee50): No points/cells to operate on
ERROR: In /home/runner/work/Open3D/Open3D/build/vtk/src/ext_vtk/Filters/General/vtkDistancePolyDataFilter.cxx, line 81
vtkDistancePolyDataFilter (0x2a2ee50): No points/cells to operate on
Expected behavior
The result of an intersection between two distant meshes should return a an empty set of points but should not crash.
Open3D, Python and System information
- Operating system: Ubuntu 20.04
- Python version: Python 3.8.10
- Open3D version: 0.16.0
- System architecture: x86_64
- Is this a remote workstation?: no
- How did you install Open3D?: pip
Additional information
No response
Does it really crash or just print those error messages? I get
print(intersection)
TriangleMesh on CPU:0 [0 vertices (Float32) and 0 triangles (Int64)].
Vertex Attributes: PointSource (dtype = Int32, shape = {0, 1}).
Triangle Attributes: CellSource (dtype = Int32, shape = {0, 1}).
You are right! My mistake, I failed to properly isolate the problem with the code above. The (slightly more complicated) code below should allow you to reproduce the problem:
import open3d as o3d
import copy
import numpy as np
import open3d as o3d
#Spawn two knots, with one translated in the z direction
knot_mesh = o3d.data.KnotMesh()
mesh1 = o3d.io.read_triangle_mesh(knot_mesh.path)
mesh1 = o3d.t.geometry.TriangleMesh.from_legacy(mesh1)
mesh1.translate([0,0,100])
knot_mesh = o3d.data.KnotMesh()
mesh2 = o3d.io.read_triangle_mesh(knot_mesh.path)
mesh2 = o3d.t.geometry.TriangleMesh.from_legacy(mesh2)
#Generate a number of connected components
intersection = mesh1.boolean_intersection(mesh2)
intersection = intersection.to_legacy()
#Find connected components
cluster_idx_per_tri, nb_tri_per_cluster, area_per_cluster = intersection.cluster_connected_triangles()
#Generate a convex hull for each connected component
meshes = []
for i in range(len(nb_tri_per_cluster)):
mesh = copy.deepcopy(intersection)
#Remove all triangles that are not part of the connected component
mesh.remove_triangles_by_mask(np.array(cluster_idx_per_tri) != i)
#Remove any points that are not part of any triangle
mesh.remove_unreferenced_vertices()
#Compute convex hull
if len(mesh.vertices) > 3:
hull_mesh,_ = mesh.compute_convex_hull()
meshes.append(hull_mesh)
#Compute intersections between meshes
intersections = []
for i in range(len(meshes)):
m1 = o3d.t.geometry.TriangleMesh.from_legacy(meshes[i])
for j in range(i+1, len(meshes)):
m2 = o3d.t.geometry.TriangleMesh.from_legacy(meshes[j])
intersections.append(m1.boolean_intersection(m2))
print("This point is not reached.")
Hopefully I have provided the right code this time.
Yes, this either crashes or hangs forever. @PhilNad do you observe the method hanging too or does it always crash?
In my experience, it always crashed.
Is there an example with c++ using BooleanIntesection method?
yes, the same question but not crash, just jump out a vtkOutputWindow with some error messages like @PhilNad mention