<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>RE: [vtkusers] Picking and moving a vertex</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<BR>
<P><FONT SIZE=2>Hi folks,<BR>
<BR>
Ok, for my app I have a vtk file which consists a bunch<BR>
of blobs. I find actors by first finding the number of blobs:<BR>
<BR>
# some vtk in python<BR>
polyImg = vtkPolyDataReader())<BR>
polyImg.SetFileName(name)<BR>
<BR>
# extract all regions for the blobs<BR>
connImg = vtkPolyDataConnectivityFilter())<BR>
connImg.SetExtractionModeToAllRegions()<BR>
connImg.SetInput(polyImg.GetOutput())<BR>
<BR>
# update to get the number of blobs<BR>
connImg.Update()<BR>
<BR>
# get the number of blobs<BR>
numofblobs = connImg.GetNumberOfExtractedRegions()<BR>
<BR>
The blobs are then extrated into a list of mappers and actors using:<BR>
<BR>
# loop over the number of blobs (i)<BR>
blobMappers.append(vtkPolyDataMapper())<BR>
<BR>
tempImg = vtkPolyDataConnectivityFilter()<BR>
tempImg.SetExtractionModeToSpecifiedRegions()<BR>
tempImg.SetInput(connImg.GetOutput())<BR>
tempImg.AddSpecifiedRegion(i)<BR>
<BR>
blobMappers[i].SetInput(tempImg.GetOutput())<BR>
blobActors.append(vtkActor())<BR>
blobActors[i].SetMapper(blobMappers[i])<BR>
<BR>
ren1.AddActor(blobActors[i])<BR>
<BR>
I can then use vtkPicker.GetMapper() to get the mapper which was picked,<BR>
and therefore the actor as they are created at the same time.<BR>
<BR>
# find the actor<BR>
def handlePick(object, event):<BR>
mapper = picker.GetMapper()<BR>
for i in range(0, numofblobs 1):<BR>
if mapper == blobMappers[i]: # find the mapper<BR>
# do some stuff<BR>
# i also indicates the correct actor<BR>
<BR>
Reading in all the blobs is a bit slow (100 or so blobs) but it works.<BR>
<BR>
hth,<BR>
<BR>
Henrik<BR>
<BR>
-----Original Message-----<BR>
From: vtkusers-bounces+henrik.westerberg=crg.es@vtk.org on behalf of Geoframer<BR>
Sent: Thu 6/14/2007 2:00 PM<BR>
To: Meisam Aliroteh<BR>
Cc: vtkusers@vtk.org<BR>
Subject: Re: [vtkusers] Picking and moving a vertex<BR>
<BR>
I think you can at least get the starting position by using the<BR>
picker.GetPickPosition() although this is not your center of the vertex but<BR>
the coordinates on the glyph. It is at least in 3D coordinates. To get the<BR>
real starting point you should indeed get the Actor that is picked upon and<BR>
use it's GetCenter() to retrieve the center of the glyph.<BR>
<BR>
I haven't been able to pull this off though. When i try to get the Actor i'm<BR>
picking on i seem to pick the picker's actor for my GetCenter() always<BR>
returns the middle of the data instead of the middle of the vertex.<BR>
<BR>
In any case I'm quite curious how you can go from a cellId to the<BR>
approperiate vertex... Do you just integer divide by the number of cells per<BR>
glyph?<BR>
<BR>
Perhaps Henrik can shed some more light on how you can actually get the<BR>
actor of the glyph when picking?<BR>
<BR>
Regards - Geofram<BR>
<BR>
On 6/13/07, Meisam Aliroteh <meisam.aliroteh@gmail.com> wrote:<BR>
><BR>
> Hi,<BR>
><BR>
> I have a polydata and used a sphere source to render the polydata in<BR>
> point-cloud mode (i.e only vertices are rendered, and I use spheres to<BR>
> show these vertices). I want the user to be able to click on any vertex<BR>
> (shpere) and move it in the 3D space (well actually it would be a motion<BR>
> restricted to the current view plane). I used vtkCellPicker and know how to<BR>
> figure out which vertex is picked when the user clicks on it. What I don't<BR>
> know is how to figure out the motion vector when the user clicks and drags a<BR>
> sphere ? I can get the old and new mouse positions from the interactor but<BR>
> these are 2D coordinates.<BR>
><BR>
> I guess what I need is the 3D coordinates of the previous and current<BR>
> mouse positions, so that when I subtract these 3D coordiantes I get a motion<BR>
> vector and then I can move the picked vertex by adding this motion vector to<BR>
> it. The problem is I don't know how to get the 3D coordinate of the mouse<BR>
> pointer using VTK !!!<BR>
><BR>
> Any ideas?<BR>
><BR>
> _______________________________________________<BR>
> This is the private VTK discussion list.<BR>
> Please keep messages on-topic. Check the FAQ at:<BR>
> <A HREF="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</A><BR>
> Follow this link to subscribe/unsubscribe:<BR>
> <A HREF="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</A><BR>
><BR>
><BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>