← All projects

Science

3D topology

Meshes in a 3D viewer, with topological analysis.

Done Sprint S4-S5+S36-S41+S43 · 36 points
In short, no jargon for non-developersRead the summaryClose
What it is
A tool that analyses the shape of 3D objects (a ring, a sphere, a Möbius strip): how many holes they have, where they bend, how their shape builds up when they are filled from the bottom up.
What it is for
Such measurements are used in medical imaging, simulation and industrial design, to compare and check shapes.
What it shows
My core trade, as a PhD in computer graphics: demanding mathematics turned into a fast, checked tool you handle with the mouse.

My PhD topic

Source code

How the pieces fit together

Diagram: lib-c → Topology (mesh read) ; Topology → C API (invariants, curvature) ; C API → WebAssembly ; WebAssembly → Viewer ; C API → Python API (shared library). mesh read invariants, curvature shared library lib-c reads OBJ, PLY, STL Topology C++20, half-edges C API a single interface WebAssembly Emscripten Viewer three.js, on the page Python API FastAPI, ctypes

Spin a mesh

Colour shows the Gaussian curvature at each vertex. Invariants and curvature are computed by the project's C++ code, compiled to WebAssembly, in your browser.

Samples:

Colouring

Drag to rotate, scroll or pinch to zoom; hover a point to read its curvature. The gizmo at the bottom left follows the camera: x in red, y in green, z in blue.

On the boundary the angle defect measures how the boundary itself bends: boundary vertices take the colour of their interior neighbours.

Computing times

Measured on a standing torus, best of 3 runs, on one thread of an Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz: native (C++ built in Release by GCC) and WebAssembly (the same code, in Node, as in the page). Produced by projects/topologie/scripts/bench.mjs.

TrianglesOBJ fileReading (Wasm)HeightPersistenceReeb graphExtended persistence
10,0000.3 MB24 ms2 ms native · 2 ms Wasm8 ms native · 10 ms Wasm5 ms native · 6 ms Wasm15 ms native · 17 ms Wasm
30,0001.0 MB75 ms5 ms native · 6 ms Wasm26 ms native · 37 ms Wasm14 ms native · 19 ms Wasm57 ms native · 60 ms Wasm
100,0003.5 MB251 ms24 ms native · 24 ms Wasm116 ms native · 174 ms Wasm56 ms native · 68 ms Wasm231 ms native · 248 ms Wasm
300,00010.8 MB788 ms76 ms native · 76 ms Wasm502 ms native · 736 ms Wasm178 ms native · 204 ms Wasm945 ms native · 968 ms Wasm
1,000,00037.6 MB2.72 s281 ms native · 280 ms Wasm2.38 s native · refused by the page648 ms native · refused by the page4.32 s native · refused by the page

What about a GPU? It would speed up what is done vertex by vertex or triangle by triangle, independently: the height (one dot product per vertex), sorting the vertices (parallel sort), the lower link of each vertex, and H0 persistence by parallel merges. The boundary matrix reduction, though, handles the columns one after the other (each depends on the previous ones), and the Reeb graph relies, like H0 persistence, on union-finds with unpredictable accesses: a GPU would spend its time synchronising. Yet persistence dominates (2.38 s for a million triangles natively) and it is the part that suits a GPU least: no GPU version (D49).

Why 32 MB? Before any computing, reading an OBJ of 37.6 MB (a million triangles) takes 2.72 s in WebAssembly, on the page’s thread, which stays frozen meanwhile; WebAssembly memory climbs to about 190 MB (750 MB for 4 million triangles), capped at 1 GB by the build and at 4 GB in wasm32, and a phone has less. The limit keeps the wait under two and a half seconds; lifting it would take streamed reading in a Web Worker and more memory (D49). Above 300,000 triangles, the page also refuses persistence, its extended version and the Reeb graph: half a second at that cap, one second for extended persistence.

Tech stack

  • C++
  • Three.js
  • GoogleTest

Who does what

C++
The half-edge structure, the invariants (Euler, genus, boundaries, orientability), the Gaussian curvature, the height, its critical points (discrete Morse theory) its persistence (boundary matrix reduction) and its Reeb graph; compiled to WebAssembly by Emscripten for the viewer, and to a shared library for the Python API.
Three.js
The project page viewer: the mesh coloured by its curvature or its height, filtered under a threshold, its critical points marked, its Reeb graph drawn inside, turned with the mouse or a finger.
GoogleTest
The C++ tests: invariants of the reference meshes, curvature against theoretical values, critical points (sphere, torus, monkey saddle, indices summing to χ), persistence (Betti numbers, stability), Reeb graph (loops equal to the genus), on Linux, Windows and macOS.

Definition of Done

  • Code reviewed, diff by diff
  • Unit and integration tests green
  • Green CI on Linux, Windows and macOS when compiled
  • README, REVIEW.md and DECISIONS.md up to date
  • Texts in French and English
  • Demo deployed and tested on mobile