简体   繁体   中英

How to get points inside multiple polydata

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.

The surface you created is not a manifold and vtkSelectEnclosedPoints works with manifolds only. Try to use vtkBooleanOperationPolyDataFilter with SetOperationToUnion() instead of vtkAppendPolyData .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM