Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Mesh optimization/smoothing

Project description

optimesh

CircleCI codecov Codacy grade Code style: black smooth PyPi Version GitHub stars

Several mesh smoothing/optimization methods with one simple interface.

  • fast
  • preserves submeshes
  • only works for triangular meshes (for now)
  • supports all mesh formats that meshio can handle

Install with

pip install optimesh

Example call:

optimesh in.e out.vtk --method lloyd -n 50

Output (usually looks better on the command line than in the browser):

Before:

           █                          min angle:      29.811                 █▃    min quality: 0.485    energy: 1.43225e-02
          ▆█ ▇ ▃                      avg angle:      60.000                 ██    avg quality: 0.919
          ██ █▃█                      max angle:     118.316                 ██    max quality: 0.999
         ▁██▆█▉█▆▅                    std dev angle:  14.039                 ██
       ▁▁█████▉███ ▃                                                       ▂ ██
       ███████▉███▇█                                                       █▇██
       ███████▉█████▆ ▇                                                   ▆████
      ▅███████▉████████▃▃                                                ██████
     ▆████████▉██████████▅▂                                           ▂ ▆██████
  ▁▃▅█████████▉████████████▆▅▃▅▅▁▁                              ▁▁▃▆▃▂█████████

Final (50 steps):

           █                   min angle:      25.830             █    min quality: 0.693    energy: 1.35054e-02
          ▅▉▇                  avg angle:      60.000             █    avg quality: 0.962
          █▉█▅                 max angle:      97.417             █    max quality: 1.000
         ██▉██                 std dev angle:   9.493             █
        ▅██▉██                                                    █
        ███▉██                                                    █
       ████▉██▇▄                                                 ▇█
      ▂████▉████▇▁                                               ██
    ▂▃█████▉██████▁ ▂                                          ▁▂██
  ▁▂███████▉███████▇█▅▁▃▃▂▁                              ▁▂▁▂▃▇████

The left hand-side graph shows the distribution of angles (the grid line is at the optimal 60 degrees). The right hand-side graph shows the distribution of simplex quality, where quality is twice the ratio of circumcircle and incircle radius.

All command-line options are viewed with

optimesh -h

Laplacian smoothing

laplace

Ordinary Laplacian mesh smoothing. Fast, preserves the mesh density.

optimesh circle.vtk out.vtk --method laplace

ODT smoothing

odt

Optimal Delaunay Triangulation (ODT) treated as a minimization problem. Assumes a uniform mesh (for now), so it does not preserve the original mesh density.

optimesh circle.vtk out.vtk --method odt

CVT/pseudo-Lloyd smoothing

lloyd

Centroidal Voronoi tessellation smoothing, realized by Lloyd's algorithm adapted for triangular meshes. If the topological neighbors of any node are also the geometrically closest nodes, this is exactly Lloyd's algorithm. That is fulfilled in many practical cases, but the algorithm can break down if it is not.

Assumes a uniform mesh (for now), so it does not preserve the original mesh density.

optimesh circle.vtk out.vtk --method lloyd

Chen-Holst smoothing

Mesh optimization after Chen and Holst. Both methods honor the -u/--uniform-density command line option. If not given, the mesh density is preserved.

  • ODT-like smoothing

    ch-odt

    optimesh circle.vtk out.vtk --method chen-odt --uniform-density
    
  • CPT (Centroidal Patch Triangulation, CVT-like smoothing)

    ch-cpt

    optimesh circle.vtk out.vtk --method chen-cpt --uniform-density
    

Access from Python

All optimesh functions can also be accessed from Python directly, for example:

import optimesh

X, cells = optimesh.odt(X, cells, 1.0e-2, 100, verbosity=1)

Installation

optimesh is available from the Python Package Index, so simply do

pip install -U optimesh

to install or upgrade. Use sudo -H to install as root or the --user option of pip to install in $HOME.

Relevant publications

Testing

To run the optimesh unit tests, check out this repository and type

pytest

Distribution

To create a new release

  1. bump the __version__ number,

  2. publish to PyPi and tag on GitHub:

    $ make publish
    

License

optimesh is published under the MIT license.

Project details


Download files

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

Files for optimesh, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size optimesh-0.1.1-py2.py3-none-any.whl (12.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size optimesh-0.1.1.tar.gz (11.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page