bindings/python/dionysus/__init__.py
author Dmitriy Morozov <dmitriy@mrzv.org>
Fri May 11 17:06:55 2012 -0700 (2 weeks ago)
branchdev
changeset 251 870865d25958
parent 2412ca64ce7d57c
permissions -rw-r--r--
Merge
     1 from    _dionysus   import *
     2 from    distances   import l2, ExplicitDistances, points_file
     3 from    zigzag      import *
     4 
     5 
     6 def init_with_none(self, iter, data = None):        # convenience: data defaults to None
     7     self._cpp_init_(iter, data)
     8 
     9 def repr_with_data(self):
    10     str = self._cpp_repr_()
    11     if type(self.data) == float:
    12         str += ' %f' % self.data
    13     return str
    14 
    15 Simplex._cpp_init_ =    Simplex.__init__
    16 Simplex.__init__   =    init_with_none
    17 Simplex._cpp_repr_ =    Simplex.__repr__
    18 Simplex.__repr__   =    repr_with_data
    19 
    20 def Simplex_getinitargs(self):
    21     return ([v for v in self.vertices], self.data)
    22 
    23 Simplex.__getinitargs__ = Simplex_getinitargs
    24 
    25 def data_cmp(s1, s2):
    26     return cmp(s1.data, s2.data)
    27 
    28 def data_dim_cmp(s1,s2):
    29     return cmp(s1.dimension(), s2.dimension()) or data_cmp(s1,s2)
    30 
    31 def dim_data_cmp(s1,s2):
    32     return data_cmp(s1,s2) or cmp(s1.dimension(), s2.dimension())
    33 
    34 def vertex_dim_cmp(s1, s2):
    35     return cmp(s1.dimension(), s2.dimension()) or vertex_cmp(s1, s2)
    36 
    37 def fill_alpha_complex(points, simplices):
    38     if   len(points[0]) == 2:           # 2D
    39         fill_alpha2D_complex(points, simplices)
    40     elif len(points[0]) == 3:           # 3D
    41         fill_alpha3D_complex(points, simplices)
    42 
    43 def closure(simplices, k):
    44     """Compute the k-skeleton of the closure of the list of simplices."""
    45 
    46     res = set()
    47 
    48     from    itertools   import combinations
    49     for s in simplices:
    50         for kk in xrange(1, k+2):
    51             for face in combinations(s.vertices, min(s.dimension() + 1, kk)):
    52                 res.add(Simplex(face, s.data))
    53 
    54     return list(res)