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.3.0.tar.gz
(320.7 kB
view hashes)
Built Distributions
zmesh-1.3.0-cp310-cp310-win_amd64.whl
(250.9 kB
view hashes)
zmesh-1.3.0-cp39-cp39-win_amd64.whl
(250.9 kB
view hashes)
zmesh-1.3.0-cp38-cp38-win_amd64.whl
(250.8 kB
view hashes)
zmesh-1.3.0-cp37-cp37m-win_amd64.whl
(248.7 kB
view hashes)
zmesh-1.3.0-cp36-cp36m-win_amd64.whl
(248.6 kB
view hashes)
Close
Hashes for zmesh-1.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1878f52ada3eb7cfa470461f2ce4495305724636bc05aa2da17cb4f2579564b |
|
MD5 | dbd1f9ab86c933a942dbbe04712e85fe |
|
BLAKE2b-256 | 1e2b54089f8b545a1cde45aa12536c15f241eb897692b155568cef1efacad342 |
Close
Hashes for zmesh-1.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c173c420421a8d03713e5985da49960265a840c2ba7e8a1393306ffdc9d228f8 |
|
MD5 | c2b83a1f73fd391282ce1e80e28e054d |
|
BLAKE2b-256 | 32a42b98f7765d0c6b74d9f320cbd11855bee9768949bc4be5f591c4d2b0e8e5 |
Close
Hashes for zmesh-1.3.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60902807f9b119a39b869c4b6ed750cfa1e843e94d8a8c8529839ed259f0594d |
|
MD5 | 32302b819c0cf6657d618a2091cf3aec |
|
BLAKE2b-256 | 12a4b2c1a5bfc0a36275718b63efa5ed9de044ee6d50f8a0f9f512739a1f91ca |
Close
Hashes for zmesh-1.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaf8d44769051249f09e75ba0b46ac36fd20d1c9aab4c3c12a1270b3390898fa |
|
MD5 | 97746663e104a7b343e4e9fde02d7cfa |
|
BLAKE2b-256 | 6da6202d54b12286535cbf238830e19d8691dd9959de42a1ee665c9b5b291a17 |
Close
Hashes for zmesh-1.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90abf7370801438b3021da632fd772748c1fbd3fa3df2ee5ef8899001c6a6c45 |
|
MD5 | 5f370bdc68f637d54e24ce4d56c66550 |
|
BLAKE2b-256 | cfb294515e22a22b1b316593df3be951588948397cefc1786d64816cf61a26a6 |
Close
Hashes for zmesh-1.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e42688845dfc9422b5217aa42aeb37e84e98efb5ca0bb2273ef758fc4fea9f39 |
|
MD5 | 06c26bbd47fe2bf1277b5c2c44ad48e2 |
|
BLAKE2b-256 | 9d9d21f7b01e6b9cb5f0097c0c499caac55b9887e7d8d05abb7400c2c870fb60 |
Close
Hashes for zmesh-1.3.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4159635efd2cf817678a9ccfb0e90aa3b4ff86bef7f35f9a60308a82235e8d4d |
|
MD5 | c5f60d68fe4a37415fff1363e7b8d8db |
|
BLAKE2b-256 | 12a59e3ea82c36aa3b0eb03e73eee326f2422c40d93fdf9d57b1bdfcf7a8ae89 |
Close
Hashes for zmesh-1.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f211c07e6929de757f3d195c79d10f84ea4544cf132b06c936d07b099bcbc707 |
|
MD5 | aaccd12c9cee4e74219f245dff1cfd21 |
|
BLAKE2b-256 | 3244356ef57c117a489b753ab87f5078164365a03c3822ae11d610ad1f030bbf |
Close
Hashes for zmesh-1.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e119b37324327f323bf64b7b4ec5e31e3714d80ee18d6b00a41f83a4db6f6e9c |
|
MD5 | 336dd8604ff45040b93ccc31ab1375cd |
|
BLAKE2b-256 | 02a571cb95925d5b7b59ed08bb5ae4f8e3c7ec980daad237f1441a7a0af445af |
Close
Hashes for zmesh-1.3.0-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eff1d9c2a22d8e5b52a816d393c56515faf91d165378389466a45148cc442e2b |
|
MD5 | 96abf2437654c721e658dba7d8695c7d |
|
BLAKE2b-256 | 91d9ab14dcf72bd90cbf7f75a47d4d0d7f032620e3fe015fc26971acbe3a7be6 |
Close
Hashes for zmesh-1.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c14b95eb370b23cd80c30f530627194cee120463bb0333feacafde9616f197 |
|
MD5 | 4612a7cc42206692b8d7332ed75d9102 |
|
BLAKE2b-256 | 31a734d249c735c218239d58032cfe45288d24b8f52e2c432e786d719cb086bd |
Close
Hashes for zmesh-1.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6481c8e97ca797f7999f364c24b0b382d59bd6b9e737f13524de6fec67701754 |
|
MD5 | a672ab3840d9e8e85a3133d0e5c678bf |
|
BLAKE2b-256 | c9fdbb90cf417bd3d09bb5fe64817c18f33287675b1b963e65f7a892b9f7e6e7 |
Close
Hashes for zmesh-1.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f159ed07f776378c1e3095dc089b9a4aa52ab7101e4eeab34c995fe3cbb9c481 |
|
MD5 | 706438a82e6198e4565b986728413cf9 |
|
BLAKE2b-256 | a1c4f74287b894f3e4f21fa856fa429d225142435e083a0c7184899d0340c1b7 |
Close
Hashes for zmesh-1.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2d8ffd5b6e14ccf0295e1e37434d2adbe835a1cd0b3ceabb137ced6bd5ed5c5 |
|
MD5 | 5c41efa2df04f3bd0bc00f834cb2af55 |
|
BLAKE2b-256 | 1746660b36d5904f494caa3ed87ad92210c0faf1418d23086adac88bde3c1da8 |
Close
Hashes for zmesh-1.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e717c14ad7e42b98dbc696b46eb2f5bfa02b685e118b89b02fecd7ace503cca |
|
MD5 | 6bb47960a7782a0e69b08c986256cdc6 |
|
BLAKE2b-256 | 39ac8901a7030dd47c88671d3938f4694b8f235708114ef6fd867b89e199f236 |
Close
Hashes for zmesh-1.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2112480813f23ed54255fd0328b65ef22de7fba58e82fc249dc48ef7a765b3b3 |
|
MD5 | a30133ff06d027b49b53c96313000eda |
|
BLAKE2b-256 | e68a99429c6d762d20ecb09804d4d61d72007eabb5340312665f8804a2a2c8b6 |
Close
Hashes for zmesh-1.3.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5051d7433ea5d9893c2ef006a61d63bb9fae197fabb5ba661aef142ebc81c4b |
|
MD5 | feb21b8b59b016d0b8b8137cabc8286e |
|
BLAKE2b-256 | ce043ad9a20c42b28456dc21f2358f2b5ecb2ae463241427f9621071eaeca32f |