Skip to main content

Python library for calculating geodesic distance on triangular based surface meshes

Project description

pygeodesic

Python library to compute geodesic distance over a triangular based surface mesh.

A Cython wrapper of the C++ code by Kirsanov, which is an implementation of the exact geodesic algorithm for triangular mesh first described by Mitchell, Mount and Papadimitriou in 1987.

pygeodesic is similar to other libraries on PyPi (such as gdist and tvb-gdist), but:

  • provides a wrapper of the GeodesicAlgorithmExact class
  • exposes geodesic path (not just geodesic distance)
  • licensed under MIT license similar to the orginal Kirsanov C++ code, rather than GPL

A good alternative to pygeodesic is potpourri3d, which uses the heat method and vector heat method to compute geodesic distance over surfaces and point clouds. However, this library does not currently output the geodesic path on the surface.

Requirements

A C++ compiler is required if you are not installing one of the precompiled wheels. Although pygeodesic is a Cython wrapper, Cython is not required as the cythonized C++ file is also provided.

VTK is used for visualisation in the example notebooks.

Installation

Install from PyPi:

pip install pygeodesic

Installation from source (from within folder containing setup.py):

python setup.py install

Usage

Loading pygeodesic:

import pygeodesic.geodesic as geodesic

To read the mesh files provided with the original C++ code:

filename = r'data/flat_triangular_mesh.txt'
result = geodesic.read_mesh_from_file(filename)
if result:
    points, faces = result

To calculate the geodesic distance and path between two points (the source and the target) on the mesh:

# Initialise the PyGeodesicAlgorithmExact class instance
geoalg = geodesic.PyGeodesicAlgorithmExact(points,faces)

# Define the source and target point ids with respect to the points array
sourceIndex = 25
targetIndex = 97

# Compute the geodesic distance and the path
distance, path = geoalg.geodesicDistance(sourceIndex, targetIndex)

To calculate the geodesic distances from a single point (the source point) to all other points on the mesh:

sourceIndex = 25
distances, best_source = geoalg.geodesicDistances(np.array([sourceIndex,]))

To calculate the geodesic distances from two source points to all other points on the mesh:

distances, best_source = geoalg.geodesicDistances(np.array([25,100]))

For more detail, a Jupyter notebook is provided in the examples folder to show how to use pygeodesic to compute geodesic distances and paths.

Example using the Stanford Bunny

A Jupyter notebook is provided showing how to use pygeodesic to calculate the geodesic distance and path using the Stanford Bunny as an example.

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

pygeodesic-0.1.3.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygeodesic-0.1.3-cp37-cp37m-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.7mWindows x86-64

File details

Details for the file pygeodesic-0.1.3.tar.gz.

File metadata

  • Download URL: pygeodesic-0.1.3.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

File hashes

Hashes for pygeodesic-0.1.3.tar.gz
Algorithm Hash digest
SHA256 63e0376bceb5d799a2a019ae9c412722a9a41687c81f9f773c394e55de9e011e
MD5 b84e4501009886df2606b90bd79dbae1
BLAKE2b-256 bb463b209dcff2c10a621eeb99d901f4b30bdf3a3c3c564ee7b474ccb66a30ce

See more details on using hashes here.

File details

Details for the file pygeodesic-0.1.3-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pygeodesic-0.1.3-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

File hashes

Hashes for pygeodesic-0.1.3-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 e502db0b4c6413f20325bea7f94134b54155ac31baee38546b98f52cac3c3384
MD5 9b26cbf07b08259eee6591703908da3a
BLAKE2b-256 d8c709ed8e9209e9d99535d479d6402203b5c6cabc2c0754cfd16ae008775041

See more details on using hashes here.

Supported by

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