Skip to main content

Python Fast-Quadric-Mesh-Simplification Wrapper

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/

https://github.com/pyvista/fast-simplification/raw/main/doc/images/simplify_demo.png

Installation

Fast Simplification can be installed from PyPI using pip on Python >= 3.7:

pip install fast-simplification

See the Contributing for more details regarding development or if the installation through pip doesn’t work out.

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.

Replay decimation functionality

This library also provides an interface to keep track of the successive collapses that occur during the decimation process and to replay the decimation process. This can be useful for different applications, such as:

  • applying the same decimation to a collection of meshes that share the same topology

  • computing a correspondence map between the vertices of the original mesh and the vertices of the decimated mesh, to transfer field data from one to the other for example

  • replaying the decimation process with a smaller target reduction than the original one, faster than decimating the original mesh with the smaller target reduction

To use this functionality, you need to set the return_collapses parameter to True when calling simplify. This will return the successive collapses of the decimation process in addition to points and faces.

>>> import fast_simplification
>>> import pyvista
>>> mesh = pyvista.Sphere()
>>> points, faces = mesh.points, mesh.faces.reshape(-1, 4)[:, 1:]
>>> points_out, faces_out, collapses = fast_simplification.simplify(points, faces, 0.9, return_collapses=True)

Now you can call replay_simplification to replay the decimation process and obtain the mapping between the vertices of the original mesh and the vertices of the decimated mesh.

>>> points_out, faces_out, indice_mapping = fast_simplification.replay_simplification(points, faces, collapses)
>>> i = 3
>>> print(f'Vertex {i} of the original mesh is mapped to {indice_mapping[i]} of the decimated mesh')

You can also use the replay_simplification function to replay the decimation process with a smaller target reduction than the original one. This is faster than decimating the original mesh with the smaller target reduction. To do so, you need to pass a subset of the collapses to the replay_simplification function. For example, to replay the decimation process with a target reduction of 50% the initial rate, you can run:

>>> import numpy as np
>>> collapses_half = collapses[:int(0.5 * len(collapses))]
>>> points_out, faces_out, indice_mapping = fast_simplification.replay_simplification(points, faces, collapses_half)

If you have a collection of meshes that share the same topology, you can apply the same decimation to all of them by calling replay_simplification with the same collapses for each mesh. This ensure that the decimated meshes will share the same topology.

>>> import numpy as np
>>> # Assume that you have a collection of meshes stored in a list meshes
>>> _, _, collapses = fast_simplification.simplify(meshes[0].points, meshes[0].faces,
...                                                0.9, return_collapses=True)
>>> decimated_meshes = []
>>> for mesh in meshes:
...     points_out, faces_out, _ = fast_simplification.replay_simplification(mesh.points, mesh.faces, collapses)
...     decimated_meshes.append(pyvista.PolyData(points_out, faces_out))

Contributing

Contribute to this repository by forking this repository and installing in development mode with:

git clone https://github.com/<USERNAME>/fast-simplification
pip install -e .
pip install -r requirements_test.txt

You can then add your feature or commit your bug fix and then run your unit testing with:

pytest

Unit testing will automatically enforce minimum code coverage standards.

Next, to ensure your code meets minimum code styling standards, run:

pip install pre-commit
pre-commit run --all-files

Finally, create a pull request from your fork and I’ll be sure to review it.

Metadata

Release files for fast-simplification 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fast-simplification 0.1.8
File Size Uploaded Provenance
fast_simplification-0.1.8.tar.gz 26.2 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for fast-simplification 0.1.8
File
fast_simplification-0.1.8-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
fast_simplification-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
fast_simplification-0.1.8-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
fast_simplification-0.1.8-cp312-cp312-macosx_10_9_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.9+ x86-64 Details
fast_simplification-0.1.8-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
fast_simplification-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
fast_simplification-0.1.8-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
fast_simplification-0.1.8-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
fast_simplification-0.1.8-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
fast_simplification-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
fast_simplification-0.1.8-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
fast_simplification-0.1.8-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
fast_simplification-0.1.8-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
fast_simplification-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
fast_simplification-0.1.8-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details
fast_simplification-0.1.8-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details

Total release size: 9.8 MB

Release files / fast_simplification-0.1.8.tar.gz

Download URL fast_simplification-0.1.8.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0c8ea4d363ff7778e025b3f4c2db6184c472fbcb2c4eac3638e39c06815c99ae
BLAKE2b-256 checksum
How to use checksums
bbf0d643c3202d28b513bc71d348ffd74ce7a618b9cbcd5632775ea444371341
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp312-cp312-win_amd64.whl

Download URL fast_simplification-0.1.8-cp312-cp312-win_amd64.whl
Size 211.8 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d181517ff58730c40729c13daafd8fbe03e3ca76b4014a6eb5644ecb95c5e081
BLAKE2b-256 checksum
How to use checksums
deaef87a279270f3df181b88decf4fbbe37207ca54ad1f722a5b005638270263
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fast_simplification-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
941b363d34eb44984c7eae1e27b640cf470a772761e8665ef7f44e69973b54b2
BLAKE2b-256 checksum
How to use checksums
b337ddf597722471f8b0112480eb63a6c896d8e1c469efdfe6ce6aa47e2396ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp312-cp312-macosx_11_0_arm64.whl

Download URL fast_simplification-0.1.8-cp312-cp312-macosx_11_0_arm64.whl
Size 241.0 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
896fdde7436acff92a9ba21ec281224ac54cf443298161a4e88b78e75247d798
BLAKE2b-256 checksum
How to use checksums
1394d610b57f8fda711a804c42116d85905f04749dc202b9e0b7ec1ea353fed0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp312-cp312-macosx_10_9_x86_64.whl

Download URL fast_simplification-0.1.8-cp312-cp312-macosx_10_9_x86_64.whl
Size 263.4 kB
Tags CPython 3.12 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
6ca6e511cf1d762f9751a0187147a8c8e1c4d78579f362ce8c65443f62f4adda
BLAKE2b-256 checksum
How to use checksums
a47d31aac6d22925f540c963bb4391c143067a577efa7d4137e7e27c0a2f5f41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp311-cp311-win_amd64.whl

Download URL fast_simplification-0.1.8-cp311-cp311-win_amd64.whl
Size 212.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
f779fc2a38bc68aba06c79d23cd30ad590cd0d4c4e85e4eec25bdfcd17dbe5ff
BLAKE2b-256 checksum
How to use checksums
a561535ce434ed504bd036ddafa43a744e2889b17b3fd4bdd5fef32149c6bebb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fast_simplification-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8da103a646852f8e481d2d67fc790b9bb6af0f08353a3ae904bea9e521371c53
BLAKE2b-256 checksum
How to use checksums
cc51a5081bd4a3d67b21c776116b5f0474402c6333387ed745a03c815593ef6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp311-cp311-macosx_11_0_arm64.whl

Download URL fast_simplification-0.1.8-cp311-cp311-macosx_11_0_arm64.whl
Size 241.4 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
be7841eb091e36672d252e970a7f26f91693c4b47e5cd7a502dc6f0797e231be
BLAKE2b-256 checksum
How to use checksums
66562b11440ac744c14cae997875aaafacd4009e3553cec0e3f6d8e593bb909c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp311-cp311-macosx_10_9_x86_64.whl

Download URL fast_simplification-0.1.8-cp311-cp311-macosx_10_9_x86_64.whl
Size 263.3 kB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
38d67b1c9f10fe8d3bc4f2c1ff49fe6e40ec32b6dcd9cf59dce82cafa8935e29
BLAKE2b-256 checksum
How to use checksums
a0541ad92fa6db177a8a875006a0a6d275078e90d42d76ccd2862c83e89e38d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp310-cp310-win_amd64.whl

Download URL fast_simplification-0.1.8-cp310-cp310-win_amd64.whl
Size 212.2 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
546e6b0b04d4a8e4a3f3aeb27acb7d1bfcfc208be1887631e1270689cbb4a667
BLAKE2b-256 checksum
How to use checksums
d1588151a88d1de8f18e143b83fb0eb8ecbf163f8a173464c453b9beb59ffeea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fast_simplification-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9b791e6311c7a2e33a299050e51805e444beb9a2ec171afd66279f74839d4cdd
BLAKE2b-256 checksum
How to use checksums
c7718426626584b120caa6f82a404ec9e6d7fc7191fc5085609084fedcb79363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp310-cp310-macosx_11_0_arm64.whl

Download URL fast_simplification-0.1.8-cp310-cp310-macosx_11_0_arm64.whl
Size 241.1 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
88991fe14cc22b5c05022e8121e1284645d7026af7213874f42bcda6119ce56a
BLAKE2b-256 checksum
How to use checksums
5d15df0ebbb0e950020ef7111b72ed6a1d2a752f460979eefc81fce26569d9f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp310-cp310-macosx_10_9_x86_64.whl

Download URL fast_simplification-0.1.8-cp310-cp310-macosx_10_9_x86_64.whl
Size 262.8 kB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
44fbf653f92dae71d150da945cfdec3d9fcbd2e4fe4a94832351d107fc80c21b
BLAKE2b-256 checksum
How to use checksums
7b3d130b11f437149ea05cb30808fb4c69a456e28d9679a4b8e3d29a6958e1ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp39-cp39-win_amd64.whl

Download URL fast_simplification-0.1.8-cp39-cp39-win_amd64.whl
Size 213.3 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
a31dba6d674c0c84c10c7d99d663b4527723b525ba6528171b33cebecca4447c
BLAKE2b-256 checksum
How to use checksums
8255cce953ebff25a45740c0c58e27c3efd275de827cfc0bba59155ac4091606
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fast_simplification-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
328d35a15fff5ec5ce702777c3c19339500d439cf2808b78b7a22f3e31dd48e5
BLAKE2b-256 checksum
How to use checksums
be8c0be0bb3593f8af0a2be1a7cd0496344b23639e013c857a3e3e6b74269937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp39-cp39-macosx_11_0_arm64.whl

Download URL fast_simplification-0.1.8-cp39-cp39-macosx_11_0_arm64.whl
Size 242.3 kB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
36e69a625811e2fe2bcac7492cded2600e5765556e56afda8abc3b9ab6f846bb
BLAKE2b-256 checksum
How to use checksums
bee12eefcddb2ded6babeb424db5eaeb63553a64bb6d29a53a27e2e5c61feab4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / fast_simplification-0.1.8-cp39-cp39-macosx_10_9_x86_64.whl

Download URL fast_simplification-0.1.8-cp39-cp39-macosx_10_9_x86_64.whl
Size 264.0 kB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
91f28e5c000ae51f70478574977a484f745346e927c0c030d0dde30459c772d3
BLAKE2b-256 checksum
How to use checksums
6cdcbaa832dedb750b45a7398ab275b179ab84a1d37e7b0a0f51c716066a415b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.5

Security for fast-simplification 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page