Closed pempmu closed 4 years ago
AFAIK, vtk
doesn't support boolean operations between unstructured grids, only PolyData
. We need to add type checking to provide a better error message.
You might be able to use select_enclosed_points
to subselect a part of the unstructred grid and then extract those points. voxelize
uses this:
def voxelize(mesh, density):
x_min, x_max, y_min, y_max, z_min, z_max = mesh.bounds
x = np.arange(x_min, x_max, density)
y = np.arange(y_min, y_max, density)
z = np.arange(z_min, z_max, density)
x, y, z = np.meshgrid(x, y, z)
# Create unstructured grid from the structured grid
grid = pyvista.StructuredGrid(x, y, z)
ugrid = pyvista.UnstructuredGrid(grid)
# get part of the mesh within the mesh
selection = ugrid.select_enclosed_points(mesh, tolerance=0.0)
mask = selection.point_arrays['SelectedPoints'].view(np.bool)
# extract cells from point indices
return ugrid.extract_points(mask)
Your boolean operations won't be smooth (i.e. the surface of the cut will be quite rough), but it will at least get you started.
@akaszynski thank you for the hints. I will try to figure out some solution for my problem and get back once I am satisfied with the results.
My impression: there's no need for you to use UnstructuredGrid
s. Try switching to PolyData
and using PyVista's Box
helper to create your cutter:
def make_cube():
bounds = [-1.5, 0.4, -1.5, -0.4, -1.5, -0.4]
return pv.Box(bounds).triangulate()
cube = make_cube()
# You're point cloud is only a surface, so extract the bounding surface of the delaunay filter and clean it
volume = point_cloud.delaunay_3d().extract_surface().clean()
# Now you can do the cut
cut = cube - volume
pl = pv.Plotter(notebook=False, shape=(1,2));
pl.add_mesh(volume, show_edges=True, opacity=0.5, color='grey')
pl.add_mesh(cube, color="orange", show_edges=False, opacity=0.5)
pl.add_mesh(cut, color="red")
pl.subplot(0,1)
pl.add_mesh(cut, color="red")
pl.link_views()
pl.show()
Great, this will keep me working on my project. Thank you for the tip @banesullivan
Hi pyvista community,
I have recently come across this great project and I am currently using its capabilities to do some manufacturing related simulations with it. For my purpuse I need to make usage of Boolean Operations, but I have obtained a first error that I am not quite sure how to figure out. Essentially, what I am trying to achieve is perform a Boolean operation between a unstructured grid and structured grid. Here you find the full code to reproduce the issue:
The result of executing this code in a jupyter notebook is shown in the attached picture. The problem apperars when executing the next line of code to perform the boolean:
The following error appears:
Could anyone give me a hint how to interpret this error and find a solution?
Thanks in advance!