Web

Several technologies enable 3D visualization to take place in a web page, but none offer the same level of capabilities as VTK. So, how do you bring decades of C++ development to the ever-changing web? Through two libraries, which can work together or independently to help you achieve your goals: vtkWeb and vtk.js.

vtkWeb

vtkWeb drives the C++ implementation of VTK through a web server via its Python wrapping. As a full package, it can leverage the complete input/output, data processing, and rendering capabilities of VTK.

Based on its infrastructure, vtkWeb allows a front-end client and a server to communicate. In particular, it enables method calls (RPCs) and publish/subscribe types of communication. On top of the generic communication infrastructure, vtkWeb provides protocol for vtkRenderWindow synchronization. As a result, interactions reflect both in the web page and on the server where the data lives.

Example Application

ParaView Visualizer is a version of ParaView Qt for the web browser. Since ParaView works with large data, ParaView Visualizer lends itself to remote processing, which permits either remote or local rendering (depending on the data size).

Better documentation and additional examples of how to leverage the vtkWeb infrastructure will be priorities of future development. Another priority will be to create Docker or container images to expedite the deployment of vtkWeb’s infrastructure in a cloud environment.

vtk.js

vtk.js is a re-implementation of VTK/C++ in JavaScript that leverages WebGL and focuses on geometry rendering and volume rendering. On top of its rendering aspect, vtk.js offers the same pipeline infrastructure as its C++ father. While vtk.js embraces JavaScript, it tries to keep the same vocabulary and application programming interface as VTK, so it remains familiar to VTK users. In terms of classes, vtk.js uses vtkPolyData and vtkImageData for its rendering pipeline. It also offers a handful of readers (e.g., VTP, VTI, STL, OBJ, etc.) and filters.

vtk.js: the Visualization Toolkit on the Web

ParaView Glance illustrates vtk.js for visualizing data. It provides a clean user interface for controlling what gets rendered for a wide variety of datasets. You can consider it as a best-practice example for using vtk.js.

Where to go From Here

vtkWeb and vtk.js are tools for building visualization applications. To make the best design decision, it is important that you carefully understand all parameters. Considerations include the data size, the network capability, the number of concurrent users, the type of rendering, the devices on which the application will run, and the types of computation needed. To help you build your application, Kitware offers consulting and development services.

AR and VR

VTK includes built-in support for developing VR applications. The support works with HTC Vive, Oculus Rift, and various Windows Mixed Reality headsets. It leverages the OpenVR standard, so it is easy to use,if you are familiar with VTK.

The data in this image comes from “Blondin, John & Mezzacappa, Anthony. (2007). Pulsar spins from an instability in the accretion shock of supernovae. Nature. 445. 58-60. 10.1038/nature05428.”

To start using VTK in VR, first download and install the OpenVR SDK. Also check that you are set up to use a recent version of VTK, as older versions may not work with current device drivers. Once you configure VTK and turn on the modules you desire, you can begin the build process. To maximize performance, try building an optimized version of the software platform.

As for existing applications, most can leverage VTK’s VR support with minimal changes to their codebase. Just link your executable to the vtkRenderingOpenVR module, and change four classes (renderWindow, renderer, interactor, and camera) to specifically create them as OpenVR. All other classes, such as actors and mappers, can remain unchanged.

Two classes, vtkOpenVRRenderWindow and vtkOpenVRRenderWindowInteractor, deserve some additional comments.

vtkOpenVRRenderWindow
The vtkOpenVRRenderWindow class handles the bulk of the interaction with OpenVR. It currently supports one renderer that covers the entire window. It also holds the transformation from physical space (e.g., a room) to world coordinates for your visualization. Four methods perform the mapping: SetPhysicalScale, SetPhysicalTranslation, SetPhysicalViewUp, and SetPhysicalViewDirection.

Physical space is measured in meters, and the origin is located on the floor in the middle of the room. If the world coordinates are measured in light years, for example, you can use PhysicalScale to scale them down to a suitable size for the room. The convenience method ResetCamera() on vtkOpenVRRenderer is responsible for computing a reasonable value for PhysicalScale and PhysicalTranslation.

vtkOpenVRRenderWindowInteractor
While VTK is designed to pick and interact based on X,Y mouse/window coordinates, OpenVR provides six-degrees-of-freedom events that contain X,Y,Z world coordinates and W,X,Y,Z orientations. The vtkOpenVRRenderWindowInteractor class handles these VR controller events and forwards them to the widgets in VTK.

Applications

VTK’s support for VR is employed by applications such as ParaView. ParaView is Kitware’s scientific visualization application. It has an OpenVR plugin that allows you to send a visualization to VR for immersive viewing. For Windows, ParaView binaries come with the plugin prebuilt.

Taking ParaView into Virtual Reality

3D Slicer is another application that employs VTK’s support for VR. 3D Slicer visualizes medical datasets for training and surgical planning. It can simulate bilateral sagittal split osteotomy, visualize anatomy, and help doctors prepare for biopsies.

Bringing Virtual Reality to 3D Slicer

As VR hardware and software continue to change, Kitware is happy to help you leverage VR in new application domains through support, custom development, unique capabilities, and future research programs. For more information, please contact Kitware.