MCPcopy Index your code
hub / github.com/apple/ml-pointersect / cat

Method cat

pointersect/inference/structures.py:420–466  ·  view source on GitHub ↗

concatenate at `dim`.

(point_clouds: T.List['PointCloud'], dim: int)

Source from the content-addressed store, hash-verified

418
419 @staticmethod
420 def cat(point_clouds: T.List['PointCloud'], dim: int) -> 'PointCloud':
421 """concatenate at `dim`."""
422
423 if dim == 0:
424 # check all point clouds have the same included_point_at_inf and n
425 for i in range(1, len(point_clouds)):
426 assert point_clouds[i].included_point_at_inf == point_clouds[0].included_point_at_inf
427 assert point_clouds[i].xyz_w.size(1) == point_clouds[0].xyz_w.size(1)
428
429 out_dict = dict()
430 for name in point_clouds[0].attr_names:
431 arr = [getattr(p, name, None) for p in point_clouds]
432 if None in arr:
433 out_dict[name] = None
434 else:
435 out_dict[name] = torch.cat(arr, dim=dim)
436
437 if len(point_clouds) > 0:
438 out_dict['included_point_at_inf'] = point_clouds[0].included_point_at_inf
439 else:
440 out_dict['included_point_at_inf'] = False
441 elif dim == 1:
442 out_dict = dict()
443 for name in point_clouds[0].attr_names:
444 arrs = []
445 for i in range(len(point_clouds)):
446 arr = getattr(point_clouds[i], name, None)
447 if arr is not None:
448 if point_clouds[i].included_point_at_inf and i > 0:
449 start_idx = 1 # remove point at inf for i >= 1
450 else:
451 start_idx = 0
452 arr = arr[:, start_idx:]
453 arrs.append(arr)
454
455 if None in arrs:
456 out_dict[name] = None
457 else:
458 out_dict[name] = torch.cat(arrs, dim=dim)
459
460 if len(point_clouds) > 0:
461 out_dict['included_point_at_inf'] = point_clouds[0].included_point_at_inf
462 else:
463 out_dict['included_point_at_inf'] = False
464 else:
465 raise NotImplementedError
466 return PointCloud(**out_dict)
467
468 def voxel_downsampling(
469 self,

Callers

nothing calls this directly

Calls 3

PointCloudClass · 0.85
sizeMethod · 0.80
catMethod · 0.45

Tested by

no test coverage detected