Source code for ddg.datastructures.halfedge.grid

from collections import deque

from ddg.datastructures.halfedge.get import get_opposite_edge_in_face

####################################
# grid-like hds and coordinate lines
####################################


[docs]def get_coordinate_polylines(hed): """ Finds parallel coordinate lines in a grid-like half-edge data structure with quadrilateral faces. Parameters ---------- hed : half-edge data structure Returns ------- x_lines, y_lines : deque , deque Consists of deques consisting of half-edges representing the polylines. Each polyline is only represented by one chain of half-edges with fixed direction Notes ----- * The y-direction ist given by v0.edge where v0 ist the first vertex of hed.verts. """ v0 = list(hed.verts)[0] ye = v0.edge.opp # outedge y y_lines = deque(reversed(_get_parallel_polylines(ye))) if v0.edge.face: xe = v0.edge.nex # outedge x else: xe = v0.edge.opp.pre.opp x_lines = _get_parallel_polylines(xe) return x_lines, y_lines
def _get_parallel_polylines(xe): act_xedge = xe x_lines = deque() while True: x_lines.append(get_coordinate_polyline(act_xedge)) if act_xedge.face is None: break else: act_xedge = get_opposite_edge_in_face(act_xedge) if xe.opp.face is not None: act_xedge = get_opposite_edge_in_face(xe.opp).opp while True: x_lines.appendleft(get_coordinate_polyline(act_xedge)) if act_xedge.opp.face is None: break else: act_xedge = get_opposite_edge_in_face(act_xedge.opp).opp return x_lines
[docs]def get_coordinate_polyline(e): polyline = deque() polyline.append(e) act_edge = e while True: act_edge = _get_next_edge_on_coordinate_line(act_edge) if act_edge is not None: polyline.append(act_edge) else: break act_edge = e while True: act_edge = _get_prev_edge_on_coordinate_line(act_edge) if act_edge is not None: polyline.appendleft(act_edge) else: break return polyline
def _get_next_edge_on_coordinate_line(e): if e.face is not None: next_edge = e.nex.opp if next_edge.face is not None: return next_edge.nex else: next_edge = e.opp.pre.opp if next_edge.face is not None: return next_edge.pre.opp return None def _get_prev_edge_on_coordinate_line(e): if e.face is not None: next_edge = e.pre.opp if next_edge.face is not None: return next_edge.pre else: next_edge = e.opp.nex.opp if next_edge.face is not None: return next_edge.nex.opp return None