Home

Awesome

Differentiable Iso-Surface Extraction Package (DISO)

[News] DISO now supports batch training and checkpointing! It is no longer necessary to allocate multiple iso-surface extractors.

This repository consists of a variety of differentiable iso-surface extraction algorithms implemented in cuda.

Currently, two algorithms are incorporated:

The differentiable iso-surface algorithms have multiple applications in gradient-based optimization, such as shape, texture, materials reconstruction from images.

Installation

Requirements: torch (must be compatible with CUDA version), trimesh

pip install diso

Quick Start

You can effortlessly try the following command, which converts a sphere SDF into triangle mesh using different algorithms. The generated results are saved in out/.

python test/example.py

Note:

<p align="center"> <img src="imgs/example.png" alt="four_examples" width="600" /> </p>

Usage

All the functions share the same interfaces. Firstly you should build an iso-surface extractor as follows:

from diso import DiffMC
from diso import DiffDMC

diffmc = DiffMC(dtype=torch.float32).cuda() # or dtype=torch.float64
diffdmc = DiffDMC(dtype=torch.float32).cuda() # or dtype=torch.float64

Then use its forward function to generate a single mesh:

verts, faces = diffmc(sdf, deform, normalize=True)  # or deform=None
verts, faces = diffdmc(sdf, deform, return_quads=False, normalize=True)  # or deform=None

Input

Output

The gradient will be automatically computed when backward function is called.

Batch Training

You can loop over the batch size to conduct an iso-surface extraction on each object, then compute the loss for the backward pass.

extractor = DiffMC(dtype=torch.float32).cuda()  # or DiffDMC
for bs in range(batchsize):
    verts, faces = extractor(sdf, deform)
    # compute and accumulate losses
loss.backward()

Note: It is suggested to create the extractors outside the epoch loop so that they can be reused by different iterations and avoid allocating memory every time.

Speed Comparison

We compare our library with DMTet [3] and FlexiCubes [4] on two examples: a simple round cube and a random initialized signed distance function.

<p align="center"> <img src="imgs/speed.png" alt="speed_example" width="400" /> </p>

The algorithms have been rigorously tested on an NVIDIA RTX 4090 GPU. Each algorithm underwent 100 repeated runs, and the table presents the time and CUDA memory consumption for a single run.

Round CubeDMTetFlexiCubesDiffMCDiffDMC
# Vertices19622194241994419946
# Faces39240388443988439888
VRAM / G1.575.400.600.60
Time / ms9.6110.001.541.44
Rand Init.DMTetFlexiCubesDiffMCDiffDMC
# Vertices2597474278527426510462713134
# Faces4774241436484247173844431380
VRAM / G3.074.070.590.45
Time / ms49.1065.352.552.78

Citation

If you find this repository useful, please cite the following paper:

@article{wei2023neumanifold,
  title={NeuManifold: Neural Watertight Manifold Reconstruction with Efficient and High-Quality Rendering Support},
  author={Wei, Xinyue and Xiang, Fanbo and Bi, Sai and Chen, Anpei and Sunkavalli, Kalyan and Xu, Zexiang and Su, Hao},
  journal={arXiv preprint arXiv:2305.17134},
  year={2023}
}

Reference

[1] We L S. Marching cubes: A high resolution 3d surface construction algorithm[J]. Comput Graph, 1987, 21: 163-169.

[2] Nielson G M. Dual marching cubes[C]//IEEE visualization 2004. IEEE, 2004: 489-496.

[3] Shen T, Gao J, Yin K, et al. Deep marching tetrahedra: a hybrid representation for high-resolution 3d shape synthesis[J]. Advances in Neural Information Processing Systems, 2021, 34: 6087-6101.

[4] Shen T, Munkberg J, Hasselgren J, et al. Flexible isosurface extraction for gradient-based mesh optimization[J]. ACM Transactions on Graphics (TOG), 2023, 42(4): 1-16.