[vtkusers] vtkPointPicker - position identification problem

Jeff Lee jeff at cdnorthamerica.com
Tue Oct 8 12:17:36 EDT 2002


Do you render after the pick?
-Jeff

George Kamucha wrote:

>Hi all,
>I am selecting points on a surface using vtkPointPicker, and then placing small
>spheres in the selected locations. The problem I am facing is that, when I
>select the first location,  a sphere is not immediately placed there until a
>second location is selected. That is, I can only see the position of the
>previously selected location and not the current one. I have checked the
>archives but have not found anything related to my problem. If anybody has an
>idea on this issue, please bail me out before I lose all my hair :). Below is
>the snippet.
>
>Best regards
>George
>
>
>
>static void pickControl(void *);
>
>static vtkRenderer *ren1;
>
>void main( int argc, char *argv[] )
>
>{
>
>// create pipeline
>vtkPolyDataReader *reader = vtkPolyDataReader::New();
>      reader->SetFileName ("../../../vtkdata/Bone_CTNewdrR.vtk");
>      reader->Update();
>
>vtkPolyDataMapper *dataMapper = vtkPolyDataMapper::New();
>      dataMapper->SetInput(reader->GetOutput());
>      dataMapper->ScalarVisibilityOff();
>
>vtkActor *dataActor = vtkActor::New();
>       dataActor->SetMapper(dataMapper);
>       dataActor->GetProperty()->SetColor(0.5, 0.5, 1);
>       dataActor->GetProperty()->SetOpacity(0.5);
>
>vtkPointPicker *pointpicker = vtkPointPicker::New();
>
>
>ren1 = vtkRenderer::New();
>vtkRenderWindow *renWin = vtkRenderWindow::New();
>    renWin->AddRenderer(ren1);
>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>    iren->SetRenderWindow(renWin);
>    iren->SetPicker(pointpicker);
>    iren->SetEndPickMethod(pickControl, (void *)iren);
>
>ren1->AddActor(dataActor);
>
>// render the image
>    ren1->SetBackground(1, 1, 1);
>    renWin->SetSize(500,500);
>    iren->Initialize();
>    renWin->Render();
>    iren->Start();
>
>//Clean up
>
>ren1->Delete();
>renWin->Delete();
>iren->Delete();
>reader->Delete();
>dataMapper->Delete();
>dataActor->Delete();
>pointpicker->Delete();
>
> }
>
>
>
>// Define picking method
>
>static void pickControl(void *arg)
>{
>float *selPt;
>float *pickpos;
>
>vtkRenderWindowInteractor *iren = (vtkRenderWindowInteractor *)arg;
>  vtkPointPicker *pointpicker = (vtkPointPicker *)iren->GetPicker();
>
>
>
>  selPt = pointpicker->GetSelectionPoint();
>
>    cout<<"Screen location:"<<selPt[0]<<" "<<selPt[1]<<"\n";
>
> if ( pointpicker->GetPointId() >= 0 )
>    {
>    pickpos = pointpicker->GetPickPosition();
>
>    cout<<"Point location:"<<pickpos[0]<<" "<<pickpos[1]<<" "<<pickpos[2]<<"\n";
>
>
>
>
>
>
>//Define method for placing spheres
>vtkPoints *points=vtkPoints::New();
>       points-> InsertNextPoint(pickpos);
>       points-> Modified();
>
>vtkPolyData *profile=vtkPolyData::New();
>   profile->SetPoints(points);
>
>vtkSphereSource *sphere=vtkSphereSource::New();
>  sphere->SetRadius(2);
>
>vtkGlyph3D *glyph=vtkGlyph3D::New();
>    glyph->SetInput(profile);
>    glyph->SetSource(sphere->GetOutput());
>
>vtkPolyDataMapper *glyphMapper=vtkPolyDataMapper::New();
>     glyphMapper->SetInput(glyph->GetOutput());
>
>
>vtkActor *glyphActor=vtkActor::New();
>  glyphActor->SetMapper(glyphMapper);
>  glyphActor->GetProperty()->SetColor(0, 0, 1);
>
>ren1-> AddActor(glyphActor);
>
>
>
>
>points-> Delete();
>profile->  Delete();
>sphere->  Delete();
>glyph->  Delete();
>glyphMapper->  Delete();
>glyphActor->  Delete();
>   }
>   else
>   {
>         cout<<"No point picked here!"<<"\n";
>   }
>
>}
>
>
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers
>
>  
>




More information about the vtkusers mailing list