examples/alphashapes/alphashapes.py
author Dmitriy Morozov <dmitriy@mrzv.org>
Mon Jul 25 23:21:29 2011 -0700 (6 months ago)
branchdev
changeset 244 66235db8d8b7
parent 131d9e050258358
permissions -rw-r--r--
Added cohomology/candidates counter to i/t/cohomology-persistence.hpp
     1 # Computes the persistence diagram of the alpha shapes in both 2D and 3D 
     2 # (decided dynamically based on the input file)
     3 
     4 from    dionysus        import Filtration, StaticPersistence, data_dim_cmp, vertex_cmp, \
     5                                fill_alpha3D_complex, fill_alpha2D_complex, points_file
     6 from    sys             import argv, exit
     7 from    math            import sqrt
     8 
     9 
    10 if len(argv) < 2:
    11     print "Usage: %s POINTS" % argv[0]
    12     exit()
    13 
    14 points = [p for p in points_file(argv[1])]
    15 f = Filtration()
    16 if   len(points[0]) == 2:           # 2D
    17     fill_alpha2D_complex(points, f)
    18 elif len(points[1]) == 3:           # 3D
    19     fill_alpha3D_complex(points, f)
    20 
    21 print "Total number of simplices:", len(f)
    22 
    23 f.sort(data_dim_cmp)
    24 print "Filtration initialized"
    25 
    26 p = StaticPersistence(f)
    27 print "StaticPersistence initialized" 
    28 
    29 p.pair_simplices()
    30 print "Simplices paired"
    31 
    32 print "Outputting persistence diagram"
    33 smap = p.make_simplex_map(f)
    34 for i in p:
    35     if i.sign():
    36         b = smap[i]
    37         if i.unpaired():
    38             print b.dimension(), sqrt(b.data[0]), "inf"
    39             continue
    40 
    41         d = smap[i.pair()]
    42         print b.dimension(), sqrt(b.data[0]), sqrt(d.data[0])