Why changing example to port it to VR doesn't work?

I cloned the latest VTK 9.0 version from your Github repo and build it with OpenVR and SDL2 enabled. I’m using Windows 10 and Microsoft Visual Studio 2019. I’m able to build RayCastIsosurface example without any problem and run it also without any runtime error. I wanted to port this 3D volume rendering into my HTC Vive VR headset by changing these renderers to OpenVR:

  • vtkRenderWindowvtkOpenVRRenderWindow
  • vtkRenderWindowInteractorvtkOpenVRRenderWindowInteractor
  • vtkRenderervtkOpenVRRenderer
  • vtkCameravtkOpenVRCamera

Again build is successful but when I run the program it doesn’t show anything. Even it doesn’t show any error. It just exits without any information about why the program is terminated.

Any idea why it happens? By the way, I have ParaView 5.9 with OpenVR and I’m able to see 3D renderings in my VR headset without any problem. So, I’m 100% confident that nothing is wrong with my SteamVR.

You might want to give VTK master a try. VTK 9.0 (unfortunately) is pretty old at this point.

Also I don’t think we rely on SDL2 for the VR stuff anymore. So you shouldn’t need it (at least with VTK master)

I used the current head at the master branch of the VTK. But, still have this problem.

I created a simple code to reproduce this problem, and still, it doesn’t show anything:

#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkNew.h>
#include <vtkOpenVRCamera.h>
#include <vtkOpenVRInteractorStyle.h>
#include <vtkOpenVRRenderer.h>
#include <vtkOpenVRRenderWindow.h>
#include <vtkOpenVRRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>

int main(int argc, char* argv[])
{
  // Setup the OpenVR rendering classes
  vtkNew<vtkActor> actor;
  vtkNew<vtkOpenVRRenderer> renderer;
  vtkNew<vtkOpenVRRenderWindow> renderWindow;
  vtkNew<vtkOpenVRRenderWindowInteractor> iren;
  vtkNew<vtkOpenVRInteractorStyle> style;
  vtkNew<vtkOpenVRCamera> cam;

  renderWindow->AddRenderer( renderer.Get() );
  renderer->AddActor( actor.Get() );
  iren->SetRenderWindow( renderWindow.Get() );
  iren->SetInteractorStyle( style.Get() );
  renderer->SetActiveCamera( cam.Get() );

  // Without the next line volume rendering in VR does not work
  renderWindow->SetMultiSamples( 0 );

  // Add a cone to the scene
  vtkNew<vtkConeSource> cone;
  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputConnection( cone->GetOutputPort() );
  actor->SetMapper( mapper.Get() );

  // Render
  renderer->ResetCamera();
  renderWindow->Render();
  iren->Start();

  return EXIT_SUCCESS;
}

I just checked the dragon test on my vtk master build and it worked fine. I started steamvr first then I ran it as

C:\Users\ken.martin\Documents\vtk\bin>bin\vtkRenderingOpenVRCxxTests.exe “TestDragon” “-D” “C:/Users/ken.martin/Documents/vtk/bin/ExternalData/Testing” “-T” “C:/Users/ken.martin/Documents/vtk/bin/Testing/Temporary” -I

Not sure what is off on your example but if you can get the dragon test working maybe that will give you a reference. You might need to copy the controller files into your bin directory. e.g.

01/29/2021  11:33 AM             1,652 vtk_openvr_actions.json
01/25/2021  12:46 PM             2,303 vtk_openvr_binding_hpmotioncontroller.json
01/29/2021  11:33 AM             1,760 vtk_openvr_binding_oculus_touch.json
01/25/2021  01:14 PM             1,908 vtk_openvr_binding_vive_controller.json

I’m able to run the dragon test without any problem on my computer.

If you change your example to use a surface (such as a cone + mapper + actor) instead of a volume does your example work? Just wondering if it is specific to volume rendering.

No, it doesn’t work if I use a cone instead of volume rendering.

That’s good. Now you’ve got a working example using polydata and a non working example that’s basically the same. Should be able to track down what the issue is by looking at what is different, making them more similar until something changes etc.

1 Like

Thank you for your help!

If you are still having issues one thing I thought of was the autoinit code. For vtk tests the autoinit code is added automatically. It handles setting up the object factory for runtime object creation for classes that need it. In your project’s cmakelists file you add something like

vtk_module_autoinit(
    TARGETS yourexecutable
    MODULES 
            VTK::RenderingOpenGL2
            )