Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Multilabel marching cubes and simplification of volumetric data.

Project description

zmesh: Multi-Label Marching Cubes & Mesh Simplification

Build Status PyPI version

from zmesh import Mesher

labels = ... # some dense volumetric labeled image
mesher = Mesher( (4,4,40) ) # anisotropy of image
mesher.mesh(labels) # initial marching cubes pass

meshes = []
for obj_id in mesher.ids():
  meshes.append(
    mesher.get_mesh(
      obj_id, 
      normals=False, # whether to calculate normals or not

      # tries to reduce triangles by this factor
      # 0 disables simplification
      simplification_factor=100, 

      # Max tolerable error in physical distance
      max_simplification_error=8
    )
  )
  mesher.erase(obj_id) # delete high res mesh

mesher.clear() # clear memory retained by mesher

mesh = meshes[0]
mesh = mesher.simplify(
  mesh, 
  # same as simplification_factor in get_mesh
  reduction_factor=100, 
  # same as max_simplification_error in get_mesh
  max_error=40, 
  compute_normals=False, # whether to also compute face normals
) # apply simplifier to a pre-existing mesh

mesh.vertices
mesh.faces 
mesh.normals
mesh.triangles() # compute triangles from vertices and faces

# Extremely common obj format
with open('iconic_doge.obj', 'wb') as f:
  f,write(mesh.to_obj())

# Common binary format
with open('iconic_doge.ply', 'wb') as f:
  f,write(mesh.to_ply())

# Neuroglancer Precomputed format
with open('10001001:0', 'wb') as f:
  f.write(mesh.to_precomputed())

Installation

If binaries are available for your system:

pip install zmesh

Requires a C++ compiler

sudo apt-get install python3-dev libboost-all-dev
pip install zmesh --no-binary :all:

Performance Tuning

  • The mesher will consume about double memory in 64 bit mode if the size of the object exceeds <511, 1023, 511> on the x, y, or z axes. This is due to a limitation of the 32-bit format. It might be possible to get x to 1023 as well.
  • Input labels are converted to uint32 or uint64. Use one of these data types to avoid a copy.
  • The mesher processes in C order.

Related Projects

  • zi_lib - zmesh makes heavy use of Aleks' C++ library.
  • Igneous - Visualization of connectomics data using cloud computing.

Credits

Thanks to Aleks Zlateski for creating and sharing this beautiful mesher.

Later changes by Will Silversmith, Nico Kemnitz, and Jingpeng Wu.

References

  1. W. Lorensen and H. Cline. "Marching Cubes: A High Resolution 3D Surface Construction Algorithm". pp 163-169. Computer Graphics, Volume 21, Number 4, July 1987.
  2. TK Quadratic Edge Collapse Paper

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for zmesh, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size zmesh-0.4.0-cp27-cp27m-macosx_10_14_intel.whl (245.6 kB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp27-cp27m-manylinux1_x86_64.whl (902.1 kB) File type Wheel Python version cp27 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp35-cp35m-manylinux1_x86_64.whl (907.3 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp36-cp36m-macosx_10_9_x86_64.whl (248.5 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp36-cp36m-manylinux1_x86_64.whl (919.2 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp36-cp36m-win_amd64.whl (216.1 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp37-cp37m-macosx_10_9_x86_64.whl (245.8 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp37-cp37m-manylinux1_x86_64.whl (917.0 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp37-cp37m-win_amd64.whl (216.0 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl (247.9 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size zmesh-0.4.0-cp38-cp38-manylinux1_x86_64.whl (920.3 kB) File type Wheel Python version cp38 Upload date Hashes View hashes
Filename, size zmesh-0.4.0.tar.gz (282.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page