Question

I looked into python-graph and the python bindings for the boost graph library but did not find anything relevant regarding the dual-ization of meshes (the vertices of the dual are the faces of the original graph and are connected by an edge in the dual if they share an edge in the original graph) . Before I set to re-invent this wheel, is there an implementation I might have overlooked?

Was it helpful?

Solution

Probably there is, but it is quite simple to implement one. To do this it is needed to find for edge in which triangles it is used. And with that information it is possible to construct connections between triangles.

Simple python implementation, triangle (or polygon) is a list of vertex indices and edge is ordered pair of vertex indices:

from collections import defaultdict
from itertools import combinations
triangles = [(1,2,3), (2,3,4), (1,3,5), (3,4,5), (5,6,7), (4,5,6)]
# For each edge set triangles containing that edge
edge2trias = defaultdict(list)  # edge (v1,v2) -> list of triangles
for t_ind, ps in enumerate(triangles):
    for edge in zip(ps, ps[1:]+ps[:1]):
        edge2trias[tuple(sorted(edge))].append(t_ind)
# For each edge, set pair(s) of neighbouring triangles
tria2neigh = defaultdict(list)  # triangle index -> list of neighbouring triangles
for edge, trias in edge2trias.iteritems():
    for t1, t2 in combinations(trias, 2):
        tria2neigh[t1].append(t2)
        tria2neigh[t2].append(t1)

OTHER TIPS

And to answer own question - graph-tool's line graph function calculates the dual of the graph.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top