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.
- Input labels are converted to uint32 or uint64. Use one of these data types to avoid a copy.
- 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.0.0.tar.gz
(312.3 kB
view hashes)
Built Distributions
zmesh-1.0.0-cp310-cp310-win_amd64.whl
(245.2 kB
view hashes)
zmesh-1.0.0-cp39-cp39-win_amd64.whl
(245.2 kB
view hashes)
zmesh-1.0.0-cp38-cp38-win_amd64.whl
(245.1 kB
view hashes)
zmesh-1.0.0-cp37-cp37m-win_amd64.whl
(243.1 kB
view hashes)
zmesh-1.0.0-cp36-cp36m-win_amd64.whl
(243.1 kB
view hashes)
Close
Hashes for zmesh-1.0.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 284e843d173b3b08edb5562530c7959abb64d45b1cfc8cd87fbd4ae79b2ec4d7 |
|
MD5 | 8ecd643401641ce8e0ae453f129b27f1 |
|
BLAKE2b-256 | dadc5d7ee9810274f93959833260b8c172951547b8a1c9c8bdc0764c48e0f011 |
Close
Hashes for zmesh-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0479b8daefd7b1124b17f0a2d415dc27f32d4cbdc417f4fefdb632e5fe40bfd3 |
|
MD5 | f3f31f65a2ac53ec29d20a011295abf8 |
|
BLAKE2b-256 | 15d316b1a8b805e1db988da445b6ccdbb76c2cd8828c2c9b2f55b89cc98e4afa |
Close
Hashes for zmesh-1.0.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d62713b2f5fd45ed15023d9ee70cc439319e744a9df65a12c59f1d4040afd26c |
|
MD5 | 393035ac351cb2cfffb224e0141f3d15 |
|
BLAKE2b-256 | 4b6c76c61a6525f7ecf3b6fce040f496676eaf77d456b09a1b3dea210def65b0 |
Close
Hashes for zmesh-1.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acea384bdce0ffc2f84437319ff28b913cb09b38a0f797930efe2477179a99f9 |
|
MD5 | fad3385e5a480b012e5e0afd49312cd4 |
|
BLAKE2b-256 | 0a89984142f2b4b2b2fe4bba897edd3759f9ae3197d358251bb7a351a107c1ab |
Close
Hashes for zmesh-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc24781dfa2e9af4f1a56a41a181980d7aafa3eac388fb0d463ba0058b58262f |
|
MD5 | 439f83153abf0b216abb875724f94dcd |
|
BLAKE2b-256 | 62d8a23dbf78d8bb90e6af9890b8ac75900db1270ba0a8cf5aa4c06bb6349fcc |
Close
Hashes for zmesh-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cbe741dadc46b635c478b18da5a498871c39c552b0dd45bbd84bce245820efc |
|
MD5 | 98790aa31fc9c762595026cec07729cb |
|
BLAKE2b-256 | bcc5f4d0f76d340772f056c9ab2cfa0a24df88a92e905c38f7b1ba0656313b35 |
Close
Hashes for zmesh-1.0.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6393ee39df8432fa0b43fed885d84fff3c872c86def996e21120839be49ef50 |
|
MD5 | 7d4942c26f81be563aa1c4941d36878e |
|
BLAKE2b-256 | b04dba7710a0ebe1056fede6a56c7f7deb65bd2274d48fa391d13e0200a72bb5 |
Close
Hashes for zmesh-1.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97bb80f28c50513c381c50621edd96426efc843945195d1a9c5e65873718e1bf |
|
MD5 | 6b21d679af8f689c2a025b8dad596868 |
|
BLAKE2b-256 | 095f9c8a47ac5a3d2d0892e7bc62e0571f0880ce51b361b55a8c882762664743 |
Close
Hashes for zmesh-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57ebdf2e4dac9a0208c71193f655bf0cc47e4de41351aa0ad14af50a9e7b52b3 |
|
MD5 | 9082a443cd9dc7f5c0e0c191ba2a3a34 |
|
BLAKE2b-256 | c9dc15778a5da3b2819860e27d5ba6b867cd93ccf5e96e367fe577b9a7e08e8f |
Close
Hashes for zmesh-1.0.0-cp38-cp38-macosx_11_0_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e244519cd67686bf3b4d8d555eac0e79b32ccc4f08bc88cb7bdc441a44cd7ff2 |
|
MD5 | 0b86ffb11dfd25b28f4adee5ce44f377 |
|
BLAKE2b-256 | e667fc2a478d08f704e498d9ded12a00426e42ee56a9c6f207804ab6a4a90793 |
Close
Hashes for zmesh-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4afb98989b2beee25bf085b6ec6325344b107deb256a47ac79bd98fbd3d2d22 |
|
MD5 | b752c3df9b6a4ca7be22b0da5999c57f |
|
BLAKE2b-256 | f11f0adadb34171835fdc694e9c7df63224502a6fb70224760d5087d8cf11ae3 |
Close
Hashes for zmesh-1.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 315e6848290aa8b0c9983befe24ba4e9ea3f0708a2a48fe834b0dfe6eef6b629 |
|
MD5 | fefa350354da52f3de88b9857bcc5d95 |
|
BLAKE2b-256 | 4cd876a00511d2918993ec9c128efea6052dede0247dfc7df8c093d3af177787 |
Close
Hashes for zmesh-1.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a94ff781d4873e35a40042b96760ddf7814c58cda1608246faa540baf76b31a9 |
|
MD5 | a9c088374e9d2fb974fdb26fd0e8bdf8 |
|
BLAKE2b-256 | 99f5094f8d4ac954a421b0fd403847939b236904e116749325e14f42f47e7742 |
Close
Hashes for zmesh-1.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d85f93a4ae761383ae53181ff7753a57e49eda2cc5f46fc7ee2bff1147ca1fff |
|
MD5 | 0e2f6447ce18474031731391c3da23a9 |
|
BLAKE2b-256 | b652755e3b60fd4958934d4959bc21a68d3ca7a0dac822cc6ea725c69f329261 |
Close
Hashes for zmesh-1.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84c2221d5f3477d5984e7b10b2602d4881895e8c2317c50c875480bc7335837e |
|
MD5 | dfc34c5f9d2415e05e41ab3569a0d953 |
|
BLAKE2b-256 | 75323459adb64668c694d0bd3563e3350a11f195c3175c80555002124b112ffb |
Close
Hashes for zmesh-1.0.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02e0a028a858a5ee647a0ce10a9ae3660c7fb9cdbb80300ca83f54c8820f196d |
|
MD5 | 605f16f76fdbf388afbaa9d104084e70 |
|
BLAKE2b-256 | 43762be3a11739c351034f35b23b31e38749d55fe825bfdbbf4317e2ec5b68c3 |
Close
Hashes for zmesh-1.0.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56b64b54297ba348cad11ece67f0462d9541457d43227d6fed6f2329e4d9d112 |
|
MD5 | 7511cfb65d4fb093e3e7438ba326b232 |
|
BLAKE2b-256 | a971b8b71427430eccc6718bb4c76a8b05a2fd7a52925f910b0c4edb69a7249c |