Wrapper around the Fast-Quadric-Mesh-Simplification library.
Project description
This is a python wrapping of the Fast-Quadric-Mesh-Simplification Library. Having arrived at the same problem as the original author, but needing a Python library, this project seeks to extend the work of the original library while adding integration to Python and the PyVista project.
For the full documentation visit: https://pyvista.github.io/fast-simplification/
Basic Usage
The basic interface is quite straightforward and can work directly with arrays of points and triangles:
points = [[ 0.5, -0.5, 0.0],
[ 0.0, -0.5, 0.0],
[-0.5, -0.5, 0.0],
[ 0.5, 0.0, 0.0],
[ 0.0, 0.0, 0.0],
[-0.5, 0.0, 0.0],
[ 0.5, 0.5, 0.0],
[ 0.0, 0.5, 0.0],
[-0.5, 0.5, 0.0]]
faces = [[0, 1, 3],
[4, 3, 1],
[1, 2, 4],
[5, 4, 2],
[3, 4, 6],
[7, 6, 4],
[4, 5, 7],
[8, 7, 5]]
points_out, faces_out = fast_simplification.simplify(points, faces, 0.5)
Advanced Usage
This library supports direct integration with VTK through PyVista to provide a simplistic interface to the library. As this library provides a 4-5x improvement to the VTK decimation algorithms.
>>> from pyvista import examples
>>> mesh = examples.download_nefertiti()
>>> out = fast_simplification.simplify_mesh(mesh, target_reduction=0.9)
Compare with built-in VTK/PyVista methods:
>>> fas_sim = fast_simplification.simplify_mesh(mesh, target_reduction=0.9)
>>> dec_std = mesh.decimate(0.9) # vtkQuadricDecimation
>>> dec_pro = mesh.decimate_pro(0.9) # vtkDecimatePro
>>> pv.set_plot_theme('document')
>>> pl = pv.Plotter(shape=(2, 2), window_size=(1000, 1000))
>>> pl.add_text('Original', 'upper_right', color='w')
>>> pl.add_mesh(mesh, show_edges=True)
>>> pl.camera_position = cpos
>>> pl.subplot(0, 1)
>>> pl.add_text(
... 'Fast-Quadric-Mesh-Simplification\n~2.2 seconds', 'upper_right', color='w'
... )
>>> pl.add_mesh(fas_sim, show_edges=True)
>>> pl.camera_position = cpos
>>> pl.subplot(1, 0)
>>> pl.add_mesh(dec_std, show_edges=True)
>>> pl.add_text(
... 'vtkQuadricDecimation\n~9.5 seconds', 'upper_right', color='w'
... )
>>> pl.camera_position = cpos
>>> pl.subplot(1, 1)
>>> pl.add_mesh(dec_pro, show_edges=True)
>>> pl.add_text(
... 'vtkDecimatePro\n11.4~ seconds', 'upper_right', color='w'
... )
>>> pl.camera_position = cpos
>>> pl.show()
Comparison to other libraries
The pyfqmr library wraps the same header file as this library and has similar capabilities. In this library, the decision was made to write the Cython layer on top of an additional C++ layer rather than directly interfacing with wrapper from Cython. This results in a mild performance improvement.
Reusing the example above:
Set up a timing function.
>>> import pyfqmr
>>> vertices = mesh.points
>>> faces = mesh.faces.reshape(-1, 4)[:, 1:]
>>> def time_pyfqmr():
... mesh_simplifier = pyfqmr.Simplify()
... mesh_simplifier.setMesh(vertices, faces)
... mesh_simplifier.simplify_mesh(
... target_count=out.n_faces, aggressiveness=7, verbose=0
... )
... vertices_out, faces_out, normals_out = mesh_simplifier.getMesh()
... return vertices_out, faces_out, normals_out
Now, time it and compare with the non-VTK API of this library:
>>> timeit time_pyfqmr()
2.75 s ± 5.35 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
>>> timeit vout, fout = fast_simplification.simplify(vertices, faces, 0.9)
2.05 s ± 3.18 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Additionally, the fast-simplification library has direct plugins to the pyvista library, making it easy to read and write meshes:
>>> import pyvista
>>> import fast_simplification
>>> mesh = pyvista.read('my_mesh.stl')
>>> simple = fast_simplification.simplify_mesh(mesh)
>>> simple.save('my_simple_mesh.stl')
Since both libraries are based on the same core C++ code, feel free to use whichever gives you the best performance and interoperability.
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
Built Distributions
Hashes for fast_simplification-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdd872261024e7d7289da199bdd78b4bee852d8295d19aacd41abc522c893761 |
|
MD5 | 4bea74e2d548bd906968e9e705aad728 |
|
BLAKE2b-256 | a74f9d4d6b43757798b162126db699ee62e5d45e3ea2a89f55a46e6e9c387ef7 |
Hashes for fast_simplification-0.1.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 128ad759146d5feb2641a4a74065f6190c4ec6e9fe57d1044584f73b15f17881 |
|
MD5 | ec1241a88a71c0c3d7201920b7c543f8 |
|
BLAKE2b-256 | f682e2b5740c506d02c9601015f5c0ca706e86e5ff89056a6244e737b4c892e2 |
Hashes for fast_simplification-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3b5a42cfc449eac33717a66e21ccefe2b011e3d6cb1b2fbccd728d9f1f2df6b |
|
MD5 | 6314ed87af5e4c6b2e5749c08867a146 |
|
BLAKE2b-256 | 261439f284128cd63c12ea58f03a62ede8b793a1adfda08603bfdc9912c00c47 |
Hashes for fast_simplification-0.1.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b15cc44561f315b33689fca0e90f2f5fe1aa6c65139c19769ee6d1ee3ebfff0 |
|
MD5 | ee1a390615d7404e32a44e05e6f8337b |
|
BLAKE2b-256 | 5e55e1ba9e49cbf33cf75aa7f04edc1315797d49c3e09580678eae65344f0a5f |
Hashes for fast_simplification-0.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d12698d1375871be65ec1f1636bd286d053ed0d1506cd9ecae50bf9566407afa |
|
MD5 | 48ede869fd7cb258eac9402eb4355f43 |
|
BLAKE2b-256 | 46bb26e79aa71f5dc91df1d22c26a223ee86baa92820ae8d5b1f71c984c328d9 |
Hashes for fast_simplification-0.1.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 867c1c36a454c7bcda2f289f8861e7ded98f0bc2b661583500868c59d271d1e7 |
|
MD5 | 7b57844589843587f1cbc9fbe7b942ea |
|
BLAKE2b-256 | 4e5a8a2b8571c4230350ae71dc461deeb64fff1374a2903ff168547efe2f66b4 |
Hashes for fast_simplification-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd4427d8b647d1b2cc1da7a4ed74e2fa6d5afe505d41fc7481b4dadb394bf33f |
|
MD5 | 05b8c47048f43e08d2f24f6ab4413037 |
|
BLAKE2b-256 | a307147cc239611e05ffd0c5bfc2fe7596cb170d443c7d3de297b921a60f665f |
Hashes for fast_simplification-0.1.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccadb9f40742f48afd0ad2086888f4b746f86bd444460f7c956dcd97541fd487 |
|
MD5 | cbaef064c3ee73bbdf3587f55f2e7ab4 |
|
BLAKE2b-256 | 92ce332f4b821887531baec729bcee6f4ee9578a0fdd16ce03d3cffc137fe189 |
Hashes for fast_simplification-0.1.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9c3c18f67b36acbb4676bc472029603762529336899ce88d900e9742a5b59a9 |
|
MD5 | 2d48a41ffe037994683d6166834a18cc |
|
BLAKE2b-256 | 9015baed28a99433fe2a8b2e5fd6571b132f09c0a871f88ddc1c8b2d98172a7f |
Hashes for fast_simplification-0.1.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8f4040a1a37782e7447c9eabc0f3f28ed7e977b196078f36af36be06e9974b7 |
|
MD5 | c7d5e87dcf108a94e6e71e584e60ce38 |
|
BLAKE2b-256 | c7a7ceb5e01730e0bbbbf9b5e71baf171b58af0df5420eeb6897445ea4cd5949 |
Hashes for fast_simplification-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7567d29223b8921f9c45a84cbe6e74262f23985951f2d0d4052dc92f93d7c905 |
|
MD5 | 45acfbf86634953c681990bd6be9d7a7 |
|
BLAKE2b-256 | 909c4c2a44e50a40f1c1bb9ff59b580efe871938d3a8d6f9f53c665526e455c5 |
Hashes for fast_simplification-0.1.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca38f0dda95e04b2830aa6ad78e1d2af87be9f91002d8dcc000573d46e14b2d2 |
|
MD5 | 593de83d37070af585eef5235c7a53a1 |
|
BLAKE2b-256 | ad1883054d9ec70f8112214bc94dcd9c6fd9211b693ad43589c62df8a2c1f8da |
Hashes for fast_simplification-0.1.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ec6216771fff1b40b77bcf57c9f6415e2e4ef04bbc44144f527f371877353fa |
|
MD5 | a11fa6d718f7a684a86709c4b178da46 |
|
BLAKE2b-256 | e43f57e2dbaaeb0666be516030826002b2bffa99faeeaf66ee10839f2d011c2e |
Hashes for fast_simplification-0.1.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cded12def531595d76ba967916cd4126b35c5c6953a637b28d795b0e3ffc99f |
|
MD5 | b22a723d7a311dff8c3fdf984062612f |
|
BLAKE2b-256 | 1ccac0aacfca53319dd1d0dc50a36e12d98e80b8232430d380f2456500a7bf6b |
Hashes for fast_simplification-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bbf66ba2c55a6c4cf39e64bd2d46bf9ca9bdd9f4e7413d933f7a40b9be3e3ac |
|
MD5 | 00787f39e2bd142fd7c9565d6f910234 |
|
BLAKE2b-256 | 254d5784f81142cd579fc95156de028df22c14e992f0acef6e348ed12a824889 |
Hashes for fast_simplification-0.1.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7fd918c61fc76634c07c26488f731a1c5b672973a62ec23b7f3398bfe754655 |
|
MD5 | 6c48704ed0af5fd037e6c7c26412fa60 |
|
BLAKE2b-256 | 5e479ae7d8907d77085782122a95f7f17014db98f06dfd545f871319aa129ca3 |
Hashes for fast_simplification-0.1.1-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 305336b713403a2cb2b7afb880a15d3ae1ed5486f013d134192de151cbee93d6 |
|
MD5 | 0b1d9788484c40970d93fe6620dd9816 |
|
BLAKE2b-256 | ed5c98d50f4227042934e657608e30712786598dfbd0637302bcf6a369769e41 |
Hashes for fast_simplification-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa5f6510f3204bb1634384021e847538612e84b0ad5d3aca3dc022b6000a660f |
|
MD5 | 5478c8aef5f836cf9d4b7fb42a8341a0 |
|
BLAKE2b-256 | 919a3ca12dabdabc3af6b30d6d5eff6ab318adbaef6084c315fcda586046589e |
Hashes for fast_simplification-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3815c29b9adb79367268ceb4702f60556ec85ab5da95cd0e70def28b184f1188 |
|
MD5 | 1b7e0cd469fac307dfb6ad2833668ef9 |
|
BLAKE2b-256 | 107af3db42e608a1af14685322c34daf6db1465ae9b6b6927071eb4960edbc7a |
Hashes for fast_simplification-0.1.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23e7b9ee65cf522ba3be1149a1718711efc8d7a0da1e65cf53b679b5451f0c56 |
|
MD5 | 919825c295fae35ece91df885b0297b2 |
|
BLAKE2b-256 | d2a7f295269f014b4e1ff89a317bc636879547d30c6df839ab1d36aa4ced11b0 |