Base class for Points. Args: tensor (Tensor or np.ndarray or Sequence[Sequence[float]]): The points data with shape (N, points_dim). points_dim (int): Integer indicating the dimension of a point. Each row is (x, y, z, ...). Defaults to 3. attribut
| 12 | |
| 13 | |
| 14 | class BasePoints: |
| 15 | """Base class for Points. |
| 16 | |
| 17 | Args: |
| 18 | tensor (Tensor or np.ndarray or Sequence[Sequence[float]]): The points |
| 19 | data with shape (N, points_dim). |
| 20 | points_dim (int): Integer indicating the dimension of a point. Each row |
| 21 | is (x, y, z, ...). Defaults to 3. |
| 22 | attribute_dims (dict, optional): Dictionary to indicate the meaning of |
| 23 | extra dimension. Defaults to None. |
| 24 | |
| 25 | Attributes: |
| 26 | tensor (Tensor): Float matrix with shape (N, points_dim). |
| 27 | points_dim (int): Integer indicating the dimension of a point. Each row |
| 28 | is (x, y, z, ...). |
| 29 | attribute_dims (dict, optional): Dictionary to indicate the meaning of |
| 30 | extra dimension. Defaults to None. |
| 31 | rotation_axis (int): Default rotation axis for points rotation. |
| 32 | """ |
| 33 | |
| 34 | def __init__(self, |
| 35 | tensor: Union[Tensor, np.ndarray, Sequence[Sequence[float]]], |
| 36 | points_dim: int = 3, |
| 37 | attribute_dims: Optional[dict] = None) -> None: |
| 38 | if isinstance(tensor, Tensor): |
| 39 | device = tensor.device |
| 40 | else: |
| 41 | device = torch.device('cpu') |
| 42 | tensor = torch.as_tensor(tensor, dtype=torch.float32, device=device) |
| 43 | if tensor.numel() == 0: |
| 44 | # Use reshape, so we don't end up creating a new tensor that does |
| 45 | # not depend on the inputs (and consequently confuses jit) |
| 46 | tensor = tensor.reshape((-1, points_dim)) |
| 47 | assert tensor.dim() == 2 and tensor.size(-1) == points_dim, \ |
| 48 | ('The points dimension must be 2 and the length of the last ' |
| 49 | f'dimension must be {points_dim}, but got points with shape ' |
| 50 | f'{tensor.shape}.') |
| 51 | |
| 52 | self.tensor = tensor.clone() |
| 53 | self.points_dim = points_dim |
| 54 | self.attribute_dims = attribute_dims |
| 55 | self.rotation_axis = 0 |
| 56 | |
| 57 | @property |
| 58 | def coord(self) -> Tensor: |
| 59 | """Tensor: Coordinates of each point in shape (N, 3).""" |
| 60 | return self.tensor[:, :3] |
| 61 | |
| 62 | @coord.setter |
| 63 | def coord(self, tensor: Union[Tensor, np.ndarray]) -> None: |
| 64 | """Set the coordinates of each point. |
| 65 | |
| 66 | Args: |
| 67 | tensor (Tensor or np.ndarray): Coordinates of each point with shape |
| 68 | (N, 3). |
| 69 | """ |
| 70 | try: |
| 71 | tensor = tensor.reshape(self.shape[0], 3) |
nothing calls this directly
no outgoing calls
no test coverage detected