[vtkusers] Calculating selection data using python wrappers

Eric E. Monson emonson at cs.duke.edu
Tue Jul 6 13:48:04 EDT 2010


Hey Jeff,

Maybe I'm misunderstanding your explanation, but I think another part of the problem he's facing is that with the Python wrappers you don't get the callback data that's passed when doing a callback in C++. 

Ross, I think you'll have to access the vtkAnnotationLink associated with the representation (rep.GetAnnotationLink() or create and set one explicitly). You can still use the SelectionChangedEvent, or you can add an observer to the annotation link for AnnotationChangedEvent. Then, you should be able to do:

link.GetCurrentSelection() to get the selection, or
link.GetCurrentSelection().GetNode(0).GetSelectionList() in your callback to get the selected IDs (or whatever the ContentType is).

[vtksource]/Examples/Infovis/Python/selection.py (and a couple others in that directory) shows how you can use these annotation links to link selections between views, but you can also inspect the selections as I've mentioned above.

Jeff can step in again if I've misspoken on any of this.
-Eric

------------------------------------------------------
Eric E Monson
Duke Visualization Technology Group


On Jul 6, 2010, at 9:44 AM, Jeff Baumes wrote:

> In general, a view can have multiple data sources (representations), and it is the representations that emit SelectionChangedEvent with a vtkSelection attached. vtkView and subclasses only forward these SelectionChangedEvents with no attached selection. So you can do the following:
> 
> vtkGraphLayoutView* view = vtkGraphLayoutView::New();
> vtkDataRepresentation* rep = view->AddRepresentationFromInput(graph);
> rep->AddObserver(vtkCommand::SelectionChangedEvent, your_callback);
> 
> In your_callback, cast the third argument (the void*) to a vtkSelection*.
> 
> Jeff
> 
> On Tue, Jul 6, 2010 at 12:55 AM, ross hennessy <roscoh at gmail.com> wrote:
> Hi,
> 
> I'm using vtk 5.6 with python, and I have a question about how I
> should achieve something which I can't find examples for. I have a
> vtkGraphLayoutView which I've registered a callback to for the
> SelectionChangedEvent. This is working in the sense that I've checked
> that it gets called when interacting with the window. However when I
> go to provide an implementation for this function I would like to
> calculate/retrieve the selected data (verticies or edges) which have
> been selected. This is obviously being calculated in the pipeline as
> the selected data is colored differently. However I can't seem to find
> the correct method to achieve this. Can somebody please help me out
> with the general method of doing this?
> 
> Thanks, Ross
> _______________________________________________
> 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
> 
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100706/dc6e5b4e/attachment.htm>


More information about the vtkusers mailing list