Chamfer Distance计算

Chamfer Distance(CD距离)和Earth Mover's Distance(EMD)是评估三维重建效果的两个指标。
我想问的是如何在代码中实现这两种计算?
计算这两个指标是否和网络模型有关?
是不是有groundtruth(真实值)和预估模型(预测值)就可以计算了?
希望对这方面有过研究的来帮我解惑!不胜感激

这是利用trimesh库的python实现方法:

        gt_surface_pts, _ = trimesh.sample.sample_surface_even(
            tgt_mesh, sampled_points)
        pred_surface_pts, _ = trimesh.sample.sample_surface_even(
            src_mesh, sampled_points)

        _, dist_pred_gt, _ = trimesh.proximity.closest_point(
            src_mesh, gt_surface_pts)
        _, dist_gt_pred, _ = trimesh.proximity.closest_point(
            tgt_mesh, pred_surface_pts)

        dist_pred_gt[np.isnan(dist_pred_gt)] = 0
        dist_gt_pred[np.isnan(dist_gt_pred)] = 0
        chamfer_dist = 0.5 * (dist_pred_gt.mean() +
                              dist_gt_pred.mean()).item() * 100