Skip to main content

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/

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

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))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_simplification-0.1.2.tar.gz (22.8 kB view details)

Uploaded Source

Built Distributions

fast_simplification-0.1.2-cp311-cp311-win_amd64.whl (206.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

fast_simplification-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

fast_simplification-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl (252.0 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

fast_simplification-0.1.2-cp311-cp311-macosx_10_9_universal2.whl (474.3 kB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

fast_simplification-0.1.2-cp310-cp310-win_amd64.whl (206.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

fast_simplification-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

fast_simplification-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl (250.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

fast_simplification-0.1.2-cp310-cp310-macosx_10_9_universal2.whl (472.0 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

fast_simplification-0.1.2-cp39-cp39-win_amd64.whl (207.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

fast_simplification-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

fast_simplification-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl (251.1 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

fast_simplification-0.1.2-cp39-cp39-macosx_10_9_universal2.whl (473.6 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

fast_simplification-0.1.2-cp38-cp38-win_amd64.whl (207.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

fast_simplification-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

fast_simplification-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl (250.7 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

fast_simplification-0.1.2-cp38-cp38-macosx_10_9_universal2.whl (473.4 kB view details)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

fast_simplification-0.1.2-cp37-cp37m-win_amd64.whl (207.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

fast_simplification-0.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

fast_simplification-0.1.2-cp37-cp37m-macosx_10_9_x86_64.whl (250.5 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file fast_simplification-0.1.2.tar.gz.

File metadata

  • Download URL: fast_simplification-0.1.2.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for fast_simplification-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b5a0cf07ee770ac541d8aa49ddbee4cb30fdc1a3438d507632765628695342e4
MD5 7e69be6d15edd1e6c0b542f731e30008
BLAKE2b-256 19b31403cf5bbd435306b80875889210983a9908f6b299f29af9ac57056e7a08

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 47c2854450cfa462deb443ea3989c8651219549442be1b11e8d040c2d463e76f
MD5 83ff5a759889da9e41fe4f7e48594d45
BLAKE2b-256 5a1d67d256a6ce0af54d467b510f1a89e5809038a64d1249807013df26bc4792

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b632a37662cb310fadc7bf7813db17c3881024fd2b28c32c1026c2272270c261
MD5 03b3b2aa59646b38e199ac90adf4d7ba
BLAKE2b-256 5302cb3be137844413478e0c7a7bcaae857ef12b713b330b59f050190e4076f1

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 63879f0d391af29a7e5e93c0d55d89eec337faf4702cacc75783f5a9e180e712
MD5 6c0e687ee2d8b76f4b8629c4f1fccb86
BLAKE2b-256 399cd842995fbafa0375e20ddf95893f247e2ff8728d63b524b441bd35c36e8f

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a928d25e222291bf83c7b4b77337fde62901243f4bf6f29c7453fc0a99afe334
MD5 f35eb31b24c8aef0ec49cef24f0f94d2
BLAKE2b-256 110b216947dc1f5bc67f69676279e2e5ab6ff955f18a96e8ad0cdcc95b0fa4c5

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e6ed9e280703ab672479d4c9a2bc645bae0c2e3a690098d0cd39c36755046806
MD5 557dc2b55674af0a344fd060f731a704
BLAKE2b-256 bf10d97a827060a62eac47dae6e0c6d2bb7dca6e6b1923ce6f3e88c8678b8b69

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f82c2cbb093f49afc564908399cad38bc654cc7ccc84d4dde68b2f0ed9b1cb56
MD5 52007aec218ddac2511d522f76c5a54b
BLAKE2b-256 4235c806c3d392de18c1a6e6654912c46de08a2b128a35b04ac8124405c8fe1e

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3399f1ed1dedb4c944406740365acdf71e62b27d56cc61bef9786185f90ed3c6
MD5 85d653060d5bdc932d81a38d192c96f2
BLAKE2b-256 6fd17a49dd18ef45d798027f12a4a56ba1e520d2b1f38fa4213a49ca694ca577

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6294643789b2147fe69c581a8403a6fd39b0de65a36a0db1a2c7bc9790401bbe
MD5 74d03ab02223315c3fc99b23c9441746
BLAKE2b-256 55b667fd3d6b18eb0f7bf530889e083577e10f62dc7b4b6e1dbed9ba2b091490

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 467f2eabab28f6d22cbaa4949b470f8646cf7a53004db79330565b55a3213398
MD5 ca762d8a565b3d4b75f7a62847e6780a
BLAKE2b-256 00fd4310d2f99d9cfa3138186a2380e69ec615d34b59bc352a408d611a42e9c3

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 36313b6ec71e098fdadb94ed4ed33c0464c7c663b95fe7122754305375aec613
MD5 d01e559015cbbdde6c3e4abb321a2bbd
BLAKE2b-256 89bf1374a3c73c7a2f08927104259a865a239eb8014ed3cea13f07071a2f5f65

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2b27e2b8181ce0245ea81bc9945176062b984fb494355558bdedd4b93838993b
MD5 91c775c565d9565381260ac6b060d236
BLAKE2b-256 9af7f313d8786608250c68c43280630014b0e7e5f1d1450d1bdbd53f48a8042d

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c51f2aa8f84c5a8f48331dbb11aed42730a3fc35586e797b4185baf1576002b8
MD5 15f54d811feaaef07f1d209e31047999
BLAKE2b-256 9acaf2e7367bce333832aede108b27696380896e2d221a35b0203ac696c52e8f

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 53666d0025bbc3cb04b9adbb9a310662cec18328016eea29bbb04b325e25be92
MD5 3e4f2ae61747e0d8813dba7baa8e490f
BLAKE2b-256 8583ef42ed2d9cff4f3330bf11a7d224fe9b9e5a42810c466e3281cd04d190e1

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f94bfde8f38d15ffa5f8662412c5b7fba02097e83e5aa6a56e59918eb398141
MD5 d2bcbaf77a6b8d50823662cd98c45aef
BLAKE2b-256 b60370ac9a2a71fcac228edbe8f3bd21ec11462bb67b3015c3c6cdd63dcd1dac

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9bfc47031e91803a5833624f1ff1107cdee3a9f0e8818255937986041bb681b3
MD5 b9738049ee3eecc0872a4e6f166b0e71
BLAKE2b-256 1fd64c9fc64bab9906d06bb5049dd3a516935fe8f1666c92f0b30fe97266d174

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3277dfe242e4c311f54327736bff7733e0b195bbbcd51e850e7d85e5eda83146
MD5 be7a3876a5fffd0141c74e29ed5cecae
BLAKE2b-256 3b708422bed648305f65d7cf22a75a0bd7ffee8d7418b8ee1c04afccf042ff9f

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 8146d0454d8ef6b02d8c102be73c5326038219ad8c1589ae5e97a33a42a09107
MD5 5eabebc959d09e096a6f11d36dfbe0f0
BLAKE2b-256 6b668b99273ccd0b952f3b2a1ec4eb9fa0750bc5a797d22251e457bd7ad909e1

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ec3101dab8096c4fd16c79a566d852b1f379dec7ed5d04f218d0134eeeb8a07
MD5 7fcd85e60eaf960c4e410e281677a7e7
BLAKE2b-256 50be8014c26c35a9dd74c8311d1199c1e13ad41825fa49e225253f842a1b8c1a

See more details on using hashes here.

File details

Details for the file fast_simplification-0.1.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for fast_simplification-0.1.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 092eb84442f98885e126d8a48ca21e300f1332344fbebdbe36ff41df7c91394e
MD5 61077384dadd4852e5c3e075bf3854fe
BLAKE2b-256 b8bd052468fa00ca14b60949a5acf25528252006c125211ef84d0c07f631cc51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page