Wrote the code for the generalized distance transform, not tested yet.