[vtkusers] translate x/y/z coordinates into vtk coordinate space

Sara Siegal ssiegal at passportsystems.com
Tue Mar 15 17:16:10 EDT 2011


I'm trying to get the mouse position within a QVTKWidget. I've derived a class from QVTKWidget (in my case it's called CargoViewerWidget) and in the mouse click callback, I call:
int x,y;
GetRenderWindow()->GetInteractor()->GetMousePosition(&x, &y);

No matter where I click, x and y are always 0. I also tried using vtkPointWidget:
    QPoint p = QCursor::pos(); <- gets the current position in the Qt widget
    vtkPointWidget* pt = vtkPointWidget::New();
    pt->SetPosition(x, y, 0); // z);    


x and y in this case are non-zero pixel counts. However, when I call
    double xyz[3];
    pt->GetPosition(xyz);
it returns (0,0,0) to me. 

What am I doing wrong? Is there a simpler way to get the current mouse position within the QVTKWidget?

If it's helpful, here's the code from my MainWindow constructor:

MainWindow::MainWindow(QWidget *parent) 
: QMainWindow(parent)
, myRenderer_(vtkSmartPointer<vtkRenderer>::New())
,vtkVolumeActor_(vtkSmartPointer<vtkActor>::New()) 
,volumeMapper_(vtkSmartPointer< vtkPolyDataMapper >::New())
,vtkVolumeInteractor_(vtkSmartPointer<vtkRenderWindowInteractor>::New())
{
    this->setupUi(this);
    // set up actors
    vtkVolumeActor_->SetMapper(volumeMapper_);
    myRenderer_->AddActor(vtkVolumeActor_);

    myViewerWidget_ = new PSI::CargoViewerWidget(cargoView_); <- CargoViewerWidget is derived from QVTKWidget
    // and cargoView_ is the QWidget that is its parent

    vtkRenderWindow* w1 = myViewerWidget _->GetRenderWindow();
    volumeRenderWindow_ = vtkWin32OpenGLRenderWindow::SafeDownCast(w1);
    

    // now we can set the views and renderers on the widgets
    myViewerWidget _->setView(dab_->getVolumeView()); 
    myViewerWidget_->GetRenderWindow()->AddRenderer(myRenderer_);

    vtkVolumeInteractor_->SetRenderWindow(cargoViewerWidget_->GetRenderWindow());
    vtkVolumeInteractor_->Initialize();

Thanks in advance,

Sara Siegal



More information about the vtkusers mailing list