Immersive Visualization / IQ-Station Wiki

This site hosts information on virtual reality systems that are geared toward scientific visualization, and as such often toward VR on Linux-based systems. Thus, pages here cover various software (and sometimes hardware) technologies that enable virtual reality operation on Linux.

The original IQ-station effort was to create low-cost (for the time) VR systems making use of 3DTV displays to produce CAVE/Fishtank-style VR displays. That effort pre-dated the rise of the consumer HMD VR systems, however, the realm of midrange-cost large-fishtank systems is still important, and has transitioned from 3DTV-based systems to short-throw projectors.

BuildingVTK

From IQ-Station Wiki
Jump to navigation Jump to search

Instructions for how to build VTK on Linux and MS-Windows, such that the VR features are enabled to the fullest extent. (And by "fullest extent", I mean having access to OpenXR, access to OpenVR, the vtkpython runtime, and possibly the VR collaboration feature.

(NOTE: These instructions based on the detailed instructions provided by Scott Wittenburg of Kitware.)

Building VTK on Linux

Building VTK on MS-Windows

First make sure to have the build system requirements, and then the necessary dependencies.

Note that I may have a peculiar way of arranging the build and install directories, which may not match your standard usage, so adjust to taste. (I usually put a Build directory below the source and then use cmake .. and then I create an installation directory that is a sibling to the source directory.)

Prerequisites

There are several build tools (and packages) required before building VTK:

  • Visual Studio 2019 — specifically, you need to use the command shell for configuring and building
    (it includes CMake and Ninja)
    use the search panel to find: x64 Native Tools Command Prompt for VS 2019
  • [optional] Git bash and/or Cygwin Terminal can be handy for standard Unix-style commands

Also will need these packages:

  • Python3 — needed for the live interaction
  • JsonCPP — needed for OpenXR
  • OpenXR-SDK — needed for OpenXR!
  • [optional] OpenVR-SDK — if you want to maintain the original VR option
  • [perhaps] QT — it's at least needed for ParaView, but may also be required for VTK
  • OpenMP 2.0 — only MPI supported by Visual Studio 2019 (not sure we need this for VTK)
  • [optional] ZeroMQ — needed for the ParaView collaboration feature

Installing Python3

For Python3, it's easy to just download an installer and follow the prompts.

Be sure to add Python 3.10 to %PATH%.

Building JsonCPP

(Also used by the ParaView build)

% cd C:\<project_dir>
% git clone https://github.com/open-source-parsers/jsoncpp.git jsonCpp
% mkdir jsonCpp\Build
% cd jsonCpp\Build
% cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH=C:<install_dir>\jsoncpp_Install ..
% ninja
% ninja install

Building OpenXR-SDK-Source

(Also used by the ParaView build)

% mkdir C:\<project_dir>\OpenXR-SDK
% cd C:\<project_dir>\OpenXR-SDK
% git clone https://github.com/KhronosGroup/OpenXR-SDK.git
% mkdir OpenXR-SDK\Build
% cd OpenXR-SDK\Build
% cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH=C:<install_dir>\OpenXR-SDK_Install -DJsonCpp_INCLUDE_DIR:PATH=C:<install_dir>\jsoncpp_Install\include -DJsonCpp_LIBRARY:FILEPATH=C:<install_dir>\jsoncpp_Install\lib\jsoncpp.lib -DDYNAMIC_LOADER:BOOL=ON ..
% ninja
% ninja install

Installing OpenVR-SDK [optional]

(Also used by the ParaView build)

% cd C:\<project_dir>
% git clone https://github.com/ValveSoftware/openvr.git
% mv openvr openvr_<version|date>

Building VTK

% mkdir -p C:\<project_dir>\VTK
% cd C:\<project_dir>\VTK
% git clone --recursive https://gitlab.kitware.com/vtk/vtk.git
% mkdir vtk\Build
% cd vtk\Build
% cmake -GNinja -DVTK_MODULE_ENABLE_VTK_RenderingOpenXR:STRING=WANT -DVTK_DEBUG_LEAKS:BOOL=ON -DPARAVIEW_USE_PYTHON:BOOL=ON -DPython3_EXECUTABLE:FILEPATH=/usr/bin/python3.6 -DVTK_BUILD_TESTING:STRING=WANT -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH=C:<install_dir>\vtk_Install -DOpenXR_INCLUDE_DIR:PATH=C:<install_dir>\OpenXR-SDK_Install\include\openxr -DOpenXR_LIBRARY:FILEPATH=C:<install_dir>\OpenXR-SDK_Install\lib\openxr_loader.lib ..
% ninja
% ninja install

Running VTK (on MS-Windows)

Once the build and installation completes, there are still some things that need to be taken care of. In particular, there are environment variables paths and JSON files that all must be properly configured.

Here is my %PATH% setting to run vtkpython and ctest:

% set PATH=%PATH%;C:\Users\wrs1\AppData\Local\Programs\Python\Python310;C:\Qt\5.12.12\msvc2017_64/bin;C:\Build\jsoncpp\install\bin;C:\Build\libzmq-4.3.4_Install\bin;C:\Build\OpenVR\openvr_20220130\bin\win64;C:\Build\OpenXR-SDK_20220128_Install\bin

To run the pre-built VTK Dragon test using CTest (I use Cygwin to get access to a real grep):

Cygwin% ctest -N | grep -i openxr
  Test   #59: VTK::RenderingOpenXR-HeaderTest
  Test  #143: VTK::RenderingOpenXRCxx-TestOpenXRInitialization
vs2019% ctest -R  VTK::RenderingOpenXRCxx-TestOpenXRInitialization --verbose
vs2019% C:\Build\vtk_20220128\build2\bin\vtkRenderingOpenXRCxxTests.exe "TestOpenXRInitialization" "-D" "C:/Build/vtk_20220128/build2/ExternalData/Testing" "-T" "C:/Build/vtk_20220128/build2/Testing/Temporary"

And then to run vtkpython:

% vtkpython
>>> import vtk

Running a simple VTK application in VR

To do a quick test of the vtkpython with an object (a colored sphere) appearing in VR. This example works regardless of the operating system VTK is running on.

(The Python prompts are left out to make it easier to copy and paste these commands directly into vtkpython.)

% vtkpython
import vtk

# Create the very simple scene (a colored sphere)
sphere = vtk.vtkSphereSource()
sphere.SetPhiResolution(12)
sphere.SetThetaResolution(12)
sphere.LatLongTessellationOn()
coloredSphere = vtk.vtkElevationFilter()
coloredSphere.SetInputConnection(sphere.GetOutputPort())
coloredSphere.SetLowPoint(0,0,-1)
coloredSphere.SetHighPoint(0,0,1)
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(coloredSphere.GetOutputPort())
sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)

# Setup and run in OpenVR -- or skip ahead for the OpenXR method
ren = vtk.vtkOpenVRRenderer()
ren.SetShowFloor(True)
ren.SetBackground(1,0,1)
ren.AddActor(sphereActor)
cam = vtk.vtkOpenVRCamera()
ren.SetActiveCamera(cam)
ren.RemoveCuller(ren.GetCullers().GetLastItem())
renwin = vtk.vtkOpenVRRenderWindow()
renwin.AddRenderer(ren)
iren = vtk.vtkOpenVRRenderWindowInteractor()
iren.SetRenderWindow(renwin)
iren.Start()

# Setup and run in OpenXR (instead of the OpenVR above)
ren = vtk.vtkOpenXRRenderer()
ren.SetShowFloor(True)
ren.SetBackground(1,0,1)
ren.AddActor(sphereActor)
cam = vtk.vtkOpenXRCamera()
ren.SetActiveCamera(cam)
ren.RemoveCuller(ren.GetCullers().GetLastItem())
renwin = vtk.vtkOpenXRRenderWindow()
renwin.AddRenderer(ren)
iren = vtk.vtkOpenXRRenderWindowInteractor()
iren.SetRenderWindow(renwin)
iren.Start()