Contour3D
Library-independent streamlined 3D contouring for massively-parallelized CFD simulations
Install / Use
/learn @NaokiHori/Contour3DREADME
Contour 3D
Overview
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.
Caveat
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.
Camera and Screen Configurations
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.
Dependencies
- C compiler
- GNU Make
- MPI
- Simple Decomp (included as a submodule)
Quick Start
-
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 Contour3DDo not forget to fetch the submodule as well.
-
Build
make clean make all -
Execute
mpirun -n 2 --oversubscribe ./a.outThis may take a few seconds. Change the number of processes depending on your machine's specifications.
-
Check the output
Find
<img src="https://github.com/NaokiHori/Contour3D/blob/artifact/output.jpg" alt="Sample Image" width="80%" />output.ppm, which is the result of the 3D contouring:
Method
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.
References
- Ray Tracing in One Weekend
- Marching tetrahedra
- Polygonising a scalar field
- Scratchapixel
- Tessellation (computer graphics)
- Barycentric coordinate system
Acknowledgement
I would like to thank Prof. Roberto Verzicco for a stimulating lecture in the JMBC course Multiphase Flow and Phase Transitions.
