Reputation: 97331
I use vtkAppendPolyData
to merge multiple polydata into one polydata, and vtkSelectEnclosedPoints
to get points inside the polydata.
Here is the python code using tvtk.api
:
from tvtk.api import tvtk
# create some random points
points = np.random.randn(9999, 3)
pd_points = tvtk.PolyData()
pd_points.points = points
pd_points.verts = np.arange(len(points)).reshape(-1, 1)
# create two polydata
cube1 = tvtk.CubeSource()
cube1.update()
cube2 = tvtk.CubeSource()
cube2.center = (0.5, 0, 0)
cube2.update()
# merge the two polydata into one:
append = tvtk.AppendPolyData()
append.add_input_data(cube1.output)
append.add_input_data(cube2.output)
append.update()
# select points inside polydata
sep = tvtk.SelectEnclosedPoints()
sep.set_input_data(pd_points)
sep.set_surface_data(append.output)
sep.update()
# remove outside points
tp = tvtk.ThresholdPoints()
tp.threshold_by_upper(0.5)
tp.set_input_data(sep.output)
tp.update()
res = tp.output
res.point_data.remove_array(0)
the result looks like:
as you can see, the points inside both the polydata are not included.
I don't want to use a for loop, because I have alot of polydata to clip the data.
Upvotes: 1
Views: 818
Reputation: 695
The surface you created is not a manifold and vtkSelectEnclosedPoints
works with manifolds only.
Try to use vtkBooleanOperationPolyDataFilter
with SetOperationToUnion()
instead of vtkAppendPolyData
.
Upvotes: 1