[vtkusers] Problem with vtkPointPicker

Łukasz Tutaj ltutaj at wp.pl
Thu Oct 6 13:52:23 EDT 2005


Hi vtk Users,

    In my project I display DICOM files. I would also like to pick a 
point on a screen and then get the value of this point (level of gray). 
I added vtkPointPicker to interactor and then I added observer to 
interactor, but it doesn't work. Could someone tell me why. Below is my 
source code.

Thanks in advance.
Łukasz Tutaj

class vtkMyCallback : public vtkCommand
{
public:
    vtkPointPicker * m_picker;
    vtkImageViewer2 *m_viewer;
   
    int x, y;
  static vtkMyCallback *New()
    { return new vtkMyCallback; }
  virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
            vtkRenderWindowInteractor *iren = 
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
            x = iren->GetEventPosition()[0];
            y = iren->GetEventPosition()[1];
            int succed = m_picker->Pick(x, y, m_viewer->GetZSlice(), 
m_viewer->GetRenderer());
            int pointId = m_picker->GetPointId();
            m_picker->GetPickedPositions();
            cout << "(" << x << ", " << y << ") " << succed << " " << 
pointId << endl;
    }
        void SetPicker(vtkPointPicker *picker)
        {
            m_picker = picker;
        }
        void SetImageViewer(vtkImageViewer2 *viewer)
        {
            m_viewer = viewer;
        }
};


int main (int argc, char **argv)
{
    vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
    reader->SetFileName("D:\\PRACA MAGISTERSKA\\dane381\\46009361");

    vtkImageViewer2 *viewer = vtkImageViewer2::New();
    viewer->SetInput(reader->GetOutput());
    viewer->SetColorLevel(40);
    viewer->SetColorWindow(300);
       
    vtkRenderWindowInteractor *interactor = 
vtkRenderWindowInteractor::New();
    viewer->SetupInteractor(interactor);
    vtkPointPicker *picker = vtkPointPicker::New();
    interactor->SetPicker(picker);

    vtkMyCallback *mo1 = vtkMyCallback::New();
    mo1->SetPicker(picker);
    mo1->SetImageViewer(viewer);
    interactor->AddObserver(vtkCommand::LeftButtonPressEvent,mo1);
    //mo1->Delete();

    interactor->Initialize();
    interactor->Start();

    reader->Delete();
    interactor->Delete();
    viewer->Delete();

  return 0;
}




More information about the vtkusers mailing list