Skip to content

Implement libtopotoolbox-based flow routing#156

Merged
wschwanghart merged 1 commit into
TopoToolbox:mainfrom
wkearn:libtt_flow_routing_d8
Apr 17, 2026
Merged

Implement libtopotoolbox-based flow routing#156
wschwanghart merged 1 commit into
TopoToolbox:mainfrom
wkearn:libtt_flow_routing_d8

Conversation

@wkearn
Copy link
Copy Markdown
Member

@wkearn wkearn commented Apr 16, 2026

Resolves #22
Resolves #15

This PR finishes implementing a pure libtopotoolbox workflow for flow routing for D8 with the 'carve' preprocessing option.

New bindings are implemented for libtopotoolbox's gwdt, flow_routing_d8_carve and flow_routing_d8_edgelist. The latter two functions are combined in a single binding, tt_flow_routing_d8_carve because there is no real reason to call them separately. The flow routing interface in libtopotoolbox is expected to change in the near future, so this should minimize the amount of changes needed in the MATLAB code.

createAuxiliaryTopo and the FLOWobj constructor now call only libtopotoolbox functions if uselibtt=true. This required a few changes to pass around the correct flats array. libtopotoolbox's gwdt expects a 32-bit integer with an encoding of flats, sills and presills, so we need to use libtopotoolbox's identifyflats explicitly to generate this. flow_routing_d8_carve also needs the flats array, but it is okay if they are just labels for the flats, so that array is also passed out of createAuxiliaryTopo for use in the FLOWobj constructor.

The resulting FLOWobj is not exactly identical to that without libtopotoolbox because of TopoToolbox/libtopotoolbox#122. It is, however, identical to the pytopotoolbox output. The libtopotoolbox implementation is slightly faster than the non-libtopotoolbox one.

The snapshot tests are updated to compare the auxiliary topography with a tolerance because libtopotoolbox does not give exactly identical answers as MATLAB for the gray-weighted distance transform.

Resolves TopoToolbox#22
Resolves TopoToolbox#15

This PR finishes implementing a pure libtopotoolbox workflow for
flow routing for D8 with the 'carve' preprocessing option.

New bindings are implemented for libtopotoolbox's `gwdt`,
`flow_routing_d8_carve` and `flow_routing_d8_edgelist`. The latter two
functions are combined in a single binding, `tt_flow_routing_d8_carve`
because there is no real reason to call them separately. The flow
routing interface in libtopotoolbox is expected to change in the near
future, so this should minimize the amount of changes needed in the
MATLAB code.

createAuxiliaryTopo and the FLOWobj constructor now call only
libtopotoolbox functions if uselibtt=true. This required a few changes
to pass around the correct flats array. libtopotoolbox's `gwdt`
expects a 32-bit integer with an encoding of flats, sills and
presills, so we need to use libtopotoolbox's identifyflats explicitly
to generate this. `flow_routing_d8_carve` also needs the flats array,
but it is okay if they are just labels for the flats, so that array is
also passed out of createAuxiliaryTopo for use in the FLOWobj
constructor.

The resulting FLOWobj is not exactly identical to that without
libtopotoolbox because of TopoToolbox/libtopotoolbox#122. It is,
however, identical to the pytopotoolbox output. The libtopotoolbox
implementation is slightly faster than the non-libtopotoolbox
one.

The snapshot tests are updated to compare the auxiliary topography
with a tolerance because libtopotoolbox does not give exactly
identical answers as MATLAB for the gray-weighted distance transform.

Signed-off-by: William Kearney <william.kearney@uni-potsdam.de>
@wschwanghart wschwanghart merged commit 6d2d4f8 into TopoToolbox:main Apr 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement gwdt MEX Use libtopotoolbox implementations in FLOWobj.createAuxiliaryTopo

2 participants