This library performs 3D contouring by extracting iso-surfaces from three-dimensional arrays and outputting the result as a portable pixmap (ppm
) image.
The objective is to visualise three-dimensional flow fields simulated on massively parallelised CFD solvers (available at here) without saving the full three-dimensional arrays. By embedding this library into the existing flow solver, one can easily create movies without worrying about storage limitations.
This library does not have any additional dependencies on X, Qt, VTK, OpenGL, etc., making the initial cost minimal.
The motivation of this project is to visualise the (flow) fields quickly and intuitively without the support of graphical libraries. For beautiful and comprehensive renderings, use other software options that offer more features.
- C compiler
- GNU Make
- MPI
- Simple Decomp Library (included as a sub-module)
Prepare workplace
mkdir -p /path/to/your/directory cd /path/to/your/directory
Get source
For example:
git clone --recurse-submodules https://github.com/NaokiHori/Contour3D cd Contour3D
Do not forget to fetch the sub-module as well.
Build
make clean make all
Execute
mpirun -n 2 --oversubscribe ./a.out
This may take a few seconds. Change the number of processes depending on your machine spec.
Check output
Find
output.ppm
, which is the result of the 3D contouring:
See src/main.c
to investigate how the contours, the camera, the light, and the screen are configured.
Basically this library does the following things:
Array extension
Edges of the given three-dimensional array are communicated among all processes to avoid gaps.
Tessellation
From the extended three-dimensional array, each process extracts triangular elements and their surface normals using the marching-tetrahedra algorithm.
Smoothing
Vertex normals are computed by averaging the surface normals of the neighbouring triangles to obtain a smoother result.
Rendering
Decide the color of each element based on the direction of the light and the local normal vector interpolated on each barycentric coordinate.
Reduction
Among all processes, find the nearest triangular element to the screen and output the result to an image.
The steps 1-4 are repeated if multiple arrays and/or thresholds are given.
See src/contour3d/main.c
to check the overall procedures.
- Ray Tracing in One Weekend
- Marching tetrahedra
- Polygonising a scalar field
- Scratchapixel 3.0
- Tessellation (computer graphics)
- Barycentric coordinate system
I would like to thank Prof. Roberto Verzicco for a stimulating lecture in the JMBC course Multiphase Flow and Phase Transitions.