1 设置回调函数
QVTKOpenGLNativeWidget* m_vtk_gl_widget=new QVTKOpenGLNativeWidget(this);
vtkSmartPointer<vtkRenderWindowInteractor> iron=m_vtk_gl_widget->GetInteractor();
//NON Release
iron->AddObserver( vtkCommand::LeftButtonPressEvent, this, &ImageCTViewer::mousePressCallbackFunction );
iron->AddObserver( vtkCommand::LeftButtonReleaseEvent, this, &ImageCTViewer::mouseReleaseCallbackFunction);
但是无法监听释放事件
void ImageCTViewer::mousePressCallbackFunction(vtkObject *obj, unsigned long vtkNotUsed(eventId), void *vtkNotUsed(callData))
{
int* pos=(static_cast<QVTKInteractor*>(obj))->GetEventPosition();
m_clicked_pos=QPoint(pos[0],pos[1]);
qDebug()<<pos[0]<<pos[1];
}
2 重载 ctkCommand
当vtkopenglnativewidget
有一个vtkImageViewer2
,原有的响应方式失效,为了保留原有响应方式,采用第三种
vtkSmartPointer<vtkInteractorStyleImage> nextSliceInteractorStyle =
vtkSmartPointer<vtkInteractorStyleImage>::New();
//add mouse click event
vtkSmartPointer<cutomButtonEventCallback> callback=
vtkSmartPointer<cutomButtonEventCallback>::New();
callback->setImage(this)