Let
component(e)
mark(e);
e' := e;
while(e'≠ e) do
e' := next(e');
if (e' == e) return true;
mark(e');
endwhile
e':=e;
while (e' ≠ NULL) do
e' := prev(e');
if(e'==e) return false;
mark(e');
endwhile
findcomponents()
num_circles :=0;
num_ints :=0;
unmark all edges;
for each edge e do
if (marked(e)) continue;
if (component(e))
then num_circles ++;
else num_ints++;
endif
Data Structure for surfaces
There are winged edges, half edges and quad edges. An oriented edge has the vertices head and tail and the faces left and right.
head-next(e) = – r-next(e)
head-prev(e) = – l-next(e)
tail-next(e) = – l-prev(e)
tail-prev(e) = – r-prev(e)
There is a duality: vertex
Quad edge represents both together, vertex and face are the same data structure (e.g. coordinates of vertex area of dual face). A “quad edge<2 has pointers to four vertices/faces and pointers to four other quad edges.
Store quad edge once. A reference to a quad edge is a pointer to this data structure together with two bits
mark all edges, faces, vertices
for each edge e do
if unmarked(e)
then find_component(left(e));
end for
find_component(f)
recursively mark all neighbors (breath-first or order-first, pruning when we see a marked face);
As we go, count faces, edges, vertices;
If we pass a marked face again with oposite direction, set a “nonorientability” flag.
Need to count components:
With some modifications quad edges, etc. also work for multigraphs in a surface.
Similarly, for any 2-complex in
A facet edge
next_edge(
The facet edge has four pointers to
Especially when the complex forms a closed 3-manifold, we can implement duality as quad edge.