pyvista: Incorrect result of boolean_difference

Describe the bug, what’s wrong, and what you expected.

Hello, I’ve encountered a bug, Incorrect result of boolean_difference as the following code

Steps to reproduce the bug.

import pyvista as pv

cube1 = pv.Cube(x_length=1.1, y_length=10, z_length=10)
cube1 = cube1.triangulate()
cube2 = pv.Cube(x_length=1, y_length=18, z_length=27)
cube2 = cube2.triangulate()
out_mesh = cube2 - cube1
plotter = pv.Plotter()
plotter.add_mesh(out_mesh, color='white')
plotter.show()

System Information

--------------------------------------------------------------------------------
  Date: Mon Sep 04 17:39:21 2023 

                OS : Windows
            CPU(s) : 64
           Machine : AMD64
      Architecture : 64bit
       Environment : Python
        GPU Vendor : NVIDIA Corporation
      GPU Renderer : NVIDIA GeForce RTX 3080/PCIe/SSE2
       GPU Version : 4.5.0 NVIDIA 516.94
  MathText Support : False

  Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64
  bit (AMD64)]

           pyvista : 0.41.1
               vtk : 9.2.6
             numpy : 1.25.2
        matplotlib : 3.7.2
            scooby : 0.7.2
             pooch : v1.7.0
             PyQt5 : 5.15.9
             scipy : 1.11.1
--------------------------------------------------------------------------------

Screenshots

image

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Comments: 16 (14 by maintainers)

Most upvoted comments

@Arnav-2004 Good catch. Would you mind use it to this problem?

I am preoccupied with prior commitments, I will update you in 2 to 3 days.

This has been posted on the forum here.

Reproducing the above bug using vtk:

import vtk

cube1 = vtk.vtkCubeSource()
cube1.SetXLength(1.1)
cube1.SetYLength(10)
cube1.SetZLength(10)
cube1.Update()

tri_filter1 = vtk.vtkTriangleFilter()
tri_filter1.SetInputData(cube1.GetOutput())
tri_filter1.Update()

cube2 = vtk.vtkCubeSource()
cube2.SetXLength(1)
cube2.SetYLength(18)
cube2.SetZLength(27)
cube2.Update()

tri_filter2 = vtk.vtkTriangleFilter()
tri_filter2.SetInputData(cube2.GetOutput())
tri_filter2.Update()

boolean_operation = vtk.vtkBooleanOperationPolyDataFilter()
boolean_operation.SetOperationToDifference()
boolean_operation.SetInputConnection(0, tri_filter2.GetOutputPort())
boolean_operation.SetInputConnection(1, tri_filter1.GetOutputPort())
boolean_operation.Update()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(boolean_operation.GetOutput())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

ren = vtk.vtkRenderer()
ren_win = vtk.vtkRenderWindow()
ren_win.AddRenderer(ren)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(ren_win)

ren.AddActor(actor)
ren.SetBackground(1.0, 1.0, 1.0)

ren_win.Render()
iren.Start()

image

@Arnav-2004 No. But we need to reproduce it using vtk to report vtk project. But I don’t have time to do that…

Got it, I will do it.

This seems to be an issue with vtk itself, I tried to reproduce the same code with vtk and it is similar.

Yes, we have not been able to determine the cause of this problem. First, we need to isolate whether it is a PyVista or vtk issue. If it is a vtk issue, we will reproduce this in the vtk code and report to the vtk project.

@tkoyama010,Thank you very much!!! But this is indeed a bug, will it be fixed in the future? Maybe some one just want to do boolean operations on two cubes with 8 vertices, and don’t want to complicate the graphic, although he can use decimate to simplify it after boolean operations .