SPH visualization with volume rendering

This animation shows volume rendering of an SPH (smooth particle hydrodynamics) simulation of galaxy formation by Fabrice Durier (UVic) contaning 12 million particles, with dataset coloured by the density. The goal here was to render the hydrodynamical variables in a smooth way, despite the particle nature of the dataset. For this visualization, we constructed a Delaunay tessellation of the particle distribution using qhull and stored it as an Unstructured Grid VTK file, with 80 million tetrahedral cells. This file was then read by ParaView and rendered as a volume. The entire movie containing 1800 frames was rendered on a laptop, taking about 1 minute per frame, but can be easily rendered on a cluster to speed up the process.

Note that performing the Delaunay tessellation on particles is useful primarily for volumetric rendering, as other views (slice, clip) are likely to show artifacts from the Delaunay tessellation in the form of long edges. Also, it is important to point out that the Delaunay tessellation is unique for a randomized set of points. For equidistant points sitting on a 3D Cartesian mesh one can pick a Delaunay tessellation, but ParaView will have trouble processing it leading to crashes and/or segmentation errors, so for this type of rendering one must avoid equally spaced particles.

Workflow details

While qhull has a C++ interface, it is not well documented yet, so we perform this visualization using qhull’s command-line tools. Please install qhull on your machine before proceeding.

We assume that particles are stored in a text file called qhullParticles.txt in the following format:

where the first line stores the number of dimensions, the second line the number of particles, and the rest store particle x,y,z coordinates with one particle per line. The 3D scalar fields (pressure, density, etc.) should be stored in a file named qhullFields.txt with one particle per line as follows:

Compute the Delaunay tessellation with the bash command “qvoronoi TI qhullParticles.txt TO qhullTetrahedra.txt TF100000 i”. This will place the faces of the Delaunay tetrahedra into qhullTetrahedra.txt. Next compile and run the code to convert the data to VTK:

You’ll need VTK 6.0 or higher. Here is the makefile to compile this code on WestGrid’s Parallel cluster:

The code will read qhullTetrahedra.txt, qhullParticles.txt and qhullFields.txt and will store the particles and tessellation in an UnstructuredGrid VTK file called a1.vtu. It assumes that you have two scalar variables per particle named pressure and density — you can adapt it to your own data. Import the output VTK file into ParaView, switch to a volume view, and edit the colour map.

To produce the spin animation seen above, add to your ParaView’s Python code:

where firstFrame and lastFrame give the start/end positions of the spin in degrees, and 0.2 is the rotation step in degrees.

Future work

This single-timestep visualization can be extended to show multiple timesteps, with cosmic structures evolving in time. The camera position can be adjusted to show fly-throughs, zoom-ins on individual galaxies, etc. Other quantities such as temperature and metallicity can be added to the visualization. In addition, the algorithm can scale to billions of particles and beyond, if one uses adaptive tessellation to roughly match the number of resolution elements to the number of pixels on the screen.

The tessellation artifacts near one of the edges of the box (large red cells), appearing due to a high-density region located near that edge, can be removed by introducing ghost cells on the outside such that no high-density region is truncated by the boundary.


This visualization was developed by Alex Razoumov (WestGrid, Compute Canada).