首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用vtk的热键

如何禁用vtk的热键
EN

Stack Overflow用户
提问于 2020-06-27 14:49:30
回答 2查看 351关注 0票数 1

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

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

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

我怎么才能挺过去呢?

谢谢!

代码语言:javascript
复制
    <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();
EN

回答 2

Stack Overflow用户

发布于 2020-07-02 18:25:01

我不知道js,但在C++中,我必须重写interaction类的交互风格,因为我需要去掉这些加速器。

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

票数 1
EN

Stack Overflow用户

发布于 2020-07-03 04:07:39

下面是一个示例实现。

您需要创建一个自定义的交互器样式来实现这一点。继承交互器样式,通过重写'onKeyPress()‘函数来处理按键事件,并且不转发按键事件。

如果您需要转发事件,请调用父类'onKeyPress()‘函数。

这里分享的代码是用C++写的,你可以把它转换成javascript。

代码语言: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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62606866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档