Label connected components using a serial algorithm. Designed to be used on its own or as a part of the "parallel" implementation.
Uses input
to generate the mask of patches "on the fly", saves results to output
.
This is implemented as a template function to allow using different "2D array" types.
The "mask" type has to implement methods
bool is_foreground(row, col)
indicating if a grid cell is a "foreground" cell (part of a "patch" or a "component") or "background".
bool is_attached(row, col)
indicating if a grid cell is "attached". Patches that do not contain any "attached" cells are considered "isolated". This method is called only if identify_isolated_patches
is true
.
The "array" type has to implement number_t& operator(row, col)
for some numeric type number_t
(int, double, etc). The argument output
is "write only".
If assign_final_labels
is true, then set labels to "final" values. This is appropriate when this function is used on its own (serial algorithm).
Specifically:
- If
assign_final_labels
is true and identify_isolated_patches
is true, then isolated patches are marked with 1
and the rest are set to 0
.
- If
assign_final_labels
is true and identify_isolated_patches
is false, then patches are labeled with consecutive numbers starting from min_label
.
- If
assign_final_labels
is false then patches "attached" to cells where is_attached(i, j)
is true are marked with the smallest odd number that is greater than or equal to min_label
. All other patches get consecutive even labels. This labeling scheme is used by the parallel version of this code.
Uses labels starting from min_label
. In the parallel implementation each MPI rank (each sub-domain) has to use unique labels; min_labels
is used to guarantee this.
Note: only foreground cells of output
are updated.
Definition at line 193 of file connected_components_impl.hh.
References pism::k, L, pism::connected_components::details::Run::label, pism::connected_components::details::Run::length, n, and resolve_label().