[vtkusers] Finding points inside a sphere (using vtkSelectEnclosedPoints)
Christian Jauvin
cjauvin at gmail.com
Sun Jun 26 17:46:59 EDT 2011
Hi,
I am new to VTK. I wrote three days ago about the problem of adding an
observer to intercept mouse interactions with a sphere prop in a point
cloud scene (using Python-VTK). I found a working solution by myself,
and I plan to reply to my message shortly, explaining it, in the hope
that it could be useful to someone (assuming that the approach is not
too flawed).
My new problem is dynamically finding the subset of points lying in
the sphere, and highlight them. Once the point cloud and an initial
sphere are set, it works the first time:
# pts_polydata corresponds to the point cloud data, and sphere_src to
the user-movable sphere
# pts_colors is a vtkUnsignedCharArray of triples, with the same size
as the point cloud
enclosed_pts = vtk.vtkSelectEnclosedPoints()
enclosed_pts.SetInput(pts_polydata)
enclosed_pts.SetSurface(sphere_src.GetOutput())
enclosed_pts.Update()
inside_arr = enclosed_pts.GetOutput().GetPointData().GetArray('SelectedPoints')
for i in range(inside_arr.GetNumberOfTuples()):
if inside_arr.GetComponent(i, 0):
pts_colors.SetTupleValue(i, (0,0,255))
pts_polydata.GetPointData().SetScalars(pts_colors)
As I said this works the first time, but the problem is when I try to
update the whole thing, from the callback function triggered at the
end of a user-driven sphere move (when the state should thus have
changed, reflecting the new position of the sphere, which now encloses
a new subset of points).
My naive assumption was that I could simply reuse that block of code
whenever needed (i.e. in my callback function). I'm not sure however
what exactly I have to Update() or Modified() (the sphere_src, its
actor, the vtkSelectEnclosedPoints filter?) but no matter what I try,
the update does not work, and the filter always contain the same,
initial selection (and moreover, it seems that I cannot update the
point colors using SetScalars, a second time). Is this the right way
to do it?
Thanks again for any help,
Christian
More information about the vtkusers
mailing list