[vtkusers] picking objects from a subset of a grid

Stephen Langer stephen.langer at nist.gov
Fri Jan 13 16:40:57 EST 2012


Hi --

My program displays a vtkUnstructuredGrid, along with other objects.
I'd like users to be able to pick nodes, edges, faces, and elements of
the grid with mouse clicks.  The interior of the grid needs to be
visible, and sometimes only a subset of the grid is displayed (ie,
only elements meeting some user-specified criterion).  Currently I've
more or less figured out how to click on and select elements and
nodes, but I'm having some difficulties and would greatly appreciate
some advice.

If the vtkUnstructuredGrid contains only 3D (eg, tetrahedral) cells,
then the internal edges aren't drawn in a wire frame representation,
so to display the grid I'm using the vtkExtractEdges filter.  If I
only display the edges, then vtkCellPicker won't pick anything, so I
add a second actor that displays the same grid using an almost
completely transparent surface representation.  Then the picker can
work on the second actor when choosing elements.  In both cases cells
in the grid are created only for the subset that's being displayed.
This works, but it seems inefficient.  Is there a better way?

When picking nodes I'd like to use a vtkPointPicker because then I
don't have to explicitly create vertex cells in the grid. However,
then the picker can pick points that aren't in the displayed subset of
the grid.  How can I restrict the picker so that it only finds points
that are in the displayed tets?  Do I have to make a new vtkPoints
list?  I'd rather not do that for memory reasons.  (I can't use a
vtkCellPicker to pick a tet and then select the closest node of that
tet, because I might be trying to pick a node that's visible through
some number of intervening tets.)

Is it possible to get the vtkPointPicker to return multiple points for
one vtkActor?  If it returned all points within a tolerance of the
ray, then I could choose the closest one that's in the displayed
subset.  vtkPicker.GetPickedPositions returns a set of positions, but
it seems to include just one per vtkActor, and all of my points are in
the same vtkActor.  Is it necessary to create a separate vtkActor for
each point?

I tried creating a separate vtkUnstructuredGrid containing only vertex
cells from the elements in the subset, but vtkCellPicker doesn't seem
to work on vertices.  Is that correct?  Is there a way of picking
cells from a grid that contains only vertices?

In case it matters, I'm not using a vtkRenderWindowInteractor.  I'm
using vtk inside a gtk program.  The vtk render window is redirected
to a gtk drawing area, and the mouse click coordinates are returned
from there.

Thanks for any advice.  I hope my questions aren't too elementary.
I've looked for answers in the kitware books and online without much
success.

  -- Steve

--
-- EMail: stephen.langer at nist.gov                    Phone: (301) 975-5423 --
-- http://math.nist.gov/~SLanger/                      Fax: (301) 975-3553 --
-- Mail: NIST; 100 Bureau Drive -- Stop 8910; Gaithersburg, Md  20899-8910 --

-- "I don't think this will work.  That's why it's science."               --
--                              Naomi Langer (age 6),  17 Feb 2003         --




More information about the vtkusers mailing list