1 from _dionysus import *
2 from distances import l2, ExplicitDistances, points_file
6 def init_with_none(self, iter, data = None): # convenience: data defaults to None
7 self._cpp_init_(iter, data)
9 def repr_with_data(self):
10 str = self._cpp_repr_()
11 if type(self.data) == float:
12 str += ' %f' % self.data
15 Simplex._cpp_init_ = Simplex.__init__
16 Simplex.__init__ = init_with_none
17 Simplex._cpp_repr_ = Simplex.__repr__
18 Simplex.__repr__ = repr_with_data
20 def Simplex_getinitargs(self):
21 return ([v for v in self.vertices], self.data)
23 Simplex.__getinitargs__ = Simplex_getinitargs
26 return cmp(s1.data, s2.data)
28 def data_dim_cmp(s1,s2):
29 return cmp(s1.dimension(), s2.dimension()) or data_cmp(s1,s2)
31 def dim_data_cmp(s1,s2):
32 return data_cmp(s1,s2) or cmp(s1.dimension(), s2.dimension())
34 def vertex_dim_cmp(s1, s2):
35 return cmp(s1.dimension(), s2.dimension()) or vertex_cmp(s1, s2)
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)
43 def closure(simplices, k):
44 """Compute the k-skeleton of the closure of the list of simplices."""
48 from itertools import combinations
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))