[VTK 8.1.0] Incorrect picking world coordinates caused by MSAA antialiasing.
Dear all,
Recently I switched to MSAA from FXAA to get better antialising results, but the use of MSAA introduced a bug in the world coordinates returned by picking.
Here is the correct picking location with antialiasing disabled (also correct with FXAA):
Now, I enable MSAA and pick at the same cell of the model:
The picked location in screen coordinates are the same, but in world coordinates, picking results in a location right in front of the camera (notice the near-zero distance), which is clearly wrong. I'd really like to stick to MSAA because, IMO, its results are visually better than FXAA, despite the former being slower than the latter.
Here's how I enable MSAA in my code:
//MSAA antialiasing
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples ( 8 );
QSurfaceFormat::setDefaultFormat ( QVTKOpenGLWidget::defaultFormat() );
_vtkwidget = new QVTKOpenGLWidget();
_renderer = vtkSmartPointer<vtkRenderer>::New();
_vtkwidget->SetRenderWindow(vtkGenericOpenGLRenderWindow::New());
_vtkwidget->GetRenderWindow()->AddRenderer(_renderer);
_vtkwidget->setFocusPolicy(Qt::StrongFocus);
//MSAA antialiasing
_vtkwidget->GetRenderWindow()->SetMultiSamples( 4 );
Here's the code that outputs the world coordinates returned by picking (sanity checks ommited for clarity):
// Get pick position in 2D screen coordinates.
int* clickPos = this->GetInteractor()->GetEventPosition();
// Get the 3D object under the 2D screen coordinates (ray casting).
vtkSmartPointer<vtkPropPicker> picker = vtkSmartPointer<vtkPropPicker>::New();
picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
// Get the picked location in world coordinates.
double* pos = picker->GetPickPosition();
// Output the picked location.
Application::instance()->logInfo( "Picked location (world coordinates): X="
+ QString::number(pos[0]) + " Y=" + QString::number(pos[1])
+ " Z=" + QString::number(pos[2]) );
I can post more info and/or the complete code of the software's branch in GitHub if necessary.
thanks in advance,
Paulo