Algorithm 3: Finding saddles and outlets
Input : Terrain cells with elevation , set of depression basins
Output: Per-depression saddle and outlet
1 // Compute border cells and store the border altitude in
2 foreach cell in parallel do
3 if of any 4-neighbour of () then
4 tag as a border cell
5
6
7 end
8 end
9 // Saddles and outlets (with atomic lexicographic argmin)
10 foreach basin in parallel do
11 saddle of for each border cell
12 and such that and )
13 outlet of for each neighbor of the
14 saddle such that )
15 end
16 // Remove cycles
17 foreach basin in parallel do
18 basin of outlet of
19 if of outlet of of saddle of then
20 if of outlet of of saddle of then
21 Delete the saddle and outlet of
22 end
23 end
24 end
our two-layer structure, with an implicit depression graph and explicit flow routing, this needs to be interpreted differently. Instead, we merge stream trees by adding and re-routing recipient links, using one of two strategies (Figure 5 (b)).
The first strategy, depression jumping, involves adding a recipient link directly from the depression's local minima to the newly established outlet cell. This is straightforward and efficient but leads to a jump discontinuity in the flow path, which, depending on the application, may be undesirable.
The second strategy, depression carving [Rie98], mimics the course of water channeling down from the saddle. We first compute the flow path that connects a saddle and outlet to the associated local minimum and then reverse the direction of all recipient links. In this way, we allow water to flow upstream from the local minimum to the outlet. The pseudo-code for these two strategies is presented in Algorithm 4.
A single iteration of basin identification, saddle edge selection, and re-routing of recipients ends up being insufficient. It will not necessarily connect all depressions to the set of outflow basins. However, on any given iteration this process removes at least half of the remaining depressions, meaning that a total of iterations are required, where is the number of local minima (Algorithm 5).