我想在vtk上禁用一些热键。实际上我使用的是vtk.js,但也可以用普通的vtk方式告诉我。
我想在这里禁用下面的热键:"W":切换感兴趣区域(ROI)选择小部件"S":切换体渲染模式下的切片平面"V":切换到点形式"R":重置相机
我尝试了在OpenGLRenderwindow上设置InteractorStyleManipulator,并尝试了fullScreenRender方式。但它并不起作用。
我怎么才能挺过去呢?
谢谢!
<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();发布于 2020-07-02 18:25:01
我不知道js,但在C++中,我必须重写interaction类的交互风格,因为我需要去掉这些加速器。
例如,为了摆脱vtkInteractorStyleTrackballCamera中的加速器,我重写了这个类,并重写了OnKeyPress处理程序。
发布于 2020-07-03 04:07:39
下面是一个示例实现。
您需要创建一个自定义的交互器样式来实现这一点。继承交互器样式,通过重写'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);https://stackoverflow.com/questions/62606866
复制相似问题