pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

Get Surface Mesh from Boolean Operation between Mesh and Surface #381

Open rhys-e1 opened 3 years ago

rhys-e1 commented 3 years ago

Description

Hi,

I am currently trying to do some Boolean operations between a mesh and a surface: image I would like to return the portion of the surface (as a surface mesh) constrained by the mesh. However, when attempting the Boolean operations in PyVista, I instead get the cut portion of the mesh: image

Using an OpenScad-based engine, I can obtain the desired output: image

I would like to be able to complete the same operation in PyVista, is this possible? How might I go about this? Below is my code to reproduce the above images:

import pyvista as pv 
import numpy as np
import trimesh as tm
import pymeshfix as pf

model_mesh = pv.read('stl/Tensile_Bar_Thick.stl')
model_trimesh = tm.load('stl/Tensile_Bar_Thick.stl')

x = np.arange(-100, 100, 2)
y = np.arange(-100, 100, 2)
x, y = np.meshgrid(x, y)
z = np.sin(0.2 * x) * np.sin(0.25 * y)
points = np.c_[x.reshape(-1), y.reshape(-1), z.reshape(-1)]
point_cloud = pv.PolyData(points)
surf = point_cloud.delaunay_2d()
intersecting_surf = model_mesh.boolean_cut(surf)

surf_trimesh = pf.MeshFix(surf)
surf_trimesh = tm.Trimesh(surf_trimesh.v, surf_trimesh.f)
intersecting_surf_trimesh = tm.boolean.intersection([model_trimesh, surf_trimesh], engine='scad')

intersecting_surf_trimesh.show()
intersecting_surf.plot()
MatthewFlamm commented 3 years ago

Does the resample filter do what you want? https://docs.pyvista.org/examples/01-filter/resample.html

Edit: this is the sample filter, the title of this example had confused me.