<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Hi Dominik!<BR> <BR>Thank you for your reply. I tried what you suggested and included the update just before I get the release position of the mouse. It seems to be the most logical place to do so to me. However, there is still no change in the output.<BR><br>I was thinking maybe the problem lies with the coordinates returned themselves.<BR> <BR>Does anyone have any previous experience with this?<BR> <BR>Vashist<BR> <BR><div>> Date: Fri, 17 Jun 2011 14:14:25 +0200<br>> From: dominik@itis.ethz.ch<br>> To: vashist14@yahoo.com<br>> CC: vtkusers@vtk.org<br>> Subject: Re: [vtkusers] Picking and dragging a vertex - points not moving to appropriate position<br>> <br>> Sounds very much like you miss dataset->Modified() somewhere.<br>> <br>> Dominik<br>> <br>> On Fri, Jun 17, 2011 at 10:41 AM, Vashist Purbhoo <vashist14@hotmail.com> wrote:<br>> > Hi vtkusers!<br>> ><br>> > I am trying to deform a 3D object by clicking and dragging its vertices. I<br>> > was able to adapt the "SelectAVertex.cxx" example<br>> > (http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/MoveAVertex) on the<br>> > vtk website to make it work with a polydata I create using vtkSphereSource.<br>> > To summarise, to deform the object I select a vertex by clicking on the<br>> > middle mouse button and drag the point to the new location I want. I render<br>> > the vertices of my object using<br>> > vtkVertexGlyphFilter as well as the surface of the object.<br>> ><br>> > The program works correctly if I select the points without changing the<br>> > initial view of the rendered object. However, once I change the view, for<br>> > example to access a point at the back of my object, the point no longer<br>> > moves to where I drag it. The coordinates returned do not correspond to the<br>> > position where i release the mouse button. I would highly appreciate if any<br>> > help/suggestions could be provided on how to solve this.<br>> ><br>> > Thank you.<br>> ><br>> > Vashist<br>> ><br>> ><br>> > #include <vtkSmartPointer.h><br>> > #include <vtkPointPicker.h><br>> > #include <vtkRendererCollection.h><br>> > #include <vtkProperty.h><br>> > #include <vtkObjectFactory.h><br>> > #include <vtkPolyDataMapper.h><br>> > #include <vtkActor.h><br>> > #include <vtkRenderWindow.h><br>> > #include <vtkRenderer.h><br>> > #include <vtkRenderWindowInteractor.h><br>> > #include <vtkPolyData.h><br>> > #include <vtkPointSource.h><br>> > #include <vtkInteractorStyleJoystickActor.h><br>> > #include <vtkAreaPicker.h><br>> > #include <vtkVertexGlyphFilter.h><br>> > #include <vtkIdFilter.h><br>> > #include <vtkAssembly.h><br>> > #include <vtkSphereSource.h><br>> > #include <vtkExtractGeometry.h><br>> > #include <vtkDataSetMapper.h><br>> > #include <vtkUnstructuredGrid.h><br>> > #include <vtkGlyph3D.h><br>> > #include <vtkPointData.h><br>> > #include <vtkIdTypeArray.h><br>> > #include <vtkDataSetSurfaceFilter.h><br>> > #include <vtkPlanes.h><br>> ><br>> > class InteractorStyle : public vtkInteractorStyleJoystickActor<br>> > {<br>> > public:<br>> > static InteractorStyle* New();<br>> > vtkTypeMacro(InteractorStyle,vtkInteractorStyleJoystickActor);<br>> ><br>> > InteractorStyle()<br>> > {<br>> > this->Move = false;<br>> > this->PointPicker = vtkSmartPointer<vtkPointPicker>::New();<br>> ><br>> > // Setup ghost glyph<br>> > vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();<br>> > points->InsertNextPoint(0,0,0);<br>> > this->MovePolyData = vtkSmartPointer<vtkPolyData>::New();<br>> > this->MovePolyData->SetPoints(points);<br>> > this->MoveGlyphFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();<br>> ><br>> > this->MoveGlyphFilter->SetInputConnection(this->MovePolyData->GetProducerPort());<br>> > this->MoveGlyphFilter->Update();<br>> ><br>> > this->MoveMapper = vtkSmartPointer<vtkPolyDataMapper>::New();<br>> ><br>> > this->MoveMapper->SetInputConnection(this->MoveGlyphFilter->GetOutputPort());<br>> ><br>> > this->MoveActor = vtkSmartPointer<vtkActor>::New();<br>> > this->MoveActor->SetMapper(this->MoveMapper);<br>> > this->MoveActor->VisibilityOff();<br>> > this->MoveActor->GetProperty()->SetPointSize(5);<br>> > this->MoveActor->GetProperty()->SetColor(1,0,0);<br>> > }<br>> > //_____________________________________________________________________________________<br>> > void OnMouseMove()<br>> > {<br>> > if(!this->Move)<br>> > {<br>> > return;<br>> > }<br>> > vtkInteractorStyleJoystickActor::OnMouseMove();<br>> > }<br>> > //_____________________________________________________________________________________<br>> > void OnMiddleButtonUp()<br>> > {<br>> > this->EndPan();<br>> ><br>> > this->Move = false;<br>> > this->MoveActor->VisibilityOff();<br>> > this->Data->GetPoints()->SetPoint(this->SelectedPoint,<br>> > this->MoveActor->GetPosition());<br>> > this->Data->Modified();<br>> > this->GetCurrentRenderer()->Render();<br>> > this->GetCurrentRenderer()->GetRenderWindow()->Render();<br>> ><br>> > }<br>> > //_____________________________________________________________________________________<br>> > void OnMiddleButtonDown()<br>> > {<br>> > // Get the selected point<br>> > int x = this->Interactor->GetEventPosition()[0];<br>> > int y = this->Interactor->GetEventPosition()[1];<br>> > this->FindPokedRenderer(x, y);<br>> ><br>> > this->PointPicker->Pick(this->Interactor->GetEventPosition()[0],<br>> > this->Interactor->GetEventPosition()[1],<br>> > 0, // always zero.<br>> ><br>> > this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());<br>> > if(this->PointPicker->GetPointId() >= 0)<br>> > {<br>> > this->StartPan();<br>> > this->MoveActor->VisibilityOn();<br>> > this->Move = true;<br>> > this->SelectedPoint = this->PointPicker->GetPointId();<br>> ><br>> > std::cout << "Dragging point " << this->SelectedPoint << std::endl;<br>> ><br>> > double p[3];<br>> > this->Data->GetPoint(this->SelectedPoint, p);<br>> > std::cout << "p: " << p[0] << " " << p[1] << " " << p[2] <<<br>> > std::endl;<br>> > this->MoveActor->SetPosition(p);<br>> ><br>> > this->GetCurrentRenderer()->AddActor(this->MoveActor);<br>> > this->InteractionProp = this->MoveActor;<br>> > }<br>> > }<br>> > //_____________________________________________________________________________________<br>> > vtkPolyData* Data;<br>> > vtkPolyData* GlyphData;<br>> ><br>> > vtkSmartPointer<vtkPolyDataMapper> MoveMapper;<br>> > vtkSmartPointer<vtkActor> MoveActor;<br>> > vtkSmartPointer<vtkPolyData> MovePolyData;<br>> > vtkSmartPointer<vtkVertexGlyphFilter> MoveGlyphFilter;<br>> > vtkSmartPointer<vtkPointPicker> PointPicker;<br>> > bool Move;<br>> > vtkIdType SelectedPoint;<br>> > };<br>> > //_____________________________________________________________________________________<br>> > vtkStandardNewMacro(InteractorStyle);<br>> > //_____________________________________________________________________________________<br>> ><br>> > int main (int, char *[])<br>> > {<br>> > // Create a sphere (object to be deformed)<br>> > vtkSmartPointer<vtkSphereSource> sphereSource =<br>> > vtkSmartPointer<vtkSphereSource>::New();<br>> > sphereSource->SetCenter(20.0, 20.0, 20.0);<br>> > sphereSource->SetRadius(20.0);<br>> > sphereSource->SetThetaResolution(10);<br>> > sphereSource->SetPhiResolution(10);<br>> > sphereSource->Update();<br>> ><br>> > //Create polydata from sphereSource<br>> > vtkSmartPointer<vtkPolyData> points_poly =<br>> > vtkSmartPointer<vtkPolyData>::New();<br>> > points_poly->CopyStructure(sphereSource->GetOutput());<br>> ><br>> > vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter<br>> > = vtkSmartPointer<vtkVertexGlyphFilter>::New();<br>> > glyphFilter->SetInputConnection(points_poly->GetProducerPort());<br>> > glyphFilter->Update();<br>> > // Create a mapper and actor<br>> > vtkSmartPointer<vtkPolyDataMapper> points_mapper =<br>> > vtkSmartPointer<vtkPolyDataMapper>::New();<br>> > points_mapper->SetInputConnection(glyphFilter->GetOutputPort());<br>> ><br>> > vtkSmartPointer<vtkActor> points_actor = vtkSmartPointer<vtkActor>::New();<br>> > points_actor->SetMapper(points_mapper);<br>> > points_actor->GetProperty()->SetPointSize(10);<br>> > vtkSmartPointer<vtkPolyDataMapper> Mapper2 =<br>> > vtkSmartPointer<vtkPolyDataMapper>::New();<br>> > Mapper2->SetInput(points_poly);<br>> ><br>> > vtkSmartPointer<vtkActor> Actor2 = vtkSmartPointer<vtkActor>::New();<br>> > Actor2->SetMapper(Mapper2);<br>> ><br>> > //assembly to synchronise interaction of points & polydata<br>> > vtkSmartPointer<vtkAssembly> assembly<br>> > = vtkSmartPointer<vtkAssembly>::New();<br>> > assembly->AddPart(points_actor);<br>> > assembly->AddPart(Actor2);<br>> > // Visualize<br>> > vtkSmartPointer<vtkRenderer> renderer =<br>> > vtkSmartPointer<vtkRenderer>::New();<br>> > vtkSmartPointer<vtkRenderWindow> renderWindow =<br>> > vtkSmartPointer<vtkRenderWindow>::New();<br>> > renderWindow->AddRenderer(renderer);<br>> ><br>> > vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>> > vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>> > renderWindowInteractor->SetRenderWindow(renderWindow);<br>> ><br>> > renderer->AddActor(assembly);<br>> ><br>> > renderWindow->Render();<br>> ><br>> > vtkSmartPointer<InteractorStyle> style =<br>> > vtkSmartPointer<InteractorStyle>::New();<br>> > renderWindowInteractor->SetInteractorStyle( style );<br>> > style->Data = points_poly;<br>> ><br>> > renderWindowInteractor->Start();<br>> > return EXIT_SUCCESS;<br>> > }<br>> ><br>> > _______________________________________________<br>> > Powered by www.kitware.com<br>> ><br>> > Visit other Kitware open-source projects at<br>> > http://www.kitware.com/opensource/opensource.html<br>> ><br>> > Please keep messages on-topic and check the VTK FAQ at:<br>> > http://www.vtk.org/Wiki/VTK_FAQ<br>> ><br>> > Follow this link to subscribe/unsubscribe:<br>> > http://www.vtk.org/mailman/listinfo/vtkusers<br>> ><br>> ><br>> _______________________________________________<br>> Powered by www.kitware.com<br>> <br>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br>> <br>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br>> <br>> Follow this link to subscribe/unsubscribe:<br>> http://www.vtk.org/mailman/listinfo/vtkusers<br></div>                                            </div></body>
</html>