MCPcopy
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / point_to_voxel

Function point_to_voxel

lib/spvcnn_utils.py:37–60  ·  view source on GitHub ↗
(x, z)

Source from the content-addressed store, hash-verified

35# x: SparseTensor, z: PointTensor
36# return: SparseTensor
37def 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

Callers 1

forwardMethod · 0.85

Calls 2

getMethod · 0.80
catMethod · 0.80

Tested by

no test coverage detected