[vtkusers] picking objects from a subset of a grid

David E DeMarle dave.demarle at kitware.com
Thu Jan 19 16:12:18 EST 2012


On Thu, Jan 19, 2012 at 1:57 PM, Stephen Langer <stephen.langer at nist.gov>wrote:

> Hi David --
>
> Following your suggestion I've been looking at using selections and
> vtkExtractSelectedFrustum, but I'm getting more confused.
>
> Is the selection list that's set by SetSelectionList used for input or
> output?  The examples that I've seen (e.g.,
> http://vtk.org/gitweb?p=VTK.git;a=blob;f=Graphics/Testing/Cxx/TestExtraction.cxx)
> fill the list before calling SetSelectionList.  Is that just simulating a
> selection so that the extraction process can be demonstrated?   Does the
> selection list contain the selected items, or does it contain the set of
> items from which the selection will be made?  Do I need to call
> SetSelectionList at all, since I want vtk to make the selection?
>
>
That is an input.

The key thing you are missing is that selection is general. It should be
called "subset" which is what we are going to call the refactored version
in VTK 6. Use selection's content type to describe what kind of subset you
want, then fill in the selection list with the details of what you want to
extract.

In ParaView style surface selection for instance (which is most similar to
picking) content type = INDICES and the selection list contains the set of
cell/point ids you want to extract. Those have already been determined by
some other mechanism, such as by vtkHardwareSelector which runs a set of
offscreen render passes to determine what cells are behind each pixel. That
itself is demonstrated by some of the other tests and examples.

You are looking for content_type = FRUSTUM, where the selection list
contains instead the coordinates of the bounding box which you want to
extract within. Internally the general vtkExtractSelection selection filter
just calls vtkExtractSelectedFrustum for you.

You might also want to experiment with CONTENT_TYPE = LOCATIONS.



> I still don't understand how to select edges and vertices.  The extracted
> grid contains the tetrahedra from the source grid that intersect the
> frustum, and its Points array contains only the points from those tets, but
> those points are not in the frustum.
>
>
Try changing the selection filter's FIELD_TYPE to
vtkSelection::POINT<http://www.vtk.org/doc/nightly/html/classvtkDataObject.html#a75b13d501194938772601cb0a3385f20ac61140e6fd1ab7f3210477460c0d9aa2>,
and then if you want the tets too use SetContainingCellsOn().

You will have to do edges by traversing the test yourself unfortunately.
VTK doesn't treat faces and edges as first class citizens.


 Here's what I've been trying:
>
>  vtkSmartPointer<vtkSelectionNode> selectionNode =
>    vtkSmartPointer<vtkSelectionNode>::New();
>  selectionNode->Initialize();
>  selectionNode->SetFieldType(vtkSelectionNode::POINT);
>  selectionNode->SetContentType(vtkSelectionNode::INDICES);
>
>  // I don't understand what the next two lines do.  I don't see any change
> in
>  // behavior if I remove them.
>  vtkSmartPointer<vtkIdTypeArray> ids =
> vtkSmartPointer<vtkIdTypeArray>::New();
>  selectionNode->SetSelectionList(ids);
>
>  vtkSmartPointer<vtkSelection> selection =
>    vtkSmartPointer<vtkSelection>::New();
>  selection->AddNode(selectionNode);
>
>  // Using vtkAreaPicker here seems like it must be inefficient, but it's
> easier
>  // than doing the geometry myself, for now.
>  vtkSmartPointer<vtkAreaPicker> picker =
> vtkSmartPointer<vtkAreaPicker>::New();
>  picker->AreaPick(x, y, x+1, y+1, renderer);   // x and y are given screen
> coordinates
>  vtkSmartPointer<vtkPlanes> planes = picker->GetFrustum();
>
>  vtkSmartPointer<vtkExtractSelectedFrustum> extractor =
>    vtkSmartPointer<vtkExtractSelectedFrustum>::New();
>  extractor->SetFrustum(planes);
>  extractor->PreserveTopologyOff();
>  vtkSmartPointer<vtkDataSet> dataset =
> layer->get_pickable_dataset("elements");
>  extractor->SetInputConnection(0, dataset->GetProducerPort());
>  extractor->SetInputConnection(1, selection->GetProducerPort());
>  extractor->Update();
>
>  vtkSmartPointer<vtkUnstructuredGrid> selected =
>    vtkSmartPointer<vtkUnstructuredGrid>::New();
>  selected->ShallowCopy(extractor->GetOutput());
>
> At this point the "selected" grid contains tets that intersect the frustum
> of the screen pixel x,y, even though the selection field type was POINT.
>  What am I missing?
>
>
I am guessing it is because you are doing a mix of using selection and
calling the vtkExtractSelectedFrustum filter yourself. That is likely
changing the settings of the filter after you have set them. Use the filter
on its own (without giving it a selection input) or use the
vtkExtractSelection filter instead.


> I also don't see how this helps to find the point or edge that was clicked
> on, if the user is trying to select a vertex or edge of the grid.
>
>
In paraview we augment the input data with a GLOBAL_IDS array, then when
you look at this array in the extracted dataset, we know what cells were
picked in the input data. You'll have to sort by depth yourself if you only
want the nearest. As I said you'll have to do edges yourself, but the same
trick can help trace it back.


> Thanks again,
>    Steve
>
>
> On Jan 16, 2012, at 11:52 AM, David E DeMarle wrote:
>
> > I suggest using vtkExtractSelectedFrustum instead of picking. See
> > http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Frustum
> > and
> >
> http://vtk.org/gitweb?p=VTK.git;a=blob;f=Rendering/Testing/Cxx/TestAreaSelections.cxx
> > for examples
> >
> > Picking is, with the exception of picking multiple actors, more useful
> for identifying the one thing underneath one pixel.
> >
> > Selection is more useful for picking multiple things (both under
> multiple pixels and deeper underneath them).
> >
> > Note you can select points directly and then turn on a flag to include
> the cells that contain those points. Also note that the filter behind
> FrustumSelection is defined in world space, not screen space and works on
> cells or points directly, so there shouldn't be any need to make cells to
> represent edges or vertices. Lastly note that you can manipulate the
> frustum however you like to be more selective about what is chosen.
> >
> > David E DeMarle
> > Kitware, Inc.
> > R&D Engineer
> > 21 Corporate Drive
> > Clifton Park, NY 12065-8662
> > Phone: 518-881-4909
> >
> >
> > On Fri, Jan 13, 2012 at 4:40 PM, Stephen Langer <stephen.langer at nist.gov>
> wrote:
> > 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
>   --
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
> --
> -- 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
> --
>
>
David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120119/6658edbb/attachment.htm>


More information about the vtkusers mailing list