<br clear="all">On Thu, Jan 19, 2012 at 1:57 PM, Stephen Langer <span dir="ltr"><<a href="mailto:stephen.langer@nist.gov">stephen.langer@nist.gov</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi David --<br>
<br>
Following your suggestion I've been looking at using selections and vtkExtractSelectedFrustum, but I'm getting more confused.<br>
<br>
Is the selection list that's set by SetSelectionList used for input or output? The examples that I've seen (e.g., <a href="http://vtk.org/gitweb?p=VTK.git;a=blob;f=Graphics/Testing/Cxx/TestExtraction.cxx" target="_blank">http://vtk.org/gitweb?p=VTK.git;a=blob;f=Graphics/Testing/Cxx/TestExtraction.cxx</a>) 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?<br>
<br></blockquote><div><br></div><div>That is an input. </div><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>You might also want to experiment with CONTENT_TYPE = LOCATIONS.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br></blockquote><div><br></div><div>Try changing the selection filter's FIELD_TYPE to <span class="Apple-style-span" style="font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:13px;line-height:16px"><a class="el" href="http://www.vtk.org/doc/nightly/html/classvtkDataObject.html#a75b13d501194938772601cb0a3385f20ac61140e6fd1ab7f3210477460c0d9aa2" style="color:rgb(61,87,140);font-weight:bold;text-decoration:none">vtkSelection::POINT</a>, and then if you want the tets too use SetContainingCellsOn().</span></div>
<div><span class="Apple-style-span" style="font-family:'Lucida Grande',Verdana,Geneva,Arial,sans-serif;font-size:13px;line-height:16px"><br></span></div><div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="line-height:16px">You will have to do edges by traversing the test yourself unfortunately. VTK doesn't treat faces and edges as first class citizens.</span></font></div>
<div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="line-height:16px"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande', Verdana, Geneva, Arial, sans-serif"><span class="Apple-style-span" style="line-height:16px"><br>
</span></font></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Here's what I've been trying:<br>
<br>
vtkSmartPointer<vtkSelectionNode> selectionNode =<br>
vtkSmartPointer<vtkSelectionNode>::New();<br>
selectionNode->Initialize();<br>
selectionNode->SetFieldType(vtkSelectionNode::POINT);<br>
selectionNode->SetContentType(vtkSelectionNode::INDICES);<br>
<br>
// I don't understand what the next two lines do. I don't see any change in<br>
// behavior if I remove them.<br>
vtkSmartPointer<vtkIdTypeArray> ids = vtkSmartPointer<vtkIdTypeArray>::New();<br>
selectionNode->SetSelectionList(ids);<br>
<br>
vtkSmartPointer<vtkSelection> selection =<br>
vtkSmartPointer<vtkSelection>::New();<br>
selection->AddNode(selectionNode);<br>
<br>
// Using vtkAreaPicker here seems like it must be inefficient, but it's easier<br>
// than doing the geometry myself, for now.<br>
vtkSmartPointer<vtkAreaPicker> picker = vtkSmartPointer<vtkAreaPicker>::New();<br>
picker->AreaPick(x, y, x+1, y+1, renderer); // x and y are given screen coordinates<br>
vtkSmartPointer<vtkPlanes> planes = picker->GetFrustum();<br>
<br>
vtkSmartPointer<vtkExtractSelectedFrustum> extractor =<br>
vtkSmartPointer<vtkExtractSelectedFrustum>::New();<br>
extractor->SetFrustum(planes);<br>
extractor->PreserveTopologyOff();<br>
vtkSmartPointer<vtkDataSet> dataset = layer->get_pickable_dataset("elements");<br>
extractor->SetInputConnection(0, dataset->GetProducerPort());<br>
extractor->SetInputConnection(1, selection->GetProducerPort());<br>
extractor->Update();<br>
<br>
vtkSmartPointer<vtkUnstructuredGrid> selected =<br>
vtkSmartPointer<vtkUnstructuredGrid>::New();<br>
selected->ShallowCopy(extractor->GetOutput());<br>
<br>
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?<br>
<br></blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br></blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks again,<br>
<div class="im HOEnZb"> Steve<br>
<br>
<br>
On Jan 16, 2012, at 11:52 AM, David E DeMarle wrote:<br>
<br>
</div><div class="HOEnZb"><div class="h5">> I suggest using vtkExtractSelectedFrustum instead of picking. See<br>
> <a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Frustum" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Frustum</a><br>
> and<br>
> <a href="http://vtk.org/gitweb?p=VTK.git;a=blob;f=Rendering/Testing/Cxx/TestAreaSelections.cxx" target="_blank">http://vtk.org/gitweb?p=VTK.git;a=blob;f=Rendering/Testing/Cxx/TestAreaSelections.cxx</a><br>
> for examples<br>
><br>
> Picking is, with the exception of picking multiple actors, more useful for identifying the one thing underneath one pixel.<br>
><br>
> Selection is more useful for picking multiple things (both under multiple pixels and deeper underneath them).<br>
><br>
> 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.<br>
><br>
> David E DeMarle<br>
> Kitware, Inc.<br>
> R&D Engineer<br>
> 21 Corporate Drive<br>
> Clifton Park, NY 12065-8662<br>
> Phone: <a href="tel:518-881-4909" value="+15188814909">518-881-4909</a><br>
><br>
><br>
> On Fri, Jan 13, 2012 at 4:40 PM, Stephen Langer <<a href="mailto:stephen.langer@nist.gov">stephen.langer@nist.gov</a>> wrote:<br>
> Hi --<br>
><br>
> My program displays a vtkUnstructuredGrid, along with other objects.<br>
> I'd like users to be able to pick nodes, edges, faces, and elements of<br>
> the grid with mouse clicks. The interior of the grid needs to be<br>
> visible, and sometimes only a subset of the grid is displayed (ie,<br>
> only elements meeting some user-specified criterion). Currently I've<br>
> more or less figured out how to click on and select elements and<br>
> nodes, but I'm having some difficulties and would greatly appreciate<br>
> some advice.<br>
><br>
> If the vtkUnstructuredGrid contains only 3D (eg, tetrahedral) cells,<br>
> then the internal edges aren't drawn in a wire frame representation,<br>
> so to display the grid I'm using the vtkExtractEdges filter. If I<br>
> only display the edges, then vtkCellPicker won't pick anything, so I<br>
> add a second actor that displays the same grid using an almost<br>
> completely transparent surface representation. Then the picker can<br>
> work on the second actor when choosing elements. In both cases cells<br>
> in the grid are created only for the subset that's being displayed.<br>
> This works, but it seems inefficient. Is there a better way?<br>
><br>
> When picking nodes I'd like to use a vtkPointPicker because then I<br>
> don't have to explicitly create vertex cells in the grid. However,<br>
> then the picker can pick points that aren't in the displayed subset of<br>
> the grid. How can I restrict the picker so that it only finds points<br>
> that are in the displayed tets? Do I have to make a new vtkPoints<br>
> list? I'd rather not do that for memory reasons. (I can't use a<br>
> vtkCellPicker to pick a tet and then select the closest node of that<br>
> tet, because I might be trying to pick a node that's visible through<br>
> some number of intervening tets.)<br>
><br>
> Is it possible to get the vtkPointPicker to return multiple points for<br>
> one vtkActor? If it returned all points within a tolerance of the<br>
> ray, then I could choose the closest one that's in the displayed<br>
> subset. vtkPicker.GetPickedPositions returns a set of positions, but<br>
> it seems to include just one per vtkActor, and all of my points are in<br>
> the same vtkActor. Is it necessary to create a separate vtkActor for<br>
> each point?<br>
><br>
> I tried creating a separate vtkUnstructuredGrid containing only vertex<br>
> cells from the elements in the subset, but vtkCellPicker doesn't seem<br>
> to work on vertices. Is that correct? Is there a way of picking<br>
> cells from a grid that contains only vertices?<br>
><br>
> In case it matters, I'm not using a vtkRenderWindowInteractor. I'm<br>
> using vtk inside a gtk program. The vtk render window is redirected<br>
> to a gtk drawing area, and the mouse click coordinates are returned<br>
> from there.<br>
><br>
> Thanks for any advice. I hope my questions aren't too elementary.<br>
> I've looked for answers in the kitware books and online without much<br>
> success.<br>
><br>
> -- Steve<br>
><br>
> --<br>
> -- EMail: <a href="mailto:stephen.langer@nist.gov">stephen.langer@nist.gov</a> Phone: <a href="tel:%28301%29%20975-5423" value="+13019755423">(301) 975-5423</a> --<br>
> -- <a href="http://math.nist.gov/~SLanger/" target="_blank">http://math.nist.gov/~SLanger/</a> Fax: <a href="tel:%28301%29%20975-3553" value="+13019753553">(301) 975-3553</a> --<br>
> -- Mail: NIST; 100 Bureau Drive -- Stop 8910; Gaithersburg, Md 20899-8910 --<br>
><br>
> -- "I don't think this will work. That's why it's science." --<br>
> -- Naomi Langer (age 6), 17 Feb 2003 --<br>
><br>
> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
<br>
--<br>
-- EMail: <a href="mailto:stephen.langer@nist.gov">stephen.langer@nist.gov</a> Phone: <a href="tel:%28301%29%20975-5423" value="+13019755423">(301) 975-5423</a> --<br>
-- <a href="http://math.nist.gov/~SLanger/" target="_blank">http://math.nist.gov/~SLanger/</a> Fax: <a href="tel:%28301%29%20975-3553" value="+13019753553">(301) 975-3553</a> --<br>
-- Mail: NIST; 100 Bureau Drive -- Stop 8910; Gaithersburg, Md 20899-8910 --<br>
<br>
-- "I don't think this will work. That's why it's science." --<br>
-- Naomi Langer (age 6), 17 Feb 2003 --<br>
<br></div></div></blockquote><div><br></div>David E DeMarle<br>Kitware, Inc.<br>R&D Engineer<br>21 Corporate Drive<br>Clifton Park, NY 12065-8662<br>Phone: 518-881-4909<br><div> </div></div><br>