/Contour3D

Library-independent streamlined 3D contouring for massively-parallelised CFD simulations

Primary LanguageCMIT LicenseMIT

Contour 3D

CI License LastCommit

https://github.com/NaokiHori/Contour3D/blob/main/.github/thumbnail.jpg

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 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.

Caveat

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.

Dependency

Quick start

  1. Prepare workplace

    mkdir -p /path/to/your/directory
    cd       /path/to/your/directory
  2. 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.

  3. Build

    make clean
    make all
  4. Execute

    mpirun -n 2 --oversubscribe ./a.out

    This may take a few seconds. Change the number of processes depending on your machine spec.

  5. Check output

    Find output.ppm, which is the result of the 3D contouring:

    https://github.com/NaokiHori/Contour3D/blob/artifact/output.jpg

Detail

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:

  1. Array extension

    Edges of the given three-dimensional array are communicated among all processes to avoid gaps.

  2. Tessellation

    From the extended three-dimensional array, each process extracts triangular elements and their surface normals using the marching-tetrahedra algorithm.

  3. Smoothing

    Vertex normals are computed by averaging the surface normals of the neighbouring triangles to obtain a smoother result.

  4. Rendering

    Decide the color of each element based on the direction of the light and the local normal vector interpolated on each barycentric coordinate.

  5. 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.

Reference

Acknowledgement

I would like to thank Prof. Roberto Verzicco for a stimulating lecture in the JMBC course Multiphase Flow and Phase Transitions.