doc/python/alphashapes.rst
author Aravindakshan Babu <akshan@stanford.edu>
Thu, 08 Jul 2010 23:50:39 -0700
branchdev
changeset 217 64a272a34cb2
parent 181 1ee6edc17cb6
child 246 88f7806633e0
permissions -rw-r--r--
Added extra functionality to Point class( an iterator ) and PersistenceDiagram( dimension property and __len__ func ). persistence-diagram.h: Added a new read-only dimension member and member function to access it. With a new constructor that that takes in an int type to initialize dimension. persistence-diagram.cpp: Added new bp::init constructor. Takes in an integer type to initialize the dimension. Exposed the dimension property. Exposed the size property via a __len__ method. __init__.py: Added an iterator for Point objects. This iterates over the coords and then the data( if present ).

.. _alphashapes:

Alpha shapes
============

There are two functions provided to compute alpha shapes. One in 2D and one in
3D. Both take a list of points (each a list of coordinates) as input, and fill a
list with the simplices of the `Delaunay triangulation`_. Each such simplex is
said to be *attached* (or *regular*) if its dual Voronoi cell does not contain a
critical point of the distance function to the point set. The smallest value of
the squared distance function on the dual Voronoi cell of the Delaunay simplex
is the alpha shape value assigned to it. This value is stored in the simplex's
`data` attribute; whether it is attached is stored in the `attached` attribute.

.. _`Delaunay triangulation`:   http://en.wikipedia.org/wiki/Delaunay_triangulation


.. function:: fill_alpha2D_complex(points, complex)
    
    Appends to the `complex` the simplices of the 2D Delaunay triangulation
    on the `points`.

.. function:: fill_alpha3D_complex(points, complex)
    
    Appends to the `complex` the simplices of the 3D Delaunay triangulation
    on the `points`.


Example
-------

The following example generates 10 points on a circle, and computes their
Delaunay triangulation with corresponding alpha shape values::

    from math import sin, cos, pi
    points = [[cos(2*pi*t/10), sin(2*pi*t/10)] for t in xrange(10)]
    complex = Filtration()
    fill_alpha2D_complex(points, complex)

One can extract any given alpha shape with the usual Python list notation::

    alphashape = [s for s in complex if s.data[0] <= .5]