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 & 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.6.1.tar.gz
(351.8 kB
view hashes)
Built Distributions
zmesh-1.6.1-cp310-cp310-win_amd64.whl
(245.2 kB
view hashes)
zmesh-1.6.1-cp39-cp39-win_amd64.whl
(247.8 kB
view hashes)
zmesh-1.6.1-cp38-cp38-win_amd64.whl
(247.7 kB
view hashes)
zmesh-1.6.1-cp37-cp37m-win_amd64.whl
(245.9 kB
view hashes)
Close
Hashes for zmesh-1.6.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ed848ab05956dcacd650a9e052498bff9fe14b50b070ae6c25b86f373cade4 |
|
MD5 | bd06b908d8ccb4cd5dcccd370e42ce3e |
|
BLAKE2b-256 | f50af9986dd2f226e663b2fb875b24609210cb4e9655eeb680a8f29469d4dc29 |
Close
Hashes for zmesh-1.6.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 711124c8a9b20267298b29485aa433a54696a9a2bacc9b8a6fc84da5ffa1c7de |
|
MD5 | d3e4bf90059c8ed4abc3c74316e69bf1 |
|
BLAKE2b-256 | 9137873bddb6e04d928d5308dd0a0cade726b91081f1aa2e6f81cb7668ff8e6f |
Close
Hashes for zmesh-1.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2026448e530b46b8ef9c8245ce46704dca3e0e0af76d48296fc0c3d0e2532b66 |
|
MD5 | d3f18cda31fe718fdde307b670f661cc |
|
BLAKE2b-256 | a21696c03c8e76f12c7ff29eeb1d50c3d93db0e719e736f8d8fc0859a53e08ad |
Close
Hashes for zmesh-1.6.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35716872ed06cce9748415d8f14b3970d3f44f7035cde2824a2d8ff6a3548e9a |
|
MD5 | cd9e0831e08295a9303416f1f4335d32 |
|
BLAKE2b-256 | 60abee318577d7e229521e6f8f9dc8f3cb66f20227922097eb2a39bbf246a182 |
Close
Hashes for zmesh-1.6.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8de34069e6e8a6a5a4d6ff18081e339a1e702e1f71c52b173904fe18ebbed99 |
|
MD5 | b90e30fe6a8f6545812279637e1f39ad |
|
BLAKE2b-256 | fe1e88b4ee179a53a3261645d1b26a6b6fe36b98ce124c4929c8ee1acf468684 |
Close
Hashes for zmesh-1.6.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96eace32d4edc9e6c3b3f5f910f0f94586317c0be88615470aba3f4773b8d433 |
|
MD5 | 2b4ff73a50d443a353340fed5bcb0ceb |
|
BLAKE2b-256 | c584533ce7a515684854df29ceae1f0c2daa0966aa99a0b3d6f1e6a6ca2fd1fa |
Close
Hashes for zmesh-1.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c234b852f8ba2f9f216a0323ecf0a9e4616d0cfcbd9c669576f4c36debc53e3 |
|
MD5 | b8f8144f98853de2d536e0713c198c83 |
|
BLAKE2b-256 | c4e087e13c82944ff38f765b355e77faeedd7201d17cbea319487bc79e193339 |
Close
Hashes for zmesh-1.6.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 447fb5a8f38e6462a4ba91e2049a34b55e64050d7af0be62a15650e094d07ac1 |
|
MD5 | bd74296649b053f1be64a9561961f6d2 |
|
BLAKE2b-256 | d91866d3fe32b65324a3cf647c5e0010adf850177403cf6d87bf4dee8a647c88 |
Close
Hashes for zmesh-1.6.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77f96d52b2b519140fe7bb697071b753ebd8b2383334be81aece6d8e87add395 |
|
MD5 | 9b99ab4be420515dc6659129eb86452a |
|
BLAKE2b-256 | 50face47383ce6656604e3ce34e63cc28ebaf01bd4352ba354037c295b5a8ada |
Close
Hashes for zmesh-1.6.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81bdf17f2b1121efa226289ed7c79c43192c8fec434bf9f2d3cad9284a184217 |
|
MD5 | 46e642559f4e62416d24ce132ffcc7b1 |
|
BLAKE2b-256 | 484e24016c5d4dd10f599d8f72ee591220cdf4be4ac1e5f62d415e3e23d25519 |
Close
Hashes for zmesh-1.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 966ffc04d89d4918c6fe5eaca66400c09696a91a8f2ce091013088f802850504 |
|
MD5 | cf0b8e77770802f5c39eb7e2a87baf12 |
|
BLAKE2b-256 | 4fd78f36b1ea2a1d2499fcfcd499e441d63e00fc241995c1fef19d94645cb28a |
Close
Hashes for zmesh-1.6.1-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb3998335d82e52e26e0cba1d2ab6542280450e9eef7cb76a3fa2c9be05286e2 |
|
MD5 | 2f37eb29883e7f0cbd56f7470510f1d3 |
|
BLAKE2b-256 | 6a008b4e5d51d7b6a778d626c786048b8e25eb86b420fa2ad4b3f4aed7cddbb2 |
Close
Hashes for zmesh-1.6.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89728ef9389be15aa2678f830a7a5a0da14c77af1a75211e4445f0f2baa5adbf |
|
MD5 | f5285e13cc0ee2f78ccb63753cc47b1e |
|
BLAKE2b-256 | 72600b2303948296910fe5d8e1ea00b753801d97866577ad7b768c28a658f605 |
Close
Hashes for zmesh-1.6.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d93cf86cb7f9fc669a0aab3033edc975c789160bb4adfd97407ab6094ed0a5 |
|
MD5 | f8431487416d42086210c6b547926363 |
|
BLAKE2b-256 | 06d1069aa4b0bbc4412172f4adeab4c0ab8db8328b3673a32a86490a24310b35 |
Close
Hashes for zmesh-1.6.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c114cbe5215b27753d8eec1961917ba20c224da34b4cd6de1fc67e2d6b644ca |
|
MD5 | 3c8b3af36ddd80fa126aac805e39dda5 |
|
BLAKE2b-256 | 1b3d88918018dad79bb80b5b2ee15fc908ef7788f2193128fc0452d0123296e8 |
Close
Hashes for zmesh-1.6.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d399377aedf19a23d62c22e65690398646d837207f202f930cb40068e559a73 |
|
MD5 | 77aab03c4f6d2bd8db730a5e781b8976 |
|
BLAKE2b-256 | 57be09ea6c500fc031a5d6cbde3b74ed7ef7e1806f65902b89356672994dba96 |