1

I want to disable some hotkey on vtk. Actually i'm using vtk.js, but it's OK to tell me in the normal vtk way.

I want to disable the hotkey belows here: "W": Toggle region of interest (ROI) selection widget "S": Toggle slicing planes in volume rendering mode "V": Toggle to dot form "R": Reset camera

I tried set InteractorStyleManipulator on OpenGLRenderwindow, and tried fullScreenRender way. but it doesn't work though.

How could I get through it?

Thank You!

    <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();

3 Answers3

1

I don't know js, but in C++ I have to overriden the interaction class for interaction style where I need to get rid of these accelerators.

For instance, to get rid of accelerators from vtkInteractorStyleTrackballCamera, I overridden this class, and I over write OnKeyPress handler.

Flaviu_
  • 1,285
  • 17
  • 33
1

Here is an example implementation.

You need to create a custom interactor style to make this possible. Subclass the interactor style and handle the key press events by overriding the 'onKeyPress()' function and don't forward the key press events.

If you need to forward the events, call the parent class 'onKeyPress()' function.

The code shared here is in C++, you can convert the same to 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);
Ravi
  • 179
  • 3
  • 14
0

To have VTK (9.0) stop processing a key press internally, it seems that the OnChar() virtual function need to be overridden, not OnKeyPress.

For example:

// 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);
Totte Karlsson
  • 1,261
  • 1
  • 20
  • 55