要获取相邻信息,请假设我们有一种方法可以 在给定的边上返回三角形的邻居neighbor_on_egde( next_tria, edge )。
该方法可以使用在每个 三角形中使用每个顶点的信息来实现。那是将顶点索引映射到 三角形索引列表的字典结构。通过遍历 三角形列表并为右 字典元素中的三角形的每个三角形顶点索引设置,可以轻松地创建它。
通过存储要检查方向的 三角形以及已检查哪些三角形来完成遍历。当有三角形要检查时,对其进行 检查,并添加要检查的邻居(如果未选中)。 伪代码如下所示:
to_process = set of pairs triangle and orientation edge
initial state is one good oriented triangle with any edge on it
processed = set of processed triangles; initial empty
while to_process is not empty:
next_tria, orientation_edge = to_process.pop()
add next_tria in processed
if next_tria is not opposite oriented than orientation_edge:
change next_tria (ABC) orientation (B<->C)
for each edge (AB) in next_tria:
neighbor_tria = neighbor_on_egde( next_tria, edge )
if neighbor_tria exists and neighbor_tria not in processed:
to_process add (neighbor_tria, edge opposite oriented (BA))