VTK中获取鼠标交互场景的一种方法

FindPokedRenderer函数的用法

为了找到事件发生在哪一个renderer中使用FindPokedRendere函数该函数就是用于获取renderWindow中当前的renderer,使用时能获取鼠标在当前窗口中的坐标值同时配合vtkCellPicker使用还能用于拾取actor

class vtkButtonCallback : public vtkCommand
{
public:
	static vtkButtonCallback *New()
	{
		return new vtkButtonCallback;
	}
	virtual void Execute(vtkObject *caller, unsigned long, void*)
	{
		vtkRenderWindowInteractor  *iren = reinterpret_cast<vtkRenderWindowInteractor*>(caller);
		int x = iren->GetEventPosition()[0];
		int y = iren->GetEventPosition()[1];
		vtkRenderer *CurrentRenderer = iren->FindPokedRenderer(x, y);//获取交互场景
		vtkCellPicker *Picker = vtkCellPicker::SafeDownCast(iren->GetPicker());
		Picker->Pick(x, y, 0.0, CurrentRenderer);
		vtkProp *prop = Picker->GetViewProp();//拾取vtkactor
		if (prop != NULL)
		{
			vtkActor *InteractionProp = vtkActor::SafeDownCast(prop);
			InteractionProp->GetProperty()->SetColor(1.0, 0.0, 0.0);
		}
	}
};

你可能感兴趣的:(VTK,交互,c++,开发语言)