BestMPRBaseVtk-013-myVtkInteractorStyleImage交互样式
Posted DreamLife.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BestMPRBaseVtk-013-myVtkInteractorStyleImage交互样式相关的知识,希望对你有一定的参考价值。
BestMPRBaseVtk myVtkInteractorStyleImage交互样式
myVtkInteractorStyleImage
继承自vtkInteractorStyleImage
,将重写部分鼠标事件和将部分数据传输给外部,形成信号发送出去。
关键字:
Style
、InteractorStyle
、Interactor
、vtk
、交互
1 重写鼠标滚轮事件,实现鼠标滚轮切换Slice
在vtkInteractorStyleImage
中没有找到对应的接口。vtkInteractorStyleImage
继承自vtkInteractorStyleTrackballCamera
,在vtkInteractorStyleTrackballCamera
中有与鼠标滚轮相关的接口。如下:
void OnMouseWheelForward() override;
void OnMouseWheelBackward() override;
官方的代码实现如下,默认鼠标滚轮为放大缩小。
//----------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera::OnMouseWheelForward()
this->FindPokedRenderer(
this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
if (this->CurrentRenderer == nullptr)
return;
this->GrabFocus(this->EventCallbackCommand);
this->StartDolly();
double factor = this->MotionFactor * 0.2 * this->MouseWheelMotionFactor;
this->Dolly(pow(1.1, factor));
this->EndDolly();
this->ReleaseFocus();
//----------------------------------------------------------------------------
void vtkInteractorStyleTrackballCamera::OnMouseWheelBackward()
this->FindPokedRenderer(
this->Interactor->GetEventPosition()[0], this->Interactor->GetEventPosition()[1]);
if (this->CurrentRenderer == nullptr)
return;
this->GrabFocus(this->EventCallbackCommand);
this->StartDolly();
double factor = this->MotionFactor * -0.2 * this->MouseWheelMotionFactor;
this->Dolly(pow(1.1, factor));
this->EndDolly();
this->ReleaseFocus();
改写以下:
/**
* @brief myVtkInteractorStyleImage::OnMouseWheelForward
* 鼠标滚轮向前滚动
* 切换图层显示
*/
void myVtkInteractorStyleImage::OnMouseWheelForward()
int maxSlice = this->ImageViewer->getSliceMax();
int currentSlice = this->ImageViewer->getSlice();
if(currentSlice < maxSlice)
currentSlice += 1;
this->ImageViewer->setSlice(currentSlice);
this->ImageViewer->render();
bppWidget->emitSliceChangedSignal(currentSlice);
/**
* @brief myVtkInteractorStyleImage::OnMouseWheelBackward
* 鼠标滚轮向后滚动
* 切换图层显示
*/
void myVtkInteractorStyleImage::OnMouseWheelBackward()
int minSlice = this->ImageViewer->getSliceMin();
int currentSlice = this->ImageViewer->getSlice();
if(currentSlice > minSlice)
currentSlice -= 1;
this->ImageViewer->setSlice(currentSlice);
this->ImageViewer->render();
bppWidget->emitSliceChangedSignal(currentSlice);
其他的事件也稍作了修改,可以看源码内容。
☞ 源码
源码链接:GitHub仓库自取
使用方法:☟☟☟
以上是关于BestMPRBaseVtk-013-myVtkInteractorStyleImage交互样式的主要内容,如果未能解决你的问题,请参考以下文章