author Dmitriy Morozov <dmitriy@mrzv.org>
Mon, 06 Mar 2023 12:54:27 -0800
changeset 302 47512d24f907
parent 181 1ee6edc17cb6
permissions -rw-r--r--
Fix doc/conf.py

# Computes the persistence diagram of the alpha shapes in both 2D and 3D 
# (decided dynamically based on the input file)

from    dionysus        import Filtration, StaticPersistence, data_dim_cmp, vertex_cmp, \
                               fill_alpha3D_complex, fill_alpha2D_complex, points_file
from    sys             import argv, exit
from    math            import sqrt

if len(argv) < 2:
    print "Usage: %s POINTS" % argv[0]

points = [p for p in points_file(argv[1])]
f = Filtration()
if   len(points[0]) == 2:           # 2D
    fill_alpha2D_complex(points, f)
elif len(points[1]) == 3:           # 3D
    fill_alpha3D_complex(points, f)

print "Total number of simplices:", len(f)

print "Filtration initialized"

p = StaticPersistence(f)
print "StaticPersistence initialized" 

print "Simplices paired"

print "Outputting persistence diagram"
smap = p.make_simplex_map(f)
for i in p:
    if i.sign():
        b = smap[i]
        if i.unpaired():
            print b.dimension(), sqrt(b.data[0]), "inf"

        d = smap[i.pair()]
        print b.dimension(), sqrt(b.data[0]), sqrt(d.data[0])