Closed 3a1b2c3 closed 2 years ago
Hi @3a1b2c3 , Good question, we actually haven't designed an optimized function for that (but there is a good chance we may in the future as we can see some use cases), an easy way to do it would be to take the points
at the highest level from the point_hierarchy
, and do something similar to https://github.com/NVIDIAGameWorks/kaolin/blob/9085d1454c041b6300afc95ab6320e729430bb81/kaolin/ops/conversions/pointcloud.py#L171-L197
For a given point_hierarchy1
/ point_hierarchy2
and pyramid1
/ pyramid2
with matching features1
/ features2
on the last level It would look something like that:
points1 = point_hierarchy1[pyramid1[-1, 1]:pyramid1[-1, 1] + pyramid1[-1, 0]]
points2 = point_hierarchy2[pyramid2[-1, 1]:pyramid2[-1, 1] + pyramid2[-1, 0]]
all_points = torch.cat([points_hierarchy1, points_hierarchy2], dim=0)
unique, unique_keys, unique_counts = torch.unique(all_points.contiguous(), dim=0,
return_inverse=True, return_counts=True)
morton, keys = torch.sort(points_to_morton(unique.contiguous()).contiguous())
points = morton_to_points(morton.contiguous())
merged_octree = unbatched_points_to_octree(points, level, sorted=True)
all_features = torch.cat([features1, features2], dim=0)
feat = torch.zeros(unique.shape[0], all_features.shape[1], device=all_features.device).double()
# Here we just do an average when both octrees have features on the same coordinate
feat = feat.index_add_(0, unique_keys, all_features.double()) / unique_counts[..., None].double()
feat = feat.to(all_features.dtype)
merged_features = feat[keys]
If you are struggling with the variables I'm talking about, I suggest having a look at our SPC documentation to get more familiar with it.
Great, i am going through the docs at the moment. I think being able to debug draw points would be nice, on my list to add.
https://github.com/NVIDIAGameWorks/kaolin-wisp/commit/9b84ae8a84e478c2a561c08fed35a3eba1daf462 i think we can close this issue?
I have a case where i want to merge 2 separate octrees, just wondering if this already possible?