如何禁用VTK的热键

how to disable vtk's hotkey

本文关键字:VTK 何禁用      更新时间:2023-10-16

我想在vtk上禁用一些热键。 实际上我正在使用vtk.js,但是可以用正常的vtk方式告诉我。

我想在这里禁用下面的热键: "W":切换感兴趣区域 (ROI( 选择微件 "S":在体积渲染模式下切换切片平面 "V":切换为点形式 "R":重置相机

我尝试在OpenGLRenderwindow上设置InteractorStyleManipulator, 并尝试了全屏渲染方式。 但它不起作用。

我怎样才能通过它?

谢谢!

<div id="container"></div>
<script>

const container = document.querySelector('#container');
//VTK renderwindow/renderer
//const fullScreenRenderer = vtk.Rendering.Misc.vtkFullScreenRenderWindow.newInstance();
const renderWindow = vtk.Rendering.Core.vtkRenderWindow.newInstance();
const renderer     = vtk.Rendering.Core.vtkRenderer.newInstance();
renderWindow.addRenderer(renderer);
//webGL/opengl impl
const openGLRenderWindow = vtk.Rendering.OpenGL.vtkRenderWindow.newInstance();
openGLRenderWindow.setContainer(container);
openGLRenderWindow.setSize(1000,1000);
renderWindow.addView(openGLRenderWindow);
//Interactor
const interactor = vtk.Rendering.Core.vtkRenderWindowInteractor.newInstance();
interactor.setView(openGLRenderWindow);
interactor.initialize();
interactor.bindEvents(container);
//Interactor style
const trackball = vtk.Interaction.Style.vtkInteractorStyleTrackballCamera.newInstance();
interactor.setInteractorStyle(trackball);
//disable_shortcuts
let interactorstyle = vtk.Interaction.Style.vtkInteractorStyleManipulator.newInstance();
interactorstyle.handleKeyPress = (callData) => {
const rwi = model.interactor;
let ac = null;
switch (callData.key) {
case 'r':
case 'R':
//callData.pokedRenderer.resetCamera();
//rwi.render();
break;
case 'w':
case 'W':
// ac = callData.pokedRenderer.getActors();
// ac.forEach((anActor) => {
// anActor.getProperty().setRepresentationToWireframe();
// });
//rwi.render();
// break;
break;
case 's':
case 'S':
// ac = callData.pokedRenderer.getActors();
// ac.forEach((anActor) => {
// anActor.getProperty().setRepresentationToSurface();
// });
//rwi.render();
break;
case 'v':
case 'V':
// ac = callData.pokedRenderer.getActors();
// ac.forEach((anActor) => {
// anActor.getProperty().setRepresentationToPoints();
// });
//rwi.render();
break;
default:
break;
}
};
//fullScreenRenderer.getInteractor().setInteractorStyle(interactorstyle);
//Pipeline
const cone  =   vtk.Filters.Sources.vtkConeSource.newInstance();
const actor =   vtk.Rendering.Core.vtkActor.newInstance();
const mapper=   vtk.Rendering.Core.vtkMapper.newInstance();
actor.setMapper(mapper);
mapper.setInputConnection(cone.getOutputPort());
renderer.addActor(actor);
//const LUT = vtk.Common.Core.vtkLookUpTable.newInstance();
//Render
renderer.resetCamera();
renderWindow.render();

我不知道js,但是C++我必须覆盖交互风格的交互类,我需要摆脱这些加速器。

例如,为了摆脱 vtkInteractorStyleTrackballCamera 的加速器,我覆盖了这个类,并重写了 OnKeyPress 处理程序。

下面是一个示例实现。

您需要创建自定义交互器样式才能实现此目的。 通过覆盖"onKeyPress(("函数来子类化交互器样式并处理按键事件,并且不转发按键事件。

如果需要转发事件,请调用父类"onKeyPress(("函数。

这里分享的代码是C++的,你可以将其转换为javascript。

// Creating the custom interaction style
class CustomInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CustomInteractorStyle* New();
vtkTypeMacro(CustomInteractorStyle, vtkInteractorStyleTrackballCamera);
// Override onKeyPress Function
virtual void OnKeyPress() override
{
vtkRenderWindowInteractor* renderWindowInteractor = this->Interactor;
switch (rwi->GetKeySym())
{
case "w":
{
// Handle the event on 'w' key press
break;
}
case "s":
{
// Handle the event on 's' key press
break;
}
case "v":
{
// Handle the event on 'v' key press
break;
}
case "r":
{
// Handle the event on 'r' key press
break;
}
default:
break;
}

// If you still want to forward the key press events
// After handling the events. this would be like addition
// Include the below statement
// vtkInteractorStyleTrackballCamera::OnKeyPress();
}
};
vtkStandardNewMacro(CustomInteractorStyle);

要让 VTK (9.0( 在内部停止处理按键,似乎需要覆盖 OnChar(( 虚拟函数,而不是 OnKeyPress。

例如:

// Creating the custom interaction style
class CustomInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CustomInteractorStyle* New();
vtkTypeMacro(CustomInteractorStyle, vtkInteractorStyleTrackballCamera);
// Override onChar Function
virtual void OnChar() override
{
vtkRenderWindowInteractor* renderWindowInteractor = this->Interactor;

//Disable vtk processing of 'e' press
if(ch != 'e')
{
vtkInteractorStyle::OnKeyPress();
}
}
};
vtkStandardNewMacro(CustomInteractorStyle);