[vtkusers] Picking and moving a vertex

Henrik Westerberg henrik.westerberg at crg.es
Thu Jun 14 09:07:34 EDT 2007



Hi folks,

Ok, for my app I have a vtk file which consists a bunch
of blobs. I find actors by first finding the number of blobs:

# some vtk in python
polyImg = vtkPolyDataReader())
polyImg.SetFileName(name)

# extract all regions for the blobs
connImg = vtkPolyDataConnectivityFilter())
connImg.SetExtractionModeToAllRegions()
connImg.SetInput(polyImg.GetOutput())

# update to get the number of blobs
connImg.Update()

# get the number of blobs
numofblobs = connImg.GetNumberOfExtractedRegions()

The blobs are then extrated into a list of mappers and actors using:

# loop over the number of blobs (i)
blobMappers.append(vtkPolyDataMapper())

tempImg = vtkPolyDataConnectivityFilter()
tempImg.SetExtractionModeToSpecifiedRegions()
tempImg.SetInput(connImg.GetOutput())
tempImg.AddSpecifiedRegion(i)

blobMappers[i].SetInput(tempImg.GetOutput())
blobActors.append(vtkActor())
blobActors[i].SetMapper(blobMappers[i])

ren1.AddActor(blobActors[i])

I can then use vtkPicker.GetMapper() to get the mapper which was picked, 
and therefore the actor as they are created at the same time.

# find the actor
def handlePick(object, event):
    mapper =  picker.GetMapper()
    for i in range(0, numofblobs 1):
        if mapper == blobMappers[i]:           # find the mapper
            # do some stuff
            # i also indicates the correct actor

Reading in all the blobs is a bit slow (100 or so blobs) but it works.

hth,

Henrik

-----Original Message-----
From: vtkusers-bounces+henrik.westerberg=crg.es at vtk.org on behalf of Geoframer
Sent: Thu 6/14/2007 2:00 PM
To: Meisam Aliroteh
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Picking and moving a vertex
 
I think you can at least get the starting position by using the
picker.GetPickPosition() although this is not your center of the vertex but
the coordinates on the glyph. It is at least in 3D coordinates. To get the
real starting point you should indeed get the Actor that is picked upon and
use it's GetCenter() to retrieve the center of the glyph.

I haven't been able to pull this off though. When i try to get the Actor i'm
picking on i seem to pick the picker's actor for my GetCenter() always
returns the middle of the data instead of the middle of the vertex.

In any case I'm quite curious how you can go from a cellId to the
approperiate vertex... Do you just integer divide by the number of cells per
glyph?

Perhaps Henrik can shed some more light on how you can actually get the
actor of the glyph when picking?

Regards - Geofram

On 6/13/07, Meisam Aliroteh <meisam.aliroteh at gmail.com> wrote:
>
> Hi,
>
> I have a polydata and used a sphere source to render the polydata in
> point-cloud mode (i.e only vertices are rendered, and I use spheres to
> show these vertices). I want the user to be able to click on any vertex
> (shpere) and move it in the 3D space (well actually it would be a motion
> restricted to the current view plane). I used vtkCellPicker and know how to
> figure out which vertex is picked when the user clicks on it. What I don't
> know is how to figure out the motion vector when the user clicks and drags a
> sphere ? I can get the old and new mouse positions from the interactor but
> these are 2D coordinates.
>
> I guess what I need is the 3D coordinates of the previous and current
> mouse positions, so that when I subtract these 3D coordiantes I get a motion
> vector and then I can move the picked vertex by adding this motion vector to
> it. The problem is I don't know how to get the 3D coordinate of the mouse
> pointer using VTK !!!
>
> Any ideas?
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the 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/20070614/783f359a/attachment.htm>


More information about the vtkusers mailing list