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 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-1.4.0.tar.gz
(321.0 kB
view hashes)
Built Distributions
zmesh-1.4.0-cp310-cp310-win_amd64.whl
(248.1 kB
view hashes)
zmesh-1.4.0-cp39-cp39-win_amd64.whl
(248.1 kB
view hashes)
zmesh-1.4.0-cp38-cp38-win_amd64.whl
(248.0 kB
view hashes)
zmesh-1.4.0-cp37-cp37m-win_amd64.whl
(245.8 kB
view hashes)
zmesh-1.4.0-cp36-cp36m-win_amd64.whl
(245.7 kB
view hashes)
Close
Hashes for zmesh-1.4.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8b7057000ffdb790f12f57c0c2216e60e7124b2bba95304a442710507218086 |
|
MD5 | de44d43cc860de51e743a98f1fa8d58c |
|
BLAKE2b-256 | d02af8dc47390b49d2c6d78f282f554763be9006b6bdab197e8b21e6b27a79cd |
Close
Hashes for zmesh-1.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fb1f220fef9dc57fbe697e25016836930c7b35243a718a262ddb81c5b4f8ff8 |
|
MD5 | 6f1f2b98baaba58cb133b021142cfb15 |
|
BLAKE2b-256 | bac803746567279b3e7492ced1a0b94565bd79578fd8219c5cab711495d13aeb |
Close
Hashes for zmesh-1.4.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b877108112b5013bcfe5174b5ee9e461a69baf9e9d7c66b5255330d0e564a42 |
|
MD5 | ac4a2d2bf55c4bea2bff2483a87d922d |
|
BLAKE2b-256 | cd87b4237c790f55fd9fc6daf1e58ab0add1c342cb45b69912cac51dd3aca292 |
Close
Hashes for zmesh-1.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b31895ec04a058339c369335070907ebc83c6a4affa8b0c14be51fd6c000215 |
|
MD5 | 6c02dd1e1282eb0ff0e4fd1cdbcf2ac2 |
|
BLAKE2b-256 | 4f38cd5c0e231fc15afb413037998719e19c6783f2880e60faa747afbe5d5e0f |
Close
Hashes for zmesh-1.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84df7c14274e8d95cefd68b9d6e9ff649c2bcc55a378d5f5e221dfe3f005b9d1 |
|
MD5 | 38262b9484533641e525cc4a69a80f18 |
|
BLAKE2b-256 | 257ab88a57708478eef7afa062fad151a7fa2357df8f2e5a62bd6b2653e8deec |
Close
Hashes for zmesh-1.4.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5971576d09725b3f805db1d521fcad69b33e7aa0b8f5996f831348a0a930938b |
|
MD5 | 4a66a89080ed9f3c14b4e4fb5b19c3da |
|
BLAKE2b-256 | ea110df152f11cfe82b77daa5b2c3a768937f0e8593f01050cf8245fa25b2851 |
Close
Hashes for zmesh-1.4.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb99386a141926eca7cf8a4dff99c1b72ab2ccc64cb5f5caad444fbf09139406 |
|
MD5 | dd7f2a710798309673a84c1d4b4c4503 |
|
BLAKE2b-256 | fcb6ac25cfefa0c0dd9784b2963739ecdc1ad5018f748326cee488bb863e067e |
Close
Hashes for zmesh-1.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fe0821a05bfb582da472213c45ee45999c1558dc51108d06eaf2fea6c32349c |
|
MD5 | c9a0159af675e7da2e9e1b32cd1f724a |
|
BLAKE2b-256 | b9e1135a388ff963d3bca58966eda4e6f0049c60ad5af0f5a5054a4b97449ff5 |
Close
Hashes for zmesh-1.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b40529c402701f73deddfcfc32b0446b4a955e1395e6be7ed3954d114e7b1c16 |
|
MD5 | 47bd8859a1c0f09d5f5968f73c51dd7d |
|
BLAKE2b-256 | 252e3caeaee4b58ff98da8b9e404a71696b141fad730c31e4589098d195bf444 |
Close
Hashes for zmesh-1.4.0-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22a22c7664446a019826fb51a3439d3ff0fa6dedff117cc661a65a5a15e04249 |
|
MD5 | 97eb175c9f42b832f79db995a6d12516 |
|
BLAKE2b-256 | 3c7f9893bb751919859a1918b991ac4867face3bf31718b7a581d4cc10e027c2 |
Close
Hashes for zmesh-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cbf1cac57704d175e0bd023ad22fa1b331944a7d8e2996c972e4eab27585add |
|
MD5 | 39aab2da1b61108589e3ccae2c71834c |
|
BLAKE2b-256 | e09832fe9fb971a0d17c03e754c244cc65a67c0b3bad351b9ff4df96a8cc59c8 |
Close
Hashes for zmesh-1.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d51453b56d850fe7d2aafd230cc26953b7396b6d6d74c60ad773df148c5a5de4 |
|
MD5 | bac6cbf98ed549ebb2aa4f4d53562aa0 |
|
BLAKE2b-256 | 755fbe217c1071cc37e8bc50942b5ffece4af000aa5922227babbef6d45a902d |
Close
Hashes for zmesh-1.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02638f4170a09335f261d08fc7b210a6356215eedf30522244bf6286d58e18e2 |
|
MD5 | 485bb47f49123cc9ddc69843e0d08ade |
|
BLAKE2b-256 | c0f5729f6c28ce558c31af8ae01276b5c8d4cf73b8509d97a6d1049678465d68 |
Close
Hashes for zmesh-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c448cea344d73ba8959eb2c6306bbcc3253639790e3fee08db7406051dbc7d6 |
|
MD5 | b03208d5353813963578a27aaadd94ee |
|
BLAKE2b-256 | d999e9cd419bb2a14e6e4f0001d54155a0a16683eeaf1d93c0995ccfd7b48fac |
Close
Hashes for zmesh-1.4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 865e7282cbb1294a3c89d13e39bca3d9dcd4228e57bd1685325ef1870a4aa498 |
|
MD5 | 1f7436344c6f438d619a9e57003033ce |
|
BLAKE2b-256 | b452912f9f11bdb45499637ec8cc26783cde73cd2db7bfef507aa69da3c7e3db |
Close
Hashes for zmesh-1.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12018053c9d9a4524e3ee24a84ee5090399b95058234dd10b74c2123e3786e60 |
|
MD5 | 094be8fe28280edaa1cbf3597d1d4581 |
|
BLAKE2b-256 | 8845b0c5233f98e52f377ac8eecd5f6c3d9b0554cf3588582acfdef7c910b193 |
Close
Hashes for zmesh-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e8572304614386290c4fdba46a23f1d67579f3662300950b10cc17d1a43d475 |
|
MD5 | 6231271d345ca8abe3e2cda050636aba |
|
BLAKE2b-256 | 24c08fa744a4c1fb70fd3bb04e7997520f857dabe5498911105ef470d7603071 |