Skip to main content

alpha shape generator using CGAL

Project description

DioDe uses CGAL to generate alpha shapes filtrations in a format that Dionysus understands. DioDe is not integrated into Dionysus because of licensing restrictions (Dionysus is under BSD, DioDe is under GPL because of its dependence on CGAL). It supports both ordinary and weighted alpha shapes.

Dependencies:

Get, Build, Install

The simplest way to install Diode as a Python package:

pip install --verbose diode

or from this repository directly:

pip install --verbose git+https://github.com/mrzv/diode.git

Alternatively, you can clone and build everything by hand. To get Diode, either clone its repository:

git clone https://github.com/mrzv/diode.git

or download it as a Zip archive.

To build the project:

mkdir build
cd build
cmake ..
make

To use the Python bindings, either launch Python from .../build/bindings/python or add this directory to your PYTHONPATH variable, by adding:

export PYTHONPATH=.../build/bindings/python:$PYTHONPATH

to your ~/.bashrc or ~/.zshrc.

Usage

NB: a remark below about using exact computation. This issue is especially important when working with degenerate point sets (e.g., repeated copies of a fundamental domain in a periodic point set).

See examples/generate_alpha_shape.cpp and examples/generate_weighted_alpha_shape.cpp for C++ examples.

In Python, use diode.fill_alpha_shapes(...) and diode.fill_weighted_alpha_shapes(...) to fill a list of simplices, together with their alpha values:

>>> import diode
>>> import numpy as np

>>> points = np.random.random((100,3))
>>> simplices = diode.fill_alpha_shapes(points)

>>> print(simplices)
 [([13L], 0.0),
  ([18L], 0.0),
  ([59L], 0.0),
  ([10L], 0.0),
  ([72L], 0.0),
  ...,
  ([91L, 4L, 16L, 49L], 546.991052812204),
  ([49L, 62L], 1933.2257381777533),
  ([62L, 34L, 49L], 1933.2257381777533),
  ([62L, 91L, 49L], 1933.2257381777533),
  ([62L, 91L, 34L, 49L], 1933.2257381777533)]

>>> weighted_points = np.random.random((100,4))
>>> simplices2 = diode.fill_weighted_alpha_shapes(weighted_points)
>>> print(simplices2)
[([24L], -0.987214836816236),
 ([35L], -0.968749877102265),
 ([50L], -0.9673151804059413),
 ([47L], -0.9640549893422644),
 ([71L], -0.9639978806827709),
 ([24L, 50L], -0.9540965704765515),
 ...
 ([54L, 10L], 29223.611044169364),
 ([10L, 54L, 43L], 29223.611044169364),
 ([13L, 10L, 54L], 29223.611044169364),
 ([13L, 10L, 54L, 43L], 29223.611044169364)]

The list can be passed to Dionysus to initialize a filtration:

>>> import dionysus
>>> f = dionysus.Filtration(simplices)
>>> print(f)
Filtration with 2287 simplices

DioDe also includes diode.fill_periodic_alpha_shapes(...), which generates the alpha shape for a point set on a periodic cube, by default [0,0,0] - [1,1,1]. (In the periodic case, it may happen that CGAL reports each simplex multiple times. However, passing the result to dionysus.Filtration will take care of the duplicates.):

>>> simplices_periodic = diode.fill_periodic_alpha_shapes(points)
>>> f_periodic = dionysus.Filtration(simplices_periodic)
>>> print(f_periodic)
Filtration with 2912 simplices

>>> for s in f_periodic: print(s)
<0> 0
<1> 0
<2> 0
<3> 0
...
<77,94,97> 0.0704355
<46,77,94,97> 0.0708062
<30,77,94,97> 0.0708474
<18,65,79> 0.0715833
<18,64,65,79> 0.0715833
<18,65,79,99> 0.0725366

When using CGAL version at least 4.11, DioDe includes diode.fill_weighted_periodic_alpha_shapes(...), which generates the alpha shape for a weighted point set on a periodic cube:

>>> weighted_points[:,3] /= 64
>>> simplices_weighted_periodic = diode.fill_weighted_periodic_alpha_shapes(weighted_points)

diode.circumcenter(...) can be used to compute the circumcenter of a tetrahedron in 3D:

>>> tet = np.random.random((4,3))
>>> center = diode.circumcenter(tet)
>>> print(center)
[-0.00752673  0.14213101  1.0060982 ]

Exactness

All functions take an argument exact, set to False by default. The argument determines a choice of the kernel in CGAL (Exact_predicates_inexact_constructions_kernel vs Exact_predicates_exact_constructions_kernel). exact = True guarantees correctness of the output; exact = False is faster, but can sometimes fail (not even produce a simplicial complex). It’s possible to run the two versions adaptively by running the default exact = False version first, and if the result is not a simplicial complex, then run exact = True. This should be the best of both worlds.

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

diode-1.1.1.tar.gz (31.3 kB view details)

Uploaded Source

Built Distributions

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

diode-1.1.1-cp314-cp314-manylinux_2_34_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

diode-1.1.1-cp314-cp314-macosx_15_0_arm64.whl (878.6 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

diode-1.1.1-cp313-cp313-manylinux_2_34_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

diode-1.1.1-cp313-cp313-macosx_15_0_arm64.whl (878.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

diode-1.1.1-cp312-cp312-manylinux_2_34_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

diode-1.1.1-cp312-cp312-macosx_15_0_arm64.whl (878.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

File details

Details for the file diode-1.1.1.tar.gz.

File metadata

  • Download URL: diode-1.1.1.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for diode-1.1.1.tar.gz
Algorithm Hash digest
SHA256 3a1b294b88852eba3e9c632908b980d6fede69ff23c8fc614f69ebbe02b10bf8
MD5 53b189273be170f7b6b65f76abba96e9
BLAKE2b-256 cbce7be968ceb0dbf9f66853a5ecb28e666bd22bf99f5bbd424206f77b809ab2

See more details on using hashes here.

File details

Details for the file diode-1.1.1-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for diode-1.1.1-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 090e3ca5c4dac101962c8c25e16d01dfe5c3982d54366a2e149550f6bbc2bcd5
MD5 cbdecf9ac925d24c6760a513e979844d
BLAKE2b-256 168a481c34ebd3c82bbf88cb2e9381756b51ad9c683fee753d63347327407245

See more details on using hashes here.

File details

Details for the file diode-1.1.1-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for diode-1.1.1-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 352234b5090461a7e812968136f84afe21972c771dd50a0acd1de883cc93036e
MD5 8721b4c7cc49a16fea9be2dcecef34b0
BLAKE2b-256 2fc40bf8ee629d8e5cf98550d646275e2e9fbeccb5886ac6965748a4677df0fe

See more details on using hashes here.

File details

Details for the file diode-1.1.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for diode-1.1.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 daf0d1514e87279d18e777fe36b9adf03fb1410fa39a44be70e28a4f27233e53
MD5 f6652520de632b6f4b3b8be8a625182c
BLAKE2b-256 da0dab1338ae14c19860590b4ff2e73e7ab38ac1123ded6196bea632fe367612

See more details on using hashes here.

File details

Details for the file diode-1.1.1-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for diode-1.1.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 4df247e7e5c7aff919b1d63b6dfb19ba1d6f5949fea42d2446d76d98871673cb
MD5 5667fd531525c2fbf9b85fdb0e9fd9be
BLAKE2b-256 03b1a4442a1ba7d25cf5a7fc378c4e0435cc4a3dea1c476f061f17704ba17234

See more details on using hashes here.

File details

Details for the file diode-1.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for diode-1.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 89d2ae0cb67a1ec0ca2f5fca9bcd8569952c56a2694f8df5fe35896e40a9e76a
MD5 9d42765e76e10a668c16932e5043657c
BLAKE2b-256 c68d4fcf8b243b454237c03b9513c20efcb4605e321fe1b3ff66893dfcb4407d

See more details on using hashes here.

File details

Details for the file diode-1.1.1-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for diode-1.1.1-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a88215e49145a4dc3e8fa5ae51b8513888fed5d92cd425b587c589ca0a172343
MD5 0523cdd51624302bcc4a52fa08b4ced4
BLAKE2b-256 5916f77c670df040b48e2c2d4815b91c568d9645bf70f87603df6c17fd932011

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