null in this->GetDefaultRenderer() in virtual void OnRightButtonDown()

Dear all,

I have a doubt of programming. I am trying the examples of picking points from the mouse.

I see in the virtual function of the mouse (OnRightButtonDown()) when i want to get the renderer,
it returns null.

If i do this this->GetDefaultRenderer() i get a an error. So the pointer do not add the renderer info

By now, what i did was a global variable of the mainrenderer and it is working but i want to keep my code clean and i would like to understand why i cannot get this info from this



int* pos = this->GetInteractor()->GetEventPosition();

this works

it is only the renderer.

I hope you can help me so i can remove this global variable. To continue programming it is fine but i wold like to keep the code as clean as possible.


I attach the code i want to replace the global_renderer with this->GetDefaultRenderer().


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

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

		vtkSmartPointer<vtkCellPicker> picker =


		// Pick from this location.
		picker->Pick(pos[0], pos[1], 0, global_renderer);

		double* worldPosition = picker->GetPickPosition();
		std::cout << "Cell id is: " << picker->GetCellId() << std::endl;

		if (picker->GetCellId() != -1)

			std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1]
				<< " " << worldPosition[2] << endl;

		// Forward events


When you instantiate your custom style, make sure to set the default renderer on it using vtkInteractorStyle::SetDefaultRenderer()

Something like:

vtkNew<customMouseInteractorStyle> style;
1 Like