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(
obj_id,
normals=False, # whether to calculate normals or not
# tries to reduce triangles by this factor
# 0 disables simplification
reduction_factor=100,
# Max tolerable error in physical distance
# note: if max_error is not set, the max error
# will be set equivalent to one voxel along the
# smallest dimension.
max_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 reduction_factor in get
reduction_factor=100,
# same as max_error in get
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())
Note: As of the latest version, mesher.get_mesh
has been deprecated in favor of mesher.get
which fixes a long standing bug where you needed to transpose your data in order to get a mesh in the correct orientation.
Installation
If binaries are not available for your system, ensure you have a C++ compiler installed.
pip install zmesh
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.
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.7.1.tar.gz
(262.4 kB
view hashes)
Built Distributions
zmesh-1.7.1-cp312-cp312-win_amd64.whl
(132.6 kB
view hashes)
zmesh-1.7.1-cp311-cp311-win_amd64.whl
(135.6 kB
view hashes)
zmesh-1.7.1-cp310-cp310-win_amd64.whl
(135.9 kB
view hashes)
zmesh-1.7.1-cp39-cp39-win_amd64.whl
(138.4 kB
view hashes)
zmesh-1.7.1-cp38-cp38-win_amd64.whl
(138.5 kB
view hashes)
zmesh-1.7.1-cp37-cp37m-win_amd64.whl
(136.6 kB
view hashes)
Close
Hashes for zmesh-1.7.1-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 487f6d6de9282343ce10f9376d13ce4bf7c914585d12d15119b9cb0e254f7810 |
|
MD5 | 25a87d9a62002068107b73c732804bb3 |
|
BLAKE2b-256 | bb48dde89c6be2fe37df2f3ae42b6dbffb528dc75f2941bd0249305bd7c23262 |
Close
Hashes for zmesh-1.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea86be2ed135e7ebcfa2bcbcc4aae069effc047410ea9e8327755a846b0a4517 |
|
MD5 | 314b3df1c6b6ec2d3c3659aa19131721 |
|
BLAKE2b-256 | 3137ee7410387a8f9ecac69682784d4b16963c273df93b96223db5f1adb2ecc6 |
Close
Hashes for zmesh-1.7.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1988c05061470bb0b3caa0e720723877a8648e0615019b51c5f7d1811a37fa2f |
|
MD5 | 143459348278df4a8604dc469471d912 |
|
BLAKE2b-256 | 8dbc0c9e15cc8f1d8fa621ca064defa5ea56ef9c01bf75d787c010f771a1438c |
Close
Hashes for zmesh-1.7.1-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf4710e0e2664c2d91b19b0ebc00654f4bc2b334a8f135292311050b7014daa3 |
|
MD5 | babb7a0a079eb82c797cb735c973f73f |
|
BLAKE2b-256 | 49226ec4da864e20e9688fec9313bfd0d1a93b9271c78f286ee8349cf95cd134 |
Close
Hashes for zmesh-1.7.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9590c68c6803cd7edd0823222c7766a79048a58836fe2feeb5fad80722f33302 |
|
MD5 | 898cbe21f070b644ec37a56056ee468e |
|
BLAKE2b-256 | 09f8f2dc185df573d7f213492f26618903c8b6a888853e7382d9863902f24234 |
Close
Hashes for zmesh-1.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 556583003d8ff14216e5ebd5edb01fab14c0436cb4c6bf0abbe3836ad947157b |
|
MD5 | 194f7039d2da7ed156f5d6bc783de52c |
|
BLAKE2b-256 | 4ff0afb5cbeb2c71c010b4e33692ffae2c778f59a9711d9a89a33f5f91e1d1ac |
Close
Hashes for zmesh-1.7.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df83fdc74ea98137d683e005fd4b9250dc964f8dbdcbbc2dec28bf28e11b0e24 |
|
MD5 | eda81f46bc5054d163ff279324a2b018 |
|
BLAKE2b-256 | 336c3876779187c05850d101843eaf1141b01f9aaab42442d630417d459f7b2f |
Close
Hashes for zmesh-1.7.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a5104c9dd0a1ab1491abf392b6fa90ad6e766422292a84ecbe237c7b6f5178 |
|
MD5 | e9e43a2e6064223123aa7db8a47f9b56 |
|
BLAKE2b-256 | d9511a22e9c5696095c37a3390e1e9752e296d20fa95d41eb7dca043766665ba |
Close
Hashes for zmesh-1.7.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cd3acf68d9914d82d7e13fed0a87416417ce667196364f5bc887fda1c7fd9fc |
|
MD5 | aca97631e92ff150b82fae78117dcbc8 |
|
BLAKE2b-256 | 70e3f1ec0023d2f2280c4da38704f0132eaf0edb8ced9aa111bddf9dae77c4eb |
Close
Hashes for zmesh-1.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01cddac99995a7385afdcd2ce805910484ccb0b5a938583a44e5c4a1bba04104 |
|
MD5 | 071aef49cb3625054f0d1df98c9e3314 |
|
BLAKE2b-256 | 918d1fa8c10af61246840ec2d6f96305ce8b36b44b76c1ed5aa6d4ac52831a57 |
Close
Hashes for zmesh-1.7.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 350d31661ac5dc894fa1f968293b106ff4f9cf6627c5725ce9e9291150a6f1fc |
|
MD5 | 3e8b3496abab6f8604d767b0b5f02e03 |
|
BLAKE2b-256 | 39d44e51b1badbc89fe2285df95ec556780f80a637f53c6e96dc98ce2a0fe56a |
Close
Hashes for zmesh-1.7.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2c10e299b01d00fcf4e2dd28e06736db5725048d192594341424c2cfafd8752 |
|
MD5 | 8132d299686b3843f2cb6276a99b0df1 |
|
BLAKE2b-256 | f9ce973f5378126653e33c852529f7993a62a7d8e39018483f36e1bbb98ad2e8 |
Close
Hashes for zmesh-1.7.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30eca0cd18df69eeb5232d068fcb2175be94cbbfb750daaa08637d6fc4b33341 |
|
MD5 | 6a892ffb4f44966c929edb1fed875e7c |
|
BLAKE2b-256 | 5ab77118e4911b829631cd25969dff0e58b9d8c583ec8d344fec54989e1e984e |
Close
Hashes for zmesh-1.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ba78d93cd1334726da4c0a7d249de61c06a6fe1801ac1c84323cc24ff7aaaa |
|
MD5 | 37a7cada70b4baaff825b1a439169074 |
|
BLAKE2b-256 | aa7e3f8ef6c58e5530b6e75d4171e88cc975e8e816559f7f99d3769ae953721d |
Close
Hashes for zmesh-1.7.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af73e4ffe31b5db7024ef40a947558c9235392080aadf1ee8d96607b7b1aaab7 |
|
MD5 | 0c7f8a110276230be0250fec81239832 |
|
BLAKE2b-256 | 9bb6f21d7d1f0e1337841d1e731c8b82071b7bdd9c92557370505f9426b5a41d |
Close
Hashes for zmesh-1.7.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6f43e00a33f2916f952d8d4d1546f2905b122d18d086f894983aa4aef82212e |
|
MD5 | f3fd6b235b6012b610a3dc3f8ffc5f06 |
|
BLAKE2b-256 | 05fc59899df1ef1502a3e3039afb05c63899563318cc9acbdc7ebbc7cff11897 |
Close
Hashes for zmesh-1.7.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ba5847b9395648bd96c1d9f72c777d24167266e8d9400182d223975a0a0ad79 |
|
MD5 | 0ce1a488652ec5d3021744d5ff3f2b45 |
|
BLAKE2b-256 | b3791d59f21b1d7b1cf008d830cbfca87ecf96c198b8a855ec328410a152ad5d |
Close
Hashes for zmesh-1.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 216f2fa50928e029bed7782bf084b678c7e8f563db37ce332a92ee7eba006a56 |
|
MD5 | 21138285b672e47e35755d0797b2e299 |
|
BLAKE2b-256 | bc8a9d388982b3a5c1401b6d3197b979dae13f5c64e20e542332be287877bdbc |
Close
Hashes for zmesh-1.7.1-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64f2334e95208930c25241565b11cc8c1e364eb1305db6ded6fd87a2c04e07a4 |
|
MD5 | 72f8b77c5cab4fb25c320a02e5a1cc60 |
|
BLAKE2b-256 | a8a7b9fb5b15c3e2d8f7465df131317747bfaca9dae5b6784fc914f9f4911ef9 |
Close
Hashes for zmesh-1.7.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a4b395323b03a38237a159442c4afbf77cca5d65776a91087bbe4977ec4c56f |
|
MD5 | acbd835c01ec268d6549cad20ef76b0f |
|
BLAKE2b-256 | d1964faf60e807033adae72663bd32302223a9a0d7f90e37fa86fa5265bdb5c7 |
Close
Hashes for zmesh-1.7.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84b7ee80229bc5ef628f4e551631c95f8066d184b6dfe69561a965e025f36d20 |
|
MD5 | f2559f5a663ae6ee70e1caa68b9439fa |
|
BLAKE2b-256 | bd2b28fecc4d4b6c2ee77593d3d080aca36a4b4e2b01d9636f38221144496109 |
Close
Hashes for zmesh-1.7.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 324fd5c25e01b107b55af3b169e4542fe04c9015b0eb46f4271ab825d0e7e15e |
|
MD5 | 55ac453e0a941d3d31d3b5c1a5611700 |
|
BLAKE2b-256 | 76abb5b9f6bb990bb14f0cd74578f53bc98afe478bce2d9dfb6364de082d45de |
Close
Hashes for zmesh-1.7.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cd27c9054b8c0859584466d9c5403e043b19de66965c37043f694b32d07dcb2 |
|
MD5 | 179d1120832ebb1b1eab0ee91d29ae1d |
|
BLAKE2b-256 | 867444fe0cf3c5f46b2b2765e83e9c8e01ac426c69e2403137a218303b2fbebb |