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(
obj_id,
normals=False, # whether to calculate normals or not
# tries to reduce triangles by this factor
# 0 disables simplification
reduction_factor=100,
# Max tolerable error in physical distance
# note: if max_error is not set, the max error
# will be set equivalent to one voxel along the
# smallest dimension.
max_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 reduction_factor in get
reduction_factor=100,
# same as max_error in get
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())
Note: As of the latest version, mesher.get_mesh
has been deprecated in favor of mesher.get
which fixes a long standing bug where you needed to transpose your data in order to get a mesh in the correct orientation.
Installation
If binaries are not available for your system, ensure you have a C++ compiler installed.
pip install zmesh
Performance Tuning & Notes
- 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. - There is a longstanding design flaw in
cMesher.hpp
that transposes the returned mesh and resolution. We're working on a backwards compatible solution. That's why you need to domesher.mesh(data.T)
.
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.7.0.tar.gz
(262.3 kB
view hashes)
Built Distributions
zmesh-1.7.0-cp311-cp311-win_amd64.whl
(134.9 kB
view hashes)
zmesh-1.7.0-cp310-cp310-win_amd64.whl
(135.4 kB
view hashes)
zmesh-1.7.0-cp39-cp39-win_amd64.whl
(137.6 kB
view hashes)
zmesh-1.7.0-cp38-cp38-win_amd64.whl
(137.8 kB
view hashes)
zmesh-1.7.0-cp37-cp37m-win_amd64.whl
(136.0 kB
view hashes)
Close
Hashes for zmesh-1.7.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a42fc850412de81352aced4055d72541aaae9b045dee8bea517e4772227baf93 |
|
MD5 | d0eb392b12fdadbf96a2dd71a50d8bc1 |
|
BLAKE2b-256 | 69146434a05ffba7cfc28d92c0e64c9d720c5f94fbe364df97b2e03701848e33 |
Close
Hashes for zmesh-1.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dfeba6adfbe660ce55236b0003a4f70fbcd747898d71707c86f61b464163ec1 |
|
MD5 | dd3e2a65c6ecaafac8545553fbda0136 |
|
BLAKE2b-256 | 14bdd6d95d1440e4b408107cc4ea8beac67f0057c5585d903071c29b50d455f4 |
Close
Hashes for zmesh-1.7.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42ff5e56812044844e0e6d8a6dd0026638d0e40ae22d44ecf43203d60243d065 |
|
MD5 | 16ebcba89b0138234027c7c5943005e5 |
|
BLAKE2b-256 | 81f676abb499d39e9bf34aef79f6c7e0397a82f648c7ff0f63a1f317eca79e07 |
Close
Hashes for zmesh-1.7.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfb104b30522f2314d2445541ff6a4e07cd1935e6decea02c24a889fe7c228ef |
|
MD5 | 80af69feb053e6c0d702387a53cebf87 |
|
BLAKE2b-256 | f0a9f3edc2ef698c50dfcad5bc5581d27d9292b94f67dfa048578733f1ea43eb |
Close
Hashes for zmesh-1.7.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2512ac2f0c2dcc5dc60ce229a14683bef321c89fcd457153abe5f5e3435bd03 |
|
MD5 | dcaf640424c9fda5f00050aa9b604f22 |
|
BLAKE2b-256 | ccfff04106c6057d6f035d8cdd49cb41a870785e0f760e401ab2300de0a40fff |
Close
Hashes for zmesh-1.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93e1b496ce05a7b689fab68d89915c23c2156bb432fe7e952121b5d4a933c272 |
|
MD5 | 98b6268b3e6ccd4939b22987a1ce0790 |
|
BLAKE2b-256 | 9ee040c5d90f18723494276ea9bf3f48c91209a1f3ed80997beade8f3e6d3df4 |
Close
Hashes for zmesh-1.7.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bf4dca1e64da19080b30e1f32ce590b03453e1f433ee0e68d392c6fdf0a3720 |
|
MD5 | 7c085e7d87e70f63cbe69869b87bea45 |
|
BLAKE2b-256 | 8b2b0ed12895c49ce8ff7b9fa18f91f5ce07598dc29665d3a4ee87b5bb831b19 |
Close
Hashes for zmesh-1.7.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 382c9e7a9e93dcd75bcb34aea1b2fd3f95c3fb2484f285dc2f0bc2dbeb8c295f |
|
MD5 | a340cbed0e67b8b29843bcd4b9e7603a |
|
BLAKE2b-256 | 98838d533446dbbfc205b9d700ff712ae171a8f0a61edbeab614ac618244862e |
Close
Hashes for zmesh-1.7.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 991743230d3441b369097c4ddd5c19895cb28a391626fd97046c036956945f01 |
|
MD5 | 2ba8c3a5319f8a6373ac49873a2bdaae |
|
BLAKE2b-256 | 40f881504cb5004564aeef4b5e0ece6224c2737069cbf7bd5a35e05603d5dbe2 |
Close
Hashes for zmesh-1.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28958496e2ff528705c8607e62cad00892e8e7733be618f844501ced8e0723cc |
|
MD5 | ae5d6a3da238c2fac268c57db61bd078 |
|
BLAKE2b-256 | 4d24efe02dee20cfa04dd78d94be69f61fa15bb98303b4e5c05e0b2631515bda |
Close
Hashes for zmesh-1.7.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6121ef72db56ab130ae24619b4f87909efd17821f80117a744228e73fc5ddf91 |
|
MD5 | 5ef53ec23ef5f853f5765d9ba7ebb2cb |
|
BLAKE2b-256 | 989820f6ac5bd2304182d0aca849b882ba94951719a1ea2fb26bc2a7837ec89f |
Close
Hashes for zmesh-1.7.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7bb6ca331a86f9b3d29d7aca2d32feab14b5cfda64ecfdd7002175fccc44a44 |
|
MD5 | 80e8c88307fde505e5b5a390f0e68ba3 |
|
BLAKE2b-256 | 9d0220071aa7188a2b955d1f5306ed90a1ba2b797f6c4d28dd77c775732b86d7 |
Close
Hashes for zmesh-1.7.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed3023150c3ca59e34074cfbfaeba0bcf56b75d5d8c79e08d62e3532e636f6cd |
|
MD5 | 17936a0752e49f7fc15f8a42b29f6d49 |
|
BLAKE2b-256 | 74377721f3967abfc49bc8fba3730b69103f3ed64063589cf53b5f30b920c761 |
Close
Hashes for zmesh-1.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e20634b11e0b6b33d8f67ead527be2f6259b6be59e9e3c2fdaf518ed2e0d1c6 |
|
MD5 | a6222d588815c9278497a2dc5243eff1 |
|
BLAKE2b-256 | 837b5bfbc45119e0164978caf7e017658aacc579f8a672a395ba883e48562829 |
Close
Hashes for zmesh-1.7.0-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18211381ed9590b4a67a15b2cfeb00b91ffaa02d2df6011d68fef529eb1acff9 |
|
MD5 | 9f0c7c5a8056de21d32fb52fb26beb70 |
|
BLAKE2b-256 | a2ebdeee24d142e045f87b297936f95b4457754caffa15a460c736d76639fd0e |
Close
Hashes for zmesh-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f4066c7f6a0044c96c35777a9783e96d78a6fc1b435ec97e5c2382b0220013 |
|
MD5 | 685dede84b03c4c3c2c12927a54abd46 |
|
BLAKE2b-256 | 21bf8f81a1c75ca3484bebcc8e23213a2e8253e5e330063146cb3f88142d1eaa |
Close
Hashes for zmesh-1.7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f6e83f3b720174f15d7cda9151404a31267daaeb4b8365c4b86bdadbd070a03 |
|
MD5 | 3e57eff0a496caa803d94ded957283de |
|
BLAKE2b-256 | 1374f199ba1843d39fb7d16b396c0106a1f6acda674a71b9f3ac3f1710ea094c |
Close
Hashes for zmesh-1.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49ecc83660b4956ab386920160538201bccc2f11ac56dceb3603fd3d597e4e89 |
|
MD5 | bf0546786562fb428096995b1051d3a7 |
|
BLAKE2b-256 | ab3d54cd54034d5264cf02245f6d6d5a0191905504ce4ddb427e0df8c99e90c5 |
Close
Hashes for zmesh-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea0d509e44b3788de91526009b4a39eaf67a6748945b10f90c777bf9642fff08 |
|
MD5 | 415e945bab9e9d40585709307a63a505 |
|
BLAKE2b-256 | 498a4e0757b96a4a70ea0a20f8413c2b274a68f1dc28b745c1ec17942d8ab0ad |