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 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. - There is a longstanding design flaw in
cMesher.hpp
that transposes the returned mesh and resolution. We're working on a backwards compatible solution. That's why you need to domesher.mesh(data.T)
.
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.6.2.tar.gz
(368.5 kB
view hashes)
Built Distributions
zmesh-1.6.2-cp311-cp311-win_amd64.whl
(244.6 kB
view hashes)
zmesh-1.6.2-cp310-cp310-win_amd64.whl
(245.1 kB
view hashes)
zmesh-1.6.2-cp39-cp39-win_amd64.whl
(247.7 kB
view hashes)
zmesh-1.6.2-cp38-cp38-win_amd64.whl
(247.7 kB
view hashes)
zmesh-1.6.2-cp37-cp37m-win_amd64.whl
(245.8 kB
view hashes)
Close
Hashes for zmesh-1.6.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70979ae9c41845c46ccb969d061491e5fa8b731bbaff48af248307f65952c287 |
|
MD5 | 5249ea18ae7141a25d297873857bd510 |
|
BLAKE2b-256 | 72f27f5b6304e8750e73fc23e797c2c0cb18a686b189073caf813a860e8cce1b |
Close
Hashes for zmesh-1.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8233d6de29f213c5e4cd97be5b7470db98b26ec1f49aff52962a8ecda151b1b |
|
MD5 | 80db2e2d79408b8a1fdc6d8c14ec181c |
|
BLAKE2b-256 | 866380a81d650ebd1438037738f41d2667ebede1d73add5300fa487215afcf0a |
Close
Hashes for zmesh-1.6.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a897047ecc8e8e29c248aa3be4bd38ee9fa005621c790a2dabe79b264ac67bc2 |
|
MD5 | 4835e1f8d75ad41e725f8f9b38e71f2e |
|
BLAKE2b-256 | edd1f33095ddadb99ab4f98a774f386c3aaca238e77043a1959817b1afab22b6 |
Close
Hashes for zmesh-1.6.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd4a4b1447f6245b40956c23b2bcb30adfd2c3b84e1967c2a93d8e7e1f1ac51d |
|
MD5 | c8934ed742dc3338deb1910d37c21eb3 |
|
BLAKE2b-256 | 01fed7bbe73f314a9f6e013491e01e26a61a34e8557f3f33a1d458e51905aadf |
Close
Hashes for zmesh-1.6.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa85b2b9668917efe526d6fefb4f5b2469594101432bfa04e55f93c0f6ecaf1 |
|
MD5 | ab309d37fa6da791de906d76b4fbcdce |
|
BLAKE2b-256 | 2f626eb2f529cf322de1bc63293905d33ecdf5edfd7720fb92f35520172a6639 |
Close
Hashes for zmesh-1.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e16dd74ac66d60788189a38ce1094dcebf3a613c8b5591d626f0fc8e6f7ec7f |
|
MD5 | a5eb365ec47db7036a23b4e60c4efd9e |
|
BLAKE2b-256 | 65d8c18fdf7352a5985957fffb9b9909baa82514f82d8df93114c6d9675362d6 |
Close
Hashes for zmesh-1.6.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75e8db2aad71b49ffddb9d0d5a56049915ef44b0c7a2d35fdf4fbf879255a2fc |
|
MD5 | 325fd37aa073fdcd22a3b35f20311499 |
|
BLAKE2b-256 | db05848329e182e6dcca929861941defbafc8a65ceeb34a7d2788aef830e8e1e |
Close
Hashes for zmesh-1.6.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2574d77a234b1fd6e20995a4667f3bbe0ebf18db5c6684fb5da2d5d1e0884b0f |
|
MD5 | e56a76668905457c1af8da49db855fd7 |
|
BLAKE2b-256 | 5eea1066bdc906754d4fbafda8302f6e024a36436d4be6f66a2a56d538c90643 |
Close
Hashes for zmesh-1.6.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a9b0b35a4c9512d5ca4b87b4f2356496ff7a1ba6a74cf2bdb78138e31b41fb8 |
|
MD5 | 9decd878ef16f01cda27d65a9bc6002e |
|
BLAKE2b-256 | f007d4b6e6a7c3d0b67e308eac63560a846a91ab8758be5d55f75b039fe0d329 |
Close
Hashes for zmesh-1.6.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee0d8bb1a180b3e8e25e8916459f349d49629c9079dd56d3802a9b29126ee9e8 |
|
MD5 | cf0443ac1adde66e71c397f3eb022868 |
|
BLAKE2b-256 | 77fc5603697b10d1c7e044143807fb6491316cbf1b229c03015814f5f266ab8a |
Close
Hashes for zmesh-1.6.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77a10a3974288c18b97d0c9887eff2f6293f1f19e2303f92870edf7c0cd35c9c |
|
MD5 | 9135b03389c90654b7d83a463d69eadc |
|
BLAKE2b-256 | 743cf402025e16864fbb200ffb7e274d10bfbfedbd05938372f710f8ff350f80 |
Close
Hashes for zmesh-1.6.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 289e75cbdb84866089e7f7a70308b1cb4e3e98df7dcddf6ae29f6ede9e5267bd |
|
MD5 | ec6f1867b41fad83f0f0d66bc3e47da8 |
|
BLAKE2b-256 | 65f3a36fcbe587f8230ccc88e6bebd946a78fc3efbc2b6a639ae0ef10870bac4 |
Close
Hashes for zmesh-1.6.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6432c2a962b3c9c8991256e50736083fd8b573bc1dcf986509207bc9ad284ba |
|
MD5 | 4c05463da80fbbe093280093b9a5c02b |
|
BLAKE2b-256 | 92703b59e4c1fbeb44adf8eb18e695760ffbd33baae98671fe1760a813f2c826 |
Close
Hashes for zmesh-1.6.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab7c23cf02aa3e4be74f89d892ed82c45be0cf25ba750816061b7a8e3e8dde31 |
|
MD5 | a89775f1c00bec476a8b4c481bcb5faa |
|
BLAKE2b-256 | fcbe0cbc62fe93fe6fb73f30e5a284df39fb1528e6c6b6592ca2e7ab97d42488 |
Close
Hashes for zmesh-1.6.2-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d2ca639aa3b9cedbd80203bcefc6c6ede31a11cda824abe6be3ce573289148 |
|
MD5 | d31e508a81e5675bf9e1492b0e00aa88 |
|
BLAKE2b-256 | 40f19d14cd2f4c996b9eef02bbc89cf5397c5a29120c035f9c19a421fc276ecf |
Close
Hashes for zmesh-1.6.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbcf48940268cd51b13a293a1b9449b048e91178d86647e87565c9844011a290 |
|
MD5 | 4b581844e25fe25d19a6ee511b91b1ff |
|
BLAKE2b-256 | c241cf430507e0b497211a14d60dcbaae37b6f563aef4a6bc6c429e2449163c1 |
Close
Hashes for zmesh-1.6.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddf9119cfab90aa552aa8c9b2a267b31d7bbf9577d3dc9ff724c22748255dda2 |
|
MD5 | c872be5e449b197f649d53958dc06140 |
|
BLAKE2b-256 | 537133c04d2cc04dfe702c511311c1e825077fdc0c985103f8d06acdee1c830f |
Close
Hashes for zmesh-1.6.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf0c974a1f7d942c56c5414bbf0570ac1a7678c446a0d36bfdd1234a4574396d |
|
MD5 | aa6c30e2f503635c7deefb08fdac72e6 |
|
BLAKE2b-256 | 5e7413d85c2aed00b5959c59d5081f0bf019839c399863e76a335379ea82bc05 |
Close
Hashes for zmesh-1.6.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 811c869754f69a460f471e5eb34bb6e7880e9b4b80abf479d6bced4418a49cb8 |
|
MD5 | b68ce446d2736dbe4e35a3135fae9302 |
|
BLAKE2b-256 | c95143f9d584d651d8d3c0ac361ff4766bcbb2d3c79e1078e6aa2cc1ebf919c0 |