| 35 | # x: SparseTensor, z: PointTensor |
| 36 | # return: SparseTensor |
| 37 | def point_to_voxel(x, z): |
| 38 | if z.additional_features is None or z.additional_features.get('idx_query') is None\ |
| 39 | or z.additional_features['idx_query'].get(x.s) is None: |
| 40 | #pc_hash = hash_gpu(torch.floor(z.C).int()) |
| 41 | pc_hash = spf.sphash( |
| 42 | torch.cat([ |
| 43 | torch.floor(z.C[:, :3] / x.s).int() * x.s, |
| 44 | z.C[:, -1].int().view(-1, 1) |
| 45 | ], 1)) |
| 46 | sparse_hash = spf.sphash(x.C) |
| 47 | idx_query = spf.sphashquery(pc_hash, sparse_hash) |
| 48 | counts = spf.spcount(idx_query.int(), x.C.shape[0]) |
| 49 | z.additional_features['idx_query'][x.s] = idx_query |
| 50 | z.additional_features['counts'][x.s] = counts |
| 51 | else: |
| 52 | idx_query = z.additional_features['idx_query'][x.s] |
| 53 | counts = z.additional_features['counts'][x.s] |
| 54 | |
| 55 | inserted_feat = spf.spvoxelize(z.F, idx_query, counts) |
| 56 | new_tensor = SparseTensor(inserted_feat, x.C, x.s) |
| 57 | new_tensor.coord_maps = x.coord_maps |
| 58 | new_tensor.kernel_maps = x.kernel_maps |
| 59 | |
| 60 | return new_tensor |
| 61 | |
| 62 | |
| 63 | # x: SparseTensor, z: PointTensor |