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
An 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pygeodesic-0.1.1.tar.gz
.
File metadata
- Download URL: pygeodesic-0.1.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d13cd89b59eb95a2bbfaae1c6ad0c3ab665fde1923c4ec2986b018dcca2543c |
|
MD5 | e40ff2ff0b8bd2ae55f3236eacb6bc96 |
|
BLAKE2b-256 | 8e9cc9745fb717eacab2adccfdb2efc9b7e58ddc934b08d01a0241fb9bf97713 |
File details
Details for the file pygeodesic-0.1.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pygeodesic-0.1.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 371284f0ffdb80debfc0c56c092665bcd2051a9099efe1f19169c35366c0c5a0 |
|
MD5 | f8657870e656f5e2b38d1c9996400dde |
|
BLAKE2b-256 | 83ecd0fabed30fcae1e91040be5ca536c0c211d321ed7146a2ba9f2a0e18654c |