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 visualize three-dimensional flow fields simulated on massively parallelized CFD solvers (available 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 for this project is to visualize 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.
Finding the optimal positions and orientations for the screen and camera can often be challenging. To address this, I offer a simple web application that allows you to adjust these parameters interactively.
- C compiler
- GNU Make
- MPI
- Simple Decomp (included as a submodule)
-
Prepare the workspace
mkdir -p /path/to/your/directory cd /path/to/your/directory
-
Get the source
git clone --recurse-submodules https://github.com/NaokiHori/Contour3D cd Contour3D
Do not forget to fetch the submodule 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's specifications.
-
Check the 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.
This library essentially performs the following steps:
-
Array extension
The 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 neighboring triangles to obtain a smoother result.
-
Rendering
The color of each element is decided based on the direction of the light and the local normal vector interpolated on each barycentric coordinate.
-
Reduction
Among all processes, the nearest triangular element to the screen is found, and the result is output to an image.
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
- 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
.