Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

Boolean result not accurate.

Open wociety opened this issue 2 years ago • 6 comments

Checklist

Describe the issue

I ran a boolean difference on the dog model and a box, and in the result additional meshes are created. Expected output: clean cut (remaining just dog's head and feet) Actual output: big triangle at dog's head and a line at dog's feet

image image image image

Steps to reproduce the bug

import open3d as o3d
import os, copy

# My local path
os.chdir('E:\\OneDrive\\Works_online\\STL')

target = o3d.io.read_triangle_mesh('3Dcube_dog5.stl')
target. Scale(0.5, center=target.get_center())
target2 = o3d.t.geometry.TriangleMesh.from_legacy(target)

box = o3d.geometry.TriangleMesh.create_box()
box. Scale(50, center=box.get_center())
box = copy.deepcopy(box).translate((0, 0, 0.01))
box2 = o3d.t.geometry.TriangleMesh.from_legacy(box)

ans = target2.boolean_difference(box2)

o3d.visualization.draw([{'name': 'difference', 'geometry': ans}])

Error message

No response

Expected behavior

Expected output: clean cut (remaining just dog's head and feet) Actual output: big triangle at dog's head and a line at dog's feet

Open3D, Python and System information

- Operating system: Windows 11 64-bit
- Python version: Python 3.10.10
- Open3D version: 0.16.0
- System architecture: x86 / intel i7
- Is this a remote workstation?: no
- How did you install Open3D?: pip

Additional information

I attach my 3d dog model. 3Dcube_dog5.zip

wociety avatar Feb 16 '23 08:02 wociety

Hi, I would like to work on this bug. it would be great could you please assign this issue to me

jhunjhunwala1234 avatar Feb 19 '23 14:02 jhunjhunwala1234

@jhunjhunwala1234 please let me know how you want to approach this issue

benjaminum avatar Feb 20 '23 10:02 benjaminum

I found my dog was not manifold. So I attach new one. However, when I apply the new file, the boolean result still results in lines that should not be there.

3Dcube_dog11.zip

wociety avatar Mar 01 '23 00:03 wociety

import open3d as o3d
import os, copy

#My local path
os.chdir('E:\\OneDrive\\Works_online\\STL')

target = o3d.io.read_triangle_mesh('3Dcube_dog11.stl')
target.scale(10, center=target.get_center())
target = o3d.t.geometry.TriangleMesh.from_legacy(target)

box = o3d.geometry.TriangleMesh.create_box()
box.scale(35, center=box.get_center())
box. Translate([0, 20, 0])
box = o3d.t.geometry.TriangleMesh.from_legacy(box)

ans = target.boolean_difference(box)

o3d.visualization.draw([{'name': 'difference', 'geometry': ans}])

image

wociety avatar Mar 01 '23 01:03 wociety

Hi, I am seeing a similar issue on a Mac. In case it helps, here is the simple repro:

This code is from the o3d online docs for boolean_difference (I just added the line to compute normals): http://www.open3d.org/docs/release/python_api/open3d.t.geometry.TriangleMesh.html

box = o3d.geometry.TriangleMesh.create_box()
box = o3d.t.geometry.TriangleMesh.from_legacy(box)
sphere = o3d.geometry.TriangleMesh.create_sphere(0.8)
sphere = o3d.t.geometry.TriangleMesh.from_legacy(sphere)

ans = box.boolean_difference(sphere)
ans.compute_vertex_normals()
o3d.visualization.draw([{'name': 'difference', 'geometry': ans}])

The output looks ok, but is actually not watertight: Screen Shot 2023-11-04 at 2 25 23 PM

Screen Shot 2023-11-04 at 2 26 19 PM

Changing the sphere's radius from 0.8 to 0.7 makes the problem more obvious:

box = o3d.geometry.TriangleMesh.create_box()
box = o3d.t.geometry.TriangleMesh.from_legacy(box)
sphere = o3d.geometry.TriangleMesh.create_sphere(0.7)  # 0.8 -> 0.7
sphere = o3d.t.geometry.TriangleMesh.from_legacy(sphere)

ans = box.boolean_difference(sphere)
ans.compute_vertex_normals()
o3d.visualization.draw([{'name': 'difference', 'geometry': ans}])
Screen Shot 2023-11-04 at 2 27 32 PM

I'm running this on

  • Operating system: Mac OS Monterey 12.6
  • Python version: Python 3.10.13
  • Open3D version: 0.17.0
  • System architecture: Apple M1 Max chip (ARM)
  • Is this a remote workstation?: no
  • How did you install Open3D?: pip3 install open3d

daniloscepanovic avatar Nov 04 '23 18:11 daniloscepanovic

hi,

I have the same issues on WSL2 and observe that boolean_union gives incorrect results also. Here is a minimal example, taking the union of a box with a clone of itself:

box = o3d.geometry.TriangleMesh.create_box()
tbox = o3d.t.geometry.TriangleMesh.from_legacy(box)
union = tbox.boolean_union(tbox.clone())

The expected union result is another identical box, but instead it gives an empty mesh:

>>> print(union)
TriangleMesh on CPU:0 [0 vertices (Float32) and 0 triangles (Int64)].
Vertex Attributes: PointSource (dtype = Int32, shape = {0, 1}), Distance (dtype = Float64, shape = {0, 1}).
Triangle Attributes: FreeEdge (dtype = Int32, shape = {0, 1}), CellSource (dtype = Int32, shape = {0, 1}), Distance (dtype = Float64, shape = {0, 1}), BadTriangle (dtype = Int32, shape = {0, 1}).

System info:

  • Operating system: Ubuntu on WSL2
  • Python version: Python 3.10.12
  • Open3D version: 0.18.0
  • System architecture: x86/i9
  • Is this a remote workstation?: no
  • How did you install Open3D?: pip

drievuldig avatar Feb 16 '24 17:02 drievuldig