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:

source_indices = np.array([25])
target_indices = None
distances, best_source = geoalg.geodesicDistances(source_indices, target_indices)

To calculate the geodesic distances from two source points to 3 target points:

source_indices = np.array([25,100]) 
target_indices = np.array([0,10,50])
distances, best_source = geoalg.geodesicDistances(source_indices, target_indices)

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.9.tar.gz (36.3 kB view hashes)

Uploaded Source

Built Distributions

pygeodesic-0.1.9-cp312-cp312-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

pygeodesic-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pygeodesic-0.1.9-cp312-cp312-macosx_10_9_x86_64.whl (251.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

pygeodesic-0.1.9-cp312-cp312-macosx_10_9_universal2.whl (348.9 kB view hashes)

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

pygeodesic-0.1.9-cp311-cp311-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

pygeodesic-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pygeodesic-0.1.9-cp311-cp311-macosx_10_9_x86_64.whl (253.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pygeodesic-0.1.9-cp311-cp311-macosx_10_9_universal2.whl (351.1 kB view hashes)

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

pygeodesic-0.1.9-cp310-cp310-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pygeodesic-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (984.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pygeodesic-0.1.9-cp310-cp310-macosx_10_9_x86_64.whl (253.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pygeodesic-0.1.9-cp310-cp310-macosx_10_9_universal2.whl (350.7 kB view hashes)

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

pygeodesic-0.1.9-cp39-cp39-win_amd64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pygeodesic-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (984.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pygeodesic-0.1.9-cp39-cp39-macosx_10_9_x86_64.whl (253.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygeodesic-0.1.9-cp39-cp39-macosx_10_9_universal2.whl (351.0 kB view hashes)

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

pygeodesic-0.1.9-cp38-cp38-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pygeodesic-0.1.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (882.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pygeodesic-0.1.9-cp38-cp38-macosx_10_9_x86_64.whl (145.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygeodesic-0.1.9-cp38-cp38-macosx_10_9_universal2.whl (350.4 kB view hashes)

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

Supported by

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