How to get the world coordinate along with a mouse cursor.

Hi All.
I have a question about how to get the world coordinate along with a mouse cursor.

□ Background:
I’m using the vtkRenderWindow to the Picture control on the MFC project.
And I’m trying to get the world coordinate of the Point Cloud Data along with the mouse cursor on the Picture control.

Please refer to as below my sample code:

class CCustomMouseInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CCustomMouseInteractorStyle* New();
vtkTypeMacro(CCustomMouseInteractorStyle, vtkInteractorStyleTrackballCamera);

// …
virtual void OnMouseMove() override
{
int* pos = this->GetInteractor()->GetEventPosition();

  vtkNew<vtkPropPicker> picker;
  picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());
  double* picker_coordinate = picker->GetPickPosition(); //Picker coordinate

  vtkNew<vtkCoordinate> coordinate;
  coordinate->SetCoordinateSystemToDisplay();
  coordinate->SetValue(pos[0], pos[1], 0);

  double* world_coordinate = coordinate->GetComputedWorldValue(this->GetDefaultRenderer()); //World coordinate
  
  vtkInteractorStyleTrackballCamera::OnMouseMove();

}
// …
};

□ Symptom:
The world coordinate and the actual point coordinate obtained by mouse cursor when zoomed in is different.
I will explain the detail with the below picture.

  1. Load the same PCD file on the CloudCompare and my sample program.
  2. Check the coordinate of the same point.

“Display:” means that XY coordinate of the Picture control obtained by ‘this->GetInteractor()->GetEventPosition();’.
“World:” means that the world coordinate computed by the vtkCoordinate.
“Picker:” means that the coordinate of the point obtained by the vtkPropPicker.

You can see that the coordinates of the point obtained by the CloudComapre and the “Picker” are the same.
But there are different world coordinate and the “Picker” coordinate.

I would like to know how to get the correct world coordinate along with the mouse cursor.

Thank you.
Best regards,
William Kim

1 Like