Distance transform code.