def poly_topomesh(polys, positions, faces_as_cells=False, **kwargs):
polys = np.array(polys)
positions = array_dict(positions)
poly_lengths = np.array(map(len,polys))
poly_edge_list = [np.transpose([np.arange(l),(np.arange(l)+1)%l]) for l in poly_lengths]
edges = array_unique(np.sort(np.concatenate([np.array(p)[l] for p,l in zip(polys,poly_edge_list)],axis=0)))
poly_edges = np.sort(np.concatenate([np.array(p)[l] for p,l in zip(polys,poly_edge_list)],axis=0))
start_time = time()
print "--> Generating poly topomesh"
poly_edge_matching = vq(poly_edges,edges)[0]
poly_topomesh = PropertyTopomesh(3)
for c in np.unique(polys):
poly_topomesh.add_wisp(0,c)
for e in edges:
eid = poly_topomesh.add_wisp(1)
for pid in e:
poly_topomesh.link(1,eid,pid)
total_poly_length = 0
for q,l in zip(polys,poly_lengths):
fid = poly_topomesh.add_wisp(2)
for eid in poly_edge_matching[total_poly_length:total_poly_length+l]:
poly_topomesh.link(2,fid,eid)
total_poly_length += l
if not faces_as_cells:
poly_topomesh.add_wisp(3,0)
for fid in poly_topomesh.wisps(2):
poly_topomesh.link(3,0,fid)
else:
for fid in poly_topomesh.wisps(2):
poly_topomesh.add_wisp(3,fid)
poly_topomesh.link(3,fid,fid)
poly_topomesh.update_wisp_property('barycenter',0,positions.values(np.unique(polys)),keys=np.unique(polys))
end_time = time()
print "<-- Generating poly topomesh [",end_time-start_time,"s]"
return poly_topomesh
property_topomesh_creation.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录