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.2.0.tar.gz
(314.8 kB
view hashes)
Built Distributions
zmesh-1.2.0-cp310-cp310-win_amd64.whl
(245.5 kB
view hashes)
zmesh-1.2.0-cp39-cp39-win_amd64.whl
(245.5 kB
view hashes)
zmesh-1.2.0-cp38-cp38-win_amd64.whl
(245.4 kB
view hashes)
zmesh-1.2.0-cp37-cp37m-win_amd64.whl
(243.5 kB
view hashes)
zmesh-1.2.0-cp36-cp36m-win_amd64.whl
(243.4 kB
view hashes)
Close
Hashes for zmesh-1.2.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c167095b07dc9ff118bdae6b8dc95c72dfbfe713122353fc495414eb856783c |
|
MD5 | f96a7362e57c16ae16fd493c005630af |
|
BLAKE2b-256 | c74b73a85720c9e87abe17926b4bf078175744faf191fda65a3f34297102418c |
Close
Hashes for zmesh-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a1a651776018601c74193211e4dcb67a894d18dcca7b6fb1e3919469967bef8 |
|
MD5 | 7f0a324469a08945a449b96289ed1301 |
|
BLAKE2b-256 | a3cf59d20c41a3823cb8c874abd1b293b667d1e7fbb4aec4cabea8d7f72ad36b |
Close
Hashes for zmesh-1.2.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d81d39d75ab1002330cf06d348439cdd4630ebc9a072d9aaac397ce8909f09d |
|
MD5 | 346a98fa92e3cb53443ab31d594c5af5 |
|
BLAKE2b-256 | f30654c7a03eacde6140f4eed815db9c1c4af133f9959a944bbd005f4b67fd16 |
Close
Hashes for zmesh-1.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d2df18df6738cda01952c2bc9c801f46a8b4f5caf9921d1447ce1234686d1fd |
|
MD5 | b7dcec6246ad53d99274b4186e5233af |
|
BLAKE2b-256 | 643618d4af766b1cbae8d87f29a23d838b8fbcd0cfece09bb6b2049c284aee69 |
Close
Hashes for zmesh-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95a73aea2d10e93af6bb2674f1c0341a70687e0bfa444fc144cf33125dd03c2f |
|
MD5 | 6402f6acf26e5b47be505e82ead13e31 |
|
BLAKE2b-256 | 3650a88a88dd9337a95d64de43557d1c7b62abf6544e70f524d99802e5f12adc |
Close
Hashes for zmesh-1.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ff43803a0bbd0e77fbba6d47759b37a6a2b350f1c5fb6a0ec0c98581d5166d4 |
|
MD5 | fd1a4af88c3b99fb7f045f3bf64e11c0 |
|
BLAKE2b-256 | bb144fd4c070d639d4fda63b23a110e587441b4e328ff60005cc67ae92aa6d49 |
Close
Hashes for zmesh-1.2.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8926b9372d090e7d2dd85023d9d0fb15245bbfaccb74c008369dafd7603768e |
|
MD5 | ac1cea4b268503844b7241f03d6f0346 |
|
BLAKE2b-256 | 1f2d409873765e674dc4d288278ea9612b02d62ddf4b46a46fda7dac4f9676d3 |
Close
Hashes for zmesh-1.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bb780c98f0c546f5e8cad0c7508fa1518b9ae067f9bab39ea0d51f7cadeb2f5 |
|
MD5 | 90cb17421fbda3ea717b9e1a0a7533b7 |
|
BLAKE2b-256 | 9db05d654cdfe35c12bb3bd372f69fbd04a5ce56c91daa45204a3e2c32a1984d |
Close
Hashes for zmesh-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bcf167c5463e19af7d8dc48d8cdf05536a12aaa8eeb6e0ded554b54b6c49345 |
|
MD5 | ac95f6b90af2cb632571b59d9138097f |
|
BLAKE2b-256 | 8eeb8c643990d363cb9edbf5d79083ec59c96d2e49cca14b5f4912a6e8b29d1d |
Close
Hashes for zmesh-1.2.0-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9cd14a9504bdf57c33ddc53b857e925d0bf12975df9bb6bf94d7309e2dc4c4e |
|
MD5 | ab2ef75aa1fd6cff59642f0690a25ace |
|
BLAKE2b-256 | c3bb6cd6796aba33d5a7d7e1ce48f12ae963dec5b769532b6deb9765e91409c4 |
Close
Hashes for zmesh-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b51b5560440c7e6f02eeb43789ae91ad747ecc1a91a496f9f3943d5a3394ce7 |
|
MD5 | 2d246af962c23455484a471e2e2423d6 |
|
BLAKE2b-256 | a58002a6a5ee573ad8f5e4cf52183d72904f6f5e6002d322888edc9ba17696af |
Close
Hashes for zmesh-1.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bddeb4c0d38f8fe4a52cba7da01223b04fdc3dc2ddde424afba444e9170a7508 |
|
MD5 | ac55dabf660b7f95c1986664a39efa3a |
|
BLAKE2b-256 | a388f033ca9506f8fbb1698657cb1a6e19bdacf54ffcbe381b30e9b40b755196 |
Close
Hashes for zmesh-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea373089cc29c1187252ba108c7ed5344c7eb4045b8e88f16babf64725d90121 |
|
MD5 | 07dbfad8d92f91cbb1716e73fe97879b |
|
BLAKE2b-256 | a1980bb6a4b99b3eaff999f21c609895968e44c9bb46f30f276f884a93201745 |
Close
Hashes for zmesh-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d79f79291f9e2fe86ac445dd6a086c7a5f6ff3c9f14737fb8c7a9d82f2f485 |
|
MD5 | b6446f4e2ea1b96ba05380ce0436de3b |
|
BLAKE2b-256 | c7189761135219f5678fa98838009ae3d9f2c0483a90ec01091dc7abc3673c7b |
Close
Hashes for zmesh-1.2.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aad87c1bde37868a4478136fa0d2756441c782ae93a2537a123b898b83391af |
|
MD5 | 0212bc16d2ebdbd8a897983ad9e02257 |
|
BLAKE2b-256 | 9fd22c34e0406bc4a4799afb3aa1c561a7b3692b738b2e3ac581a5104295b36c |
Close
Hashes for zmesh-1.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8215dfb886bcf702afd7e03185573a4fa8a1fcd200885fa4b3bc768d989ba42 |
|
MD5 | 50b558613850e2996a19949eb0778e83 |
|
BLAKE2b-256 | 558069d56cb307885fa0577b78b678b8ea05ec9d3dcf97bddbc7d84364c50acf |
Close
Hashes for zmesh-1.2.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a8806f30dba5181a246ad08af5083c010a246ee018569b826cc747a69fa952b |
|
MD5 | 37498a4f85a573a4190441374a8aa401 |
|
BLAKE2b-256 | e4bb4d3eb4078787b33011ef574491158006fa3a170784454c03a6d38343f47f |