Performance of rendering the PCD data.

Hi all.

I’m sorry for asking so many questions recently. :sob:
But when I before asking a question, please understand that I have tested with sample code and googling. :flushed:

My question is …
I want to display the point coordinate information of PCD data depending on the mouse cursor position.

I referred the link:
https://vtk.org/Wiki/VTK/Examples/Cxx/Interaction/MouseEvents
https://vtk.org/Wiki/VTK/Examples/Cxx/Interaction/PointPicker

But the rendering speed is so slow when GetPickPosition API is called continuously by OnMouseMove() event.

My code is as below:

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

CCustomMouseInteractorStyle()
{
	selectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
	selectedActor = vtkSmartPointer<vtkActor>::New();
}

virtual void OnMouseMove() override
{
	// Get the location of the click (in window coordinates)
	int* pos = this->GetInteractor()->GetEventPosition();

	vtkSmartPointer<vtkPointPicker> picker =
		vtkSmartPointer<vtkPointPicker>::New();

	// Pick from this location.
	picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());
	if (picker->GetPointId() != -1)
	{
		double* worldPosition = picker->GetPickPosition();
		/*CString tmp;
		tmp.Format(_T("%.3f\n"), worldPosition[2]);
		OutputDebugString(tmp);*/
	}

	vtkInteractorStyleTrackballCamera::OnMouseMove();
}

vtkSmartPointer<vtkPolyData> Data;
vtkSmartPointer<vtkDataSetMapper> selectedMapper;
vtkSmartPointer<vtkActor> selectedActor;
};

vtkStandardNewMacro(CCustomMouseInteractorStyle);

How to speed up the rendering while getting the point coordinate information?

Could you please advise for me?

Thank you :slight_smile:

You can experiment with the many pickers VTK has. Some are faster (e.g., hardware-based pickers and those that are accelerated by using locator), some are more accurate or simpler.

vtkPointPicker is accurate, but I think it does not use a locator so it can be extremely slow if you have many points. vtkCellPicker can use a locator to speed up its operation. If vtkCellPicker does not work on a point cloud (require cells) then you can try to add a locator to vtkPointPicker or just use a locator directly (without a picker).

Hi Andras Lasso!

Thank you for your reply.

So… what can I do to the test?
It can’t use with vtkCellPicker because there are no cells, and I can use vtkPointPicker but rendering speed is so slow with Pick API in the OnMouseMove event().

I still don’t know how to speed up the 3D rendering while getting point information.

Thank you :cry:

There are so many options. For example, you may try adding a vertex cell for each point and see if cell picker or hardware-accelerated picker work (vtkScenePicker has some additional caching to speed up hardware-accelerated picking). You may also add a timer to only pick if the mouse is stopped over a point (vtkHoverWidget does something similar). You may also project all your points to the display plane and then use a locator to quickly find the closest point (the disadvantage is that you need to recompute each time you rotate the camera).

So thank you for your guide!

I will try all of that.

Thank you :slight_smile:

Hello, I have met the same problem as you describe. Have you solved it?