| 10 | # z: PointTensor |
| 11 | # return: SparseTensor |
| 12 | def initial_voxelize(z, init_res, after_res): |
| 13 | new_float_coord = torch.cat( |
| 14 | [(z.C[:, :3] * init_res) / after_res, z.C[:, -1].view(-1, 1)], 1) |
| 15 | |
| 16 | pc_hash = spf.sphash(torch.floor(new_float_coord).int()) |
| 17 | sparse_hash = torch.unique(pc_hash) |
| 18 | idx_query = spf.sphashquery(pc_hash, sparse_hash) |
| 19 | counts = spf.spcount(idx_query.int(), len(sparse_hash)) |
| 20 | |
| 21 | inserted_coords = spf.spvoxelize(torch.floor(new_float_coord), idx_query, |
| 22 | counts) |
| 23 | inserted_coords = torch.round(inserted_coords).int() |
| 24 | inserted_feat = spf.spvoxelize(z.F, idx_query, counts) |
| 25 | |
| 26 | new_tensor = SparseTensor(inserted_feat, inserted_coords, 1) |
| 27 | new_tensor.check() |
| 28 | z.additional_features['idx_query'][1] = idx_query |
| 29 | z.additional_features['counts'][1] = counts |
| 30 | z.C = new_float_coord |
| 31 | |
| 32 | return new_tensor |
| 33 | |
| 34 | |
| 35 | # x: SparseTensor, z: PointTensor |