def test_trianglesToEdgeList(self, triangles, numVerts=0): '''Convert a list of triangle indices to an array of up-to-10 neighbouring vertices per vertex (following anticlockwise order).''' if numVerts is None: numVerts = np.max(triangles) + 1 if len(triangles) else 1 if numVerts < 1: numVerts = 1 # avoid empty arrays T = [dict() for t in xrange(numVerts)] P = [dict() for t in xrange(numVerts)] for t0, t1, t2 in triangles: T[t0][t1], T[t1][t2], T[t2][t0] = t2, t0, t1 P[t1][t0], P[t2][t1], P[t0][t2] = t2, t0, t1 S = np.zeros((numVerts, 10), dtype=np.int32) for vi, (Si, es, ps) in enumerate(zip(S, T, P)): Si[:] = vi if not es: continue v = min(es.keys()) while v in ps: v = ps.pop(v) for li in xrange(10): Si[li] = v if v not in es: break v = es.pop(v, vi) import ISCV ret = ISCV.trianglesToEdgeList(triangles, numVerts) assert np.all(S == ret), repr(S) + repr(ret) return ret
def pointsToEdges(points, mapping_list=None): # mapping_list is such that i is mapped to mapping_list[i] from scipy.spatial import Delaunay tris = Delaunay(points).simplices edges = ISCV.trianglesToEdgeList( np.max(tris) + 1 if len(tris) else 1, tris) # (numVerts,10) edgeList = set() for vi, el in enumerate(edges): which = np.where(el > vi)[0] edgeList.update(zip(which, el[which])) edgeList = np.int32(list(edgeList)) if mapping_list is not None: edgeList = np.int32(mapping_list)[edgeList] return edgeList
def trianglesToEdgeList(self, triangles, numVerts=0): import ISCV return ISCV.trianglesToEdgeList(triangles, numVerts)