:param a: Pointclouds Batch x nul_points x dim :param b: Pointclouds Batch x nul_points x dim :return: -closest point on b of points from a -closest point on a of points from b -idx of closest point on b of points from a -idx of closest point on a of points from b W
(a, b)
| 16 | |
| 17 | |
| 18 | def distChamfer(a, b): |
| 19 | """ |
| 20 | :param a: Pointclouds Batch x nul_points x dim |
| 21 | :param b: Pointclouds Batch x nul_points x dim |
| 22 | :return: |
| 23 | -closest point on b of points from a |
| 24 | -closest point on a of points from b |
| 25 | -idx of closest point on b of points from a |
| 26 | -idx of closest point on a of points from b |
| 27 | Works for pointcloud of any dimension |
| 28 | """ |
| 29 | x, y = a.double(), b.double() |
| 30 | bs, num_points_x, points_dim = x.size() |
| 31 | bs, num_points_y, points_dim = y.size() |
| 32 | |
| 33 | xx = torch.pow(x, 2).sum(2) |
| 34 | yy = torch.pow(y, 2).sum(2) |
| 35 | zz = torch.bmm(x, y.transpose(2, 1)) |
| 36 | rx = xx.unsqueeze(1).expand(bs, num_points_y, num_points_x) # Diagonal elements xx |
| 37 | ry = yy.unsqueeze(1).expand(bs, num_points_x, num_points_y) # Diagonal elements yy |
| 38 | P = rx.transpose(2, 1) + ry - 2 * zz |
| 39 | return torch.min(P, 2)[0].float(), torch.min(P, 1)[0].float(), torch.min(P, 2)[1].int(), torch.min(P, 1)[1].int() |
| 40 |
no outgoing calls