Skip to content

janelia-flyem/vol2mesh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vol2mesh

A mesh generating wrapper in Python 3, with optional simplification and draco compression.

Installation

conda install -c flyem-forge vol2mesh

Python usage

Example:

from vol2mesh import Mesh, mesh_from_array, concatenate_meshes

# Creation from binary vol (via marching cubes)
# For some binary ndarray 'binary_array'
binary_vol = ...

box = [(0,0,0), (binary_vol.shape)]
mesh = Mesh.from_binary_vol( binary_vol, box )

# Alternative: Creation from file(s)/buffer
mesh2 = Mesh.from_file( '/path/to/mesh.drc' )
mesh3 = Mesh.from_directory( '/path/to/meshes/' )
mesh4 = Mesh.from_bytes( obj_bytes, 'obj' )

# Basic ops
mesh.laplacian_smooth(3)
mesh.simplify(0.2)

# alternative implementation of simplify(), based on OpenMesh
mesh.simplify_openmesh(0.2)

# Serialize to disk
mesh.serialize('/tmp/my-mesh.obj')
mesh.serialize('/tmp/my-mesh.drc')

# Serialize to buffer
mesh_bytes = mesh.serialize(fmt='drc')

# Combine meshes (with proper vertex renumbering in the faces)
combined_mesh = concatenate_meshes([mesh1, mesh2, mesh3])

# Optional: Deduplicate vertices
combined_mesh.stitch_adjacent_faces()

# Less common ops
mesh.drop_normals()
mesh.drop_unused_vertices()
mesh.recompute_normals()

Appendix: Dependencies

  • Mesh decimation is performed via the pyfqmr-Fast-Quadric-Mesh-Reduction/tree/master package:
  • We support the draco compressed mesh serialization format via functions from dvidutils. Technically, this is an optional dependency, even though our conda recipe pulls it in. If you want to run this code on Windows, just drop the dvidutils requirement and everything in the vol2mesh code base works without it except for draco.
  • The default marching cubes implementation is from the ilastik project's marching_cubes library.
    • Optionally, we support skimage.marching_cubes_lewiner() as an alternative, but you must install scikit-image yourself (it is not pulled in as a required dependency.

About

A mesh generating wrapper in Python 3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%