Multilabel marching cubes and simplification of volumetric data.
Project description
zmesh: Multi-Label Marching Cubes & Mesh Simplification
from zmesh import Mesher
labels = ... # some dense volumetric labeled image
mesher = Mesher( (4,4,40) ) # anisotropy of image
# initial marching cubes pass
# close controls whether meshes touching
# the image boundary are left open or closed
mesher.mesh(labels, close=False)
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,
# whether meshes should be centered in the voxel
# on (0,0,0) [False] or (0.5,0.5,0.5) [True]
voxel_centered=False,
)
)
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
# compute normals without simplifying
mesh = mesher.compute_normals(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 and boost
Note that you may need to set the environment variable BOOST_ROOT
.
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 <1023, 1023, 511> on the x, y, or z axes. This is due to a limitation of the 32-bit format.
- The mesher is ambidextrous, it can handle C or Fortran order arrays.
- The maximum vertex range supported
.simplify
after converting to voxel space is 220 (appx. 1M) due to the packed 64-bit vertex format.
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
- 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. (link)
- M. Garland and P. Heckbert. "Surface simplification using quadric error metrics". SIGGRAPH '97: Proceedings of the 24th annual conference on Computer graphics and interactive techniques. Pages 209–216. August 1997. doi: 10.1145/258734.258849 (link)
- H. Hoppe. "New Quadric Metric for Simplifying Meshes with Appearance Attributes". IEEE Visualization 1999 Conference. pp. 59-66. doi: 10.1109/VISUAL.1999.809869 (link)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zmesh-1.4.2.tar.gz
(324.2 kB
view hashes)
Built Distributions
zmesh-1.4.2-cp310-cp310-win_amd64.whl
(248.2 kB
view hashes)
zmesh-1.4.2-cp39-cp39-win_amd64.whl
(248.2 kB
view hashes)
zmesh-1.4.2-cp38-cp38-win_amd64.whl
(248.1 kB
view hashes)
zmesh-1.4.2-cp37-cp37m-win_amd64.whl
(246.2 kB
view hashes)
zmesh-1.4.2-cp36-cp36m-win_amd64.whl
(245.6 kB
view hashes)
Close
Hashes for zmesh-1.4.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e1f4e5f6418b85bb5589e60199bd97e21816df2595e8804df6afde5bdeeb8d0 |
|
MD5 | 0f856c69d31c9fb8b7a13500f2cad947 |
|
BLAKE2b-256 | 1774aca57b4b8a6823d6b49c4618914ac03961ea38a1bb573698713f2c0d09b8 |
Close
Hashes for zmesh-1.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34ec7065e4994d823f74620aa4e07420cd1dfd17cd538ef6e97a012c1faa1f3f |
|
MD5 | cf49053f60549e93abcd1f5a27f0848a |
|
BLAKE2b-256 | f223214b360449fa6a4d72a00cf97b560d2829890d76ad4abc7a9d33e70d27af |
Close
Hashes for zmesh-1.4.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d9ea802d010e5f70c4184a34c1bc536c6ba738bdce586878a78d6f1b5987886 |
|
MD5 | 1567253d3733bfebcf9ce95c6e004285 |
|
BLAKE2b-256 | 93a7bed9eae7318083dc8cf53e78cdc68020a9bc33d5d39405a39f2f9abb61f9 |
Close
Hashes for zmesh-1.4.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127a2bf26d8563139652153c15365272816729e210660daaa601274c96da1930 |
|
MD5 | 207b852f84f266773e0d498afcb927c7 |
|
BLAKE2b-256 | 087a7f84e0eb4812cc9cdd53d2952311d737bf2f093cbfe37b9fdfaa86d4c679 |
Close
Hashes for zmesh-1.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dfa4cc3140fed292fb3014c9089d653ce5f742a808282ea9a07f1d1c944572e |
|
MD5 | dfe10fc8451c344c12becb0dd1f1fbc7 |
|
BLAKE2b-256 | 5c975978fd0163a00ceb5c3ada128456fd901ee01b4c53b61bb0abdcfb687daa |
Close
Hashes for zmesh-1.4.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffd59342189c3ecbe209bbb84861583e0a3d2d3859ceee08c015173765780599 |
|
MD5 | 2140b4288c21fea925860c5973edb4ed |
|
BLAKE2b-256 | f7b025a4cbad926ba08c0d3283dae4a9bad5ac6366d579aa1f17daf5888d5e70 |
Close
Hashes for zmesh-1.4.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28e3ee5f837453b9dd4cb1c9cc594a79a1fdb1a5c3a4379d0aa04d1d89015365 |
|
MD5 | 4e1d2b31f0858eed36004aefa5d7766b |
|
BLAKE2b-256 | 028610c3b66c4d9fb09c8900ceb316cb8821f7812821136e24063eaeda7ae993 |
Close
Hashes for zmesh-1.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e7ca67ac55fa263a90a78b403eafe342b54bbf70aeafd244b08daf5c532d19e |
|
MD5 | 74faf1a209390045fcf20d162bdf245f |
|
BLAKE2b-256 | 3baa29e11211b558a04ddca21156df88b931087208394440e8d2f1805354996a |
Close
Hashes for zmesh-1.4.2-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41625eb184ae4f4961daaebaf27f85281a17d558c981a6ff151515dc9ae44dc9 |
|
MD5 | ad18974e879317ee03f7c58c538e2a82 |
|
BLAKE2b-256 | 9b293001b87590433d5ab031be5466b46eddaf4c597223a6e233d266bdb0682b |
Close
Hashes for zmesh-1.4.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d807b12f8e21668369a632a71e1219460623de93189c01170de31a4f5f4344da |
|
MD5 | e1bb00656a997cc83cc4d4be67054500 |
|
BLAKE2b-256 | 3ac2e6980cc82e42f636f7072daead438b5f369bd1776b1078d1751433a20e11 |
Close
Hashes for zmesh-1.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c634c2f416001dd48a9b1db052494da344563cd69013c256f20d3be2ac552bdd |
|
MD5 | 28f3f91d718c02fd04585b4307ac7341 |
|
BLAKE2b-256 | 2c46e8cab8fabdfa1b788b2d6c5d70169d3eb630aa08f4953d2a7854292cfbb1 |
Close
Hashes for zmesh-1.4.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765ce29f67597614d6f53e7a1fe163144ec6d009fdeca6eac3025ecb0d1a65cc |
|
MD5 | 310d24be6488ecfd30594f13820286f0 |
|
BLAKE2b-256 | 1a33b8d86c4de074a617d51bdb102c2c2fb56c49347d30a30152678a037cdd41 |
Close
Hashes for zmesh-1.4.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d005afeb5ba668c5f4ce7fb8c25846f4f18d0f898c81cbc9e34bfd1b7f270b12 |
|
MD5 | 9a60ee4b737bb01ab8f0404f5f885c2a |
|
BLAKE2b-256 | 99b00cca07c95491c7bd62ed6b6952ba18c58441f8ce79af1894e8b10d23c34e |
Close
Hashes for zmesh-1.4.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd1e5b51a0c50a37e4ea1f484608fe2e07a0119c1e529cdff586d0b2725d1631 |
|
MD5 | 7d11e59cdb15a9dc1d13ebbcc7df5089 |
|
BLAKE2b-256 | 966cbbaa1dc73c852be820f5777eba5d3a1fca1de8421cee3fe7eb47db03e15f |