[vtkusers] Re: vtkPointPicker - position identification problem

George Kamucha kamucha at hfm.e-technik.uni-kassel.de
Wed Oct 9 04:16:22 EDT 2002


Hi Jeff,
I have tried before to use renWin->Render() after the pick (within the function pickControl, as
shown in the snippet below) but the problem still persists. Or am I not doing it in the right
way?

Regards
George

static void pickControl(void *);

static vtkRenderer *ren1;

static vtkRenderWindow *renWin;

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();
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);

renWin->Render();


points-> Delete();
profile->  Delete();
sphere->  Delete();
glyph->  Delete();
glyphMapper->  Delete();
glyphActor->  Delete();
   }
   else
   {
         cout<<"No point picked here!"<<"\n";
   }

}






Jeff Lee wrote:

> 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




More information about the vtkusers mailing list