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.4.1.tar.gz
(321.3 kB
view hashes)
Built Distributions
zmesh-1.4.1-cp310-cp310-win_amd64.whl
(253.6 kB
view hashes)
zmesh-1.4.1-cp39-cp39-win_amd64.whl
(253.7 kB
view hashes)
zmesh-1.4.1-cp38-cp38-win_amd64.whl
(253.4 kB
view hashes)
zmesh-1.4.1-cp37-cp37m-win_amd64.whl
(251.6 kB
view hashes)
zmesh-1.4.1-cp36-cp36m-win_amd64.whl
(250.9 kB
view hashes)
Close
Hashes for zmesh-1.4.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64b99a6d2156535ae7a4ba0477fb967b054b188384ff1a63b78b2bf43946917b |
|
MD5 | 85a5373608c8fcd55b79fbb4984c10dd |
|
BLAKE2b-256 | da57d38148a2b1351d5c0cda5353bd24b64ccb19bed7174524ded85d94776a7e |
Close
Hashes for zmesh-1.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c95ccfdf38d82e8e2286dc4f7c0add7c3651c910cda42beda624bc0f203d908c |
|
MD5 | 86233e7fd1601d58d9ac0e622800563a |
|
BLAKE2b-256 | 7b81037a6c9909dbc76148aae7dd605f0ee87bbdda3d1b15acad64947c36fc4f |
Close
Hashes for zmesh-1.4.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c29978948a5d269a5cc973eec87a708c626946626cf84e89929e21bf18743d36 |
|
MD5 | ee57e8629b7ff0225b7a718c5c155fcc |
|
BLAKE2b-256 | e22bf7413dc014bfff04a01274d5fa02ec897f3b98bede05f11dd95d05532701 |
Close
Hashes for zmesh-1.4.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64982e3ca63261b56364f6240de5ad50440d022da6b4716f08d6cd6b86535c39 |
|
MD5 | f4a715fb8f24e670333e1c48731bc069 |
|
BLAKE2b-256 | ab9d46276c08d9ed9c75436787f9af2923f460acfa1783810a005483e815e1f0 |
Close
Hashes for zmesh-1.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1c56c09d5088854c594609b08ba26041f471a7afe6a9387e9ea5ca9707d076f |
|
MD5 | 07e159ab8a31b7a54681b4d2d5c0a08c |
|
BLAKE2b-256 | 9853d1806651aca114ca57d831a23a76dd236f7a3ca0e01f223547ebb4d4d544 |
Close
Hashes for zmesh-1.4.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a213f9e2838367febbf002bad4b37266dac702005e0a9a10cb85406cadad114d |
|
MD5 | 07490ce907d9c98dfe733db4de5c90e7 |
|
BLAKE2b-256 | d96e8370e8b85dd35301e8831f8087fed4babb67d740444b46b677e7b723d4d9 |
Close
Hashes for zmesh-1.4.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f4936ea402696430917c9a199e098887bda1c41f621a6df9c66d06989c763e1 |
|
MD5 | 7faffb5b8017e4e8e8cdf8844b23dc36 |
|
BLAKE2b-256 | b68f369cf62e51a20d98e57f0f393912168aa2e0844c20591428b995ef0dc0bb |
Close
Hashes for zmesh-1.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25980b0c522bd811222503eecf5b213eb338c8ba95600172c0d7f66faa098c26 |
|
MD5 | f9e70f7fadd7f94ca80642d58d9b3165 |
|
BLAKE2b-256 | d0fdf72b2e9733801477e1aa4a1af9f1369f28d5709beebe0b9c5b03dda155be |
Close
Hashes for zmesh-1.4.1-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 489b9579f3eb9d4f662d64325adf958a16b03949c0f9f0245c57f49f24ffa9a5 |
|
MD5 | a29ed24bfe60cec6e5d90f92adecae9f |
|
BLAKE2b-256 | 648d12278016968f46a18a79da81db1431255f54e9c37df0708e64d45dc850f3 |
Close
Hashes for zmesh-1.4.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b23b4e8ea09a6939d93fde3d1d2e3a24abd889c94858469db1fb8875fc7d9fce |
|
MD5 | c1f8dd4abfed791796e489c4e89140ac |
|
BLAKE2b-256 | 2610cd0ab813062851180e9459f6042c2dfd19b43c9705c3d652b00e9b0d915c |
Close
Hashes for zmesh-1.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa12cb2373d5f8eeb301b6e9a7f33fd6f8bfc178d330e3cdb903972394f5d304 |
|
MD5 | 634b452491d4c27e3ea87aeed58e4fee |
|
BLAKE2b-256 | 704095f15d86784afe8d293190a8f707b1e1bba6fe946f14870e050826def61c |
Close
Hashes for zmesh-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4718122761bfe72343066b44c33071e7c078ce72c17de47ebcb183d29d9a377a |
|
MD5 | 0abf59d423467fc08345d24f86134bc5 |
|
BLAKE2b-256 | c6b39d4d483501c748d09a414a9fe904fe467e01e828a27861d534ee93900628 |
Close
Hashes for zmesh-1.4.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 018d437257a80f45bfc11688f2bb084acf86416b89e949eb0597ad956911e646 |
|
MD5 | 6141b0a93b20db463562fc598da17a49 |
|
BLAKE2b-256 | 22cfaf383e115dd693be8bee37040e435fd8b680d2d862f99f42f481e1951cf6 |
Close
Hashes for zmesh-1.4.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c08723e0b1cda159fd7bb71110e7d523454d23984e19e4d72dbeead8146ad0b4 |
|
MD5 | 6f984609ca4cc52d8108731073164cc5 |
|
BLAKE2b-256 | 7f8bdfae3c64a1f1c06e74cc6d8418e579f2136a651378380a0e46cafeecb788 |
Close
Hashes for zmesh-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae406cdb3fdfcd15f700dd9b5be87ccf729c31c253f848e92793c0da1284c06 |
|
MD5 | ebbf0f63201ae0290d353541d508cb6d |
|
BLAKE2b-256 | c5d4ee7e8a81fd754601d53c2b3832324ff94f5d04674572b57fed896bfc2576 |