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 <1023, 1023, 511> on the x, y, or z axes. This is due to a limitation of the 32-bit format.
- 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.1.tar.gz
(279.2 kB
view hashes)
Built Distributions
zmesh-0.5.1-cp39-cp39-win_amd64.whl
(200.4 kB
view hashes)
zmesh-0.5.1-cp38-cp38-win_amd64.whl
(200.7 kB
view hashes)
zmesh-0.5.1-cp37-cp37m-win_amd64.whl
(198.9 kB
view hashes)
zmesh-0.5.1-cp36-cp36m-win_amd64.whl
(199.1 kB
view hashes)
Close
Hashes for zmesh-0.5.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6d8bba1ba5450cdc32bc65ef1ee77aade68624c7ae45fa5715422014aafd91 |
|
MD5 | 835321d820b4a60fc6031b2c6fe20384 |
|
BLAKE2b-256 | 7bcc2390475268587034b96085a4eaba63619978dfd655a4e40330aacd6c03c1 |
Close
Hashes for zmesh-0.5.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57a217cff178c4e51bb99bf4697654c6dd85669301598ce5b221897b1eabe2c2 |
|
MD5 | 1220460c596797579662c72ae5cffc6c |
|
BLAKE2b-256 | edb62cffbe3c205df53fc677ebe712bfc498055478055c685f1b9284bf69e45e |
Close
Hashes for zmesh-0.5.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e6a8bd1e8242a70292af39e642416d05ffeef543ffef4675f36ab29bc378b23 |
|
MD5 | b6f5b06219a85fe05a36d5bf753572a9 |
|
BLAKE2b-256 | 71ede89edf4aa46fe53beeec988fe6e4a95560d4ca88e2c8c1c03ced93328958 |
Close
Hashes for zmesh-0.5.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4bab2b2d8ae21af31590bb66ad2c288e0167f850b8170908699e94d2d416123 |
|
MD5 | 8d761f09c8c643fe70ba8669322068b4 |
|
BLAKE2b-256 | 1d671f4f86e0fdf07f7955e6bf6d62a1084ee9d9c0f4c639a85518c53bc8331b |
Close
Hashes for zmesh-0.5.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 134605dd1626b0dfb6efb81361d0811a84779cb5ebdf8f139d7998ba689a81a5 |
|
MD5 | 03f1b37bbefbacdf5154594fe22a2109 |
|
BLAKE2b-256 | bbdbaab48c9951d2b5c1f0dab439e85c58e12b519a9e97cd463888c20af3e21e |
Close
Hashes for zmesh-0.5.1-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac33115a57d9ef5bbf172a2266df4b361920d0ae7025c5caf4be0a42a67d5d54 |
|
MD5 | bdef457c9b3ae354b887ba694460d7a2 |
|
BLAKE2b-256 | dc9f8cf0fbcd539c870b42ec12b3baef2aa1bd0f9e0c0597255c17df4f6a64fd |
Close
Hashes for zmesh-0.5.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b217a10374f8f63602563bc867d4e9c07e8840919b6380801abdb479f3348d |
|
MD5 | 2e4bccda992c5902f10df3fa12024621 |
|
BLAKE2b-256 | a5fdb89e1dfad8e4e99c8e4c303b79a43da50656babc4dae3f386c224dfe5a2d |
Close
Hashes for zmesh-0.5.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6550d769127db9a6e2d13339497c034ec7066a432fec2ebfc37c78b597fc46a |
|
MD5 | 3eeb87308991f44111ff45bf5567732d |
|
BLAKE2b-256 | 1b64eabc3b958a26f5de72a8b280f6edb4090ff3f0b39493ef66a1dd880ad84c |
Close
Hashes for zmesh-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a686920305c615bcc1c8406254686003219cdb78bc0c9ad3d7d6a6ac3ede5a64 |
|
MD5 | ddc2bffb1c8274e033ab2e5b943828dc |
|
BLAKE2b-256 | b94c40f468eb61078385407272ebb6a2a73de3eaf1909a936de585e472a45108 |
Close
Hashes for zmesh-0.5.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dac0730a22307825c0cdfdf0d5659e5cc22a55560dc643bf2afaa45387d6840d |
|
MD5 | fe49de8d32a53b6387701b2e40a26da5 |
|
BLAKE2b-256 | 9e3ee9c17478916707d230c23d45cd925cc2730bf0d7d929c96de24499cede19 |
Close
Hashes for zmesh-0.5.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22818e8b83c153dac30f8eab4017ce7e180959f3d74a980b50d51aef0b9bda79 |
|
MD5 | 1b9111c104a590aa90301c278f9d8225 |
|
BLAKE2b-256 | e750a97ac05ed2e1014d34e2968d721613fef6ac2ad23ca6f9df455948653cf3 |
Close
Hashes for zmesh-0.5.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce3a1cc2b7a14c0a8c9f8b0ae6e73b10101abc1ec50f61f9485b04730c507f2d |
|
MD5 | 6b9246349d4499d299077648ccd235a2 |
|
BLAKE2b-256 | ad04bfcf4186d0e47193c99816845ea5b0c7580a3511e6b06140f4af76fdb910 |