Skip to content

navis-org/sparse-cubes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sparse-cubes

Mesh generation for (N, 3) voxel indices - i.e. the equivalent of a 3D sparse matrix in COOrdinate format - using a simple dual contouring implementation

Running dual contouring directly on sparse voxels is faster and importantly much more memory efficient than converting to a dense 3d matrix and using marching cubes from e.g. sklearn.

In brief, dual contouring produces sharper meshes than marching cubes by placing vertices at the edges of voxels rather than the centers:

Dual Contouring Example

Please see this blog for an excellent introduction to dual contouring. See also notes at the end of the README.

Install

Install latest version from PyPI:

pip3 install sparse-cubes -U

To install the developer version from Github:

pip3 install git+https://github.com/navis-org/sparse-cubes.git

The only dependencies are numpy and trimesh. Will use fastremap if present.

Usage

>>> import sparsecubes as sc >>> import numpy as np >>> # Indices for two adjacent voxels >>> voxel_xyz = np.array([[0, 0, 0], ... [0, 0, 1]], ... dtype='uint32') >>> m = sc.dual_contour(voxel_xyz) >>> m <trimesh.Trimesh(vertices.shape=(12, 3), faces.shape=(20, 3))> >>> m.is_winding_consistent True

Notes

  • The mesh might have non-manifold edges. Trimesh will report these meshes as not watertight but in the very literal definition they do hold water.
  • This implementation is very basic; I never looked into how to optimize vertex placement which is why we get a stepped appearance on diagonal surfaces.

About

Marching cubes for sparse matrices

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages