I use this example for a WorldPointPicker. It works fine, but if i zoom in, it doesn’t give the correct coordinates. How can i correct this?
Hi, Thomas,
I perform picking with this (simplified from https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/v3dmouseinteractor.cpp):
void v3dMouseInteractor::OnLeftButtonUp()
{
// Don't pick during dragging.
if( ! m_isDragging ){
// 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 cell of a 3D object under the 2D screen coordinates (ray casting).
vtkSmartPointer<vtkCellPicker> cellPicker = vtkSmartPointer<vtkCellPicker>::New();
cellPicker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());
//if something was picked
if( picker->GetActor() && cellPicker->GetCellId() != -1 ) {
// 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]) );
}
}
m_isLBdown = false;
m_isDragging = false;
// Forward the event to the superclass.
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
}
I hope this helps.
regards,
Paulo
Hi Paulo,
thank you for your help, but your code doesn’t work, because “this->GetDefaultRenderer()” crashes. But now, i found the solution. In the example, I substitutet "this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer() " and passed the Renderer as a parameter. Now it works.