Adapted version of DepthMap3d