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
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
# 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 <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
- 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-0.5.0.tar.gz
(285.7 kB
view hashes)
Built Distributions
zmesh-0.5.0-cp39-cp39-win_amd64.whl
(200.3 kB
view hashes)
zmesh-0.5.0-cp38-cp38-win_amd64.whl
(200.7 kB
view hashes)
zmesh-0.5.0-cp37-cp37m-win_amd64.whl
(199.0 kB
view hashes)
zmesh-0.5.0-cp36-cp36m-win_amd64.whl
(199.1 kB
view hashes)
Close
Hashes for zmesh-0.5.0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2d8aaf5eee21f59d876923b8baee7cd1f06be5bdf31ad9254b91ca6bd38a82f |
|
MD5 | e6d3b8185882e44012f38997ff1eafc4 |
|
BLAKE2b-256 | c7c045e72407e68e0d050b964effc50611d52f83c74c402dd7ae975520b5a291 |
Close
Hashes for zmesh-0.5.0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db688061dabfaff786d971e9f8d1d02431a67f11d0b692681236d7a46d2e8e8f |
|
MD5 | f93bbf2d33ca42cfbcd132c1ab5f13d5 |
|
BLAKE2b-256 | dcb87481fd10719bf7fb29df323932bb962aea903d091ae3201c589330917b85 |
Close
Hashes for zmesh-0.5.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a904fc970234b456837a5fb9d455c9e2f53860ffec0b61c5bcac16502e7d002a |
|
MD5 | f8e7f3b311b3bae6b51566891c560f48 |
|
BLAKE2b-256 | 866862c5d8ebad1a7221eb6d5e71a76a26de3dfa336e7e0584e61d99776d3872 |
Close
Hashes for zmesh-0.5.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9060e02870d048d6de6085b038797546e1937f16b1ed74b2c90559936a3140d8 |
|
MD5 | 09706aaaf9a2c65431b8cbfc02be809b |
|
BLAKE2b-256 | 16520909cfdec50b2eddbb854c1a0637cfd3c24bff274e3fa2f29403fa157003 |
Close
Hashes for zmesh-0.5.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d88e176b777ccd7fb6a41f8899e06b7ad4b922c1d0dd2d72bc158907ed62e19 |
|
MD5 | d00f3411e56d114fe5a4b2828d810c1e |
|
BLAKE2b-256 | a7144c766b2b4084715a0be023bfaf32bb5bbf7737bb36e2dfc5d93f428adb7c |
Close
Hashes for zmesh-0.5.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d91216cfcc41514508bd04cd661224714736aa83fee05341e6b3f1f23390808 |
|
MD5 | 05d59bd2b5fca3e0b19142b714dc42e8 |
|
BLAKE2b-256 | d75c7895416783c40303ea830688d95ddf682990e7c9f6b8d2aa4db81c6d10f3 |
Close
Hashes for zmesh-0.5.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf4d14a742a382f7da9e22c9651cf8799f915a04551c5a839b4d3b10a691b36f |
|
MD5 | 34114bc8d1794f3648f0fc09bf2d138e |
|
BLAKE2b-256 | 01657e06c9be1eaf3f293af1425e2b2bc3e6489535a0cac4b0f77e6d3ee6edce |
Close
Hashes for zmesh-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cacafe3dd53dd7defe9ff8e1869e2a50440fcdbda68cc6531ad42312e62a008 |
|
MD5 | 5e9aad10172d4b745d9cc7d97a12bf54 |
|
BLAKE2b-256 | e5d13cb3915e04f7b3f1d1538c1a6a3a4490850daef52ca8fdeb9e6886d7240d |
Close
Hashes for zmesh-0.5.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a87f878549e2c7b79f5f8b7978c5c7d6b1d0f3f0f063097bd3c0281b931b63e |
|
MD5 | 17d9016d29e4deb72a048138c35eeb74 |
|
BLAKE2b-256 | e817863039c398ba457268e81d619bf645d72d0da282188c3bbf473a1ec236c4 |
Close
Hashes for zmesh-0.5.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6fac8f0cececa19596679cc3f78acdf4fd8360552a0f630fe6b313bbef2b749 |
|
MD5 | 17a73feef9a915e914317955c5a88027 |
|
BLAKE2b-256 | 940f04ecdf940071d5a74cb2112eabc277491fd56068a05079feb68ba89ee453 |
Close
Hashes for zmesh-0.5.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2a3ce954c679d40ffe008e6a4bc89b90b84dba6f4def95d1bc598edbf394694 |
|
MD5 | 199ea568b531be0054d0bd20cd7e493c |
|
BLAKE2b-256 | 72b5bc260ccc438bc24fe56d67db7c420ffa74a31ea717daa6560a016ccef41b |
Close
Hashes for zmesh-0.5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 010f082786699c97b9dacf2b99886d6b55b4d1633892bb4c9866df4e372d7466 |
|
MD5 | e2abbbc374ba4a07371211868309a5cd |
|
BLAKE2b-256 | dc5e202638d312d806e510afdebe7c9fbe245004e90e36656204b41f7ee209ea |
Close
Hashes for zmesh-0.5.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac74cd2cb42640cb36a2ab946e712da2a89087832535f01dbb50fcd94794969f |
|
MD5 | a2c16d55a71e5097313d52ef73e3b071 |
|
BLAKE2b-256 | 1e68aa2b6ac4824fe9680d1e5128b14dadb5c8004efca2932aee5d43ea9595d8 |
Close
Hashes for zmesh-0.5.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | becf230b8adee38e1b044d89ff1f35a18aa601f1723450bffa5350d9e1d29e8c |
|
MD5 | f968097352985cc6f24048e568abf726 |
|
BLAKE2b-256 | 578a9dbacfce1e5d5c6a2527f770baaf11cad28b4c0abad44c3160d494571fe1 |