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.1.0.tar.gz
(9.3 MB
view hashes)
Built Distributions
zmesh-1.1.0-cp310-cp310-win_amd64.whl
(245.5 kB
view hashes)
zmesh-1.1.0-cp39-cp39-win_amd64.whl
(245.5 kB
view hashes)
zmesh-1.1.0-cp38-cp38-win_amd64.whl
(245.4 kB
view hashes)
zmesh-1.1.0-cp37-cp37m-win_amd64.whl
(243.5 kB
view hashes)
zmesh-1.1.0-cp36-cp36m-win_amd64.whl
(243.4 kB
view hashes)
Close
Hashes for zmesh-1.1.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f405c7f229126defbe93f2165d55b3404db00957300b67e80c3aad81875ee3 |
|
MD5 | 3170b5cc5d7556dfe44acabf972f9058 |
|
BLAKE2b-256 | 360513b231196e48259128ef72bd27ae66c630251edb615b4c3b737ce4c12831 |
Close
Hashes for zmesh-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74ee7d65a4860b5485bf72bbdbe8b66403da7d08ebc56c47ab03b92a51861fac |
|
MD5 | 7b527a15f9f85f6480dd5914973a22d6 |
|
BLAKE2b-256 | e090551fd454f453b686d3fe5155ab0f16294bfe4d6f8aae99e4074e7456ff2d |
Close
Hashes for zmesh-1.1.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b252c434f2fa432d089b7728e07cfebf0d6e6b0c3d4758b2393976ddcc9f7669 |
|
MD5 | c53da816ae359985aa170db88fe5b346 |
|
BLAKE2b-256 | 347c1aebf9588825a5517f4af299229e5e9057a676915ab1843f14493945a609 |
Close
Hashes for zmesh-1.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94e98cd4eabff61d4f82a9bf1da0a6de5b5027687f10f7df9b124dd6d561a004 |
|
MD5 | 7ad620f99f9ef3da0e32bbab471d624d |
|
BLAKE2b-256 | cd07d360b12b1d365d428bfbbceee4877d1ab021dcae93a8111723dadc3380b4 |
Close
Hashes for zmesh-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56924c06f22abac8c2e71944dc9820b2b3e6de29107c719142d6f67e285affa2 |
|
MD5 | ee16a6b32e607bf7e623a7d5fe69c9a8 |
|
BLAKE2b-256 | bc7669da548e8305be346b011d923db8f05a76d807543ee89e74552fe50faaeb |
Close
Hashes for zmesh-1.1.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c97f061e8817d10ac7f4aa734c4b73b76e74753dd26a3e17337861679bcc231c |
|
MD5 | 52143167ab5dd0f0e9a0c5fdcc2cfdb6 |
|
BLAKE2b-256 | bf327214d5b1da75ec7441c0c60ac63dd71cea1a5e41002e4172b589c9b1b1a2 |
Close
Hashes for zmesh-1.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d3e2efd5e942a411ff7f321891b01bf2d247c27dcba06dcfbb31743fa207dab |
|
MD5 | f2ac304365cdbe8947ff0126b69c9889 |
|
BLAKE2b-256 | a06c0558db83df5c24bd909c7bd9cd291d52a848ec51f7e57fb9c9a6baff4428 |
Close
Hashes for zmesh-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1fb35827047ec2c00f0478b6d311b5dccfcfad02c384cf18f765ea734884879 |
|
MD5 | 7555bda7cb9ce52b1903db036f14dd50 |
|
BLAKE2b-256 | c7b9735b375d5f764ed1de823f214250367ec0d2547fdb0cc049b26ca66d0187 |
Close
Hashes for zmesh-1.1.0-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ef99b980ccb5fd78f719eb5aaf4016c4b11cb7c7fae24a243132f9f6b7951d |
|
MD5 | 63e30aa683ba22372b66ea4c861da7f0 |
|
BLAKE2b-256 | 2334646610899b57c86928bb0017f5a612d469e1e10677833e1068ffda3bcebd |
Close
Hashes for zmesh-1.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2bb7f759a35525b58d33d91a3ef72b50e0910040bc194b61cf08baae6daa9fe |
|
MD5 | 242928a9a3308a021644b80fa4bd1a88 |
|
BLAKE2b-256 | 7e02dfb6eb2bcc007cc12f779b9f4e81183a5f28fcf99f26125492f9477f91da |
Close
Hashes for zmesh-1.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdf2c695500b802ab7ee90f597ad45eee9f13202623e961919ade78234f0b779 |
|
MD5 | 6f2f55e4188f8255d7a4764c492921a1 |
|
BLAKE2b-256 | 554fd51c8fe39ad2f3a5a35e1347ddec13f66631cdf1362126e3dc971cc86e56 |
Close
Hashes for zmesh-1.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc61ba44d02ced0077d9bce8902ea0cc06cd95badd9a48013a8daa64b6a85573 |
|
MD5 | b5f524aedafc3acda7a604dc8e88c476 |
|
BLAKE2b-256 | 5752eba42b91eb134ecf033a5dc03161d55e8e560feb0da2b68a3a530342bfc5 |
Close
Hashes for zmesh-1.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bfc452cd5ed52a0996af1df70b9b18f5dcd9d5bf25871f64aa425f5c1da960a |
|
MD5 | e9d2ca59156f51c75edfe50297e4869c |
|
BLAKE2b-256 | 32d720916f29fceeee98b2414e24c2fdf2404dc0350574a6e9ac9b3b0fa5f393 |
Close
Hashes for zmesh-1.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645300fd9efe39639f3d9a6986f3a82d945fd1cdf0a7afccd9b311fe47c4df5a |
|
MD5 | 6f8b00e4f4128129ec05f9a95b83c3a2 |
|
BLAKE2b-256 | a56b6b3c9904b2e047265a3bf2d2beab02a2bd505159c2943168d75823027994 |
Close
Hashes for zmesh-1.1.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bcc3bd2164870369993ec6bdfc3fb5779941b53bfb602db26b345e8942cf405 |
|
MD5 | 422fb6cae123c2eadb2a6842fde3cb40 |
|
BLAKE2b-256 | 2367f8c60922bb8cbf9ec9a16221311ec2e0e812f9b6f594d004a3120a114451 |