[vtkusers] A way to pick IDs from actors

Curtis Lisle clisle at sgi.com
Wed May 5 22:48:18 EDT 2004


Several of us seem to need to pick an actor from a scene and get the "ID"
back from the actor to correlate with data external to VTK structures.  I've
encountered this same problem and was able to work around it without having
to extend the VTK classes.  Here is the scheme with a few Tcl code snippets
included:

step 1: get the geometry you want to render, say it is the output of a
filter called myData.

step 2: execute myData->Update() to force the filter to execute and generate
output

step 3: Store an ID value in a new vtkIntArray instance:
		  vtkIntArray myIDarray
		  myIDarray InsertNextValue <add your ID value here>

step 4: Attach the vtkIntArray containing the ID to the geometry with: 
		[[myData GetOutput] GetPointData] SetScalars myIDarray

This will attach attribute data to the geometry rendered by the actor.  In
this example, we used Scalar data, but it could also have been in the Field
data or the Vector data.   Then we you pick the actor in a pick, go back and
fetch the id value.  Inside a tcl procedure called after the pick event
(similar to the annotatePick.tcl example): 

proc calledAfterPickEvent {} {
	set pickedProp [picker GetActor]
	set thisdata [[$pickedProp GetMapper] GetInput]
	set my_id_back_from_vtk [[[$thisdata GetPointData] GetScalars]
GetValue 0] 
      ... do something with the id ....
}

The id fetch "looks back" from the actor, through the mapper to the geometry
and fetches the id value.  The key to this strategy is to make sure that you
add the id in step 3 AFTER the filter before in the pipeline executes.
Therefore, this strategy works for things that initialize from an input
file, or that you can control when the actor is generated.  

Good luck!

Curtis 

__--__--

Message: 2
From: Wiebke Timm <wiebke.timm at uni-bielefeld.de>
Subject: Re: [vtkusers] vtk actor inheritance
Date: Wed, 5 May 2004 13:13:42 +0200
To: vtkusers at vtk.org

Hi!

On 04.05.2004, at 16:19, Simon DROUIN wrote:

> I had the same problem.

Same for me... Trying to make an actor class which can hold an  
additional int for an ID. Seems like a lot of people need to do  
something like that and it's not covered in the book in detail... :( So  
maybe somebody who already did that and it worked could write a howto  
or something?
I wasn't sure if it was better to start a new thread for this but  
because it's basically the same problem I posted to this thread.

Curtis Lisle, PhD
Visual Systems Scientist, SGI
email: clisle "at" sgi.com




More information about the vtkusers mailing list