Normalize point cloud coordinates. Args: pc (ndarray or Tensor): [N, 3] 点云坐标 (x, y, z) method (str): 'sphere' 将点云归一化到单位球; 'cube' 将点云归一化到[-1, 1]立方体 Returns: pc_normalized (same type): 归一化后的点云 centroid (ndarray): 原始质心 scale (
(pc, method='sphere')
| 178 | return results |
| 179 | |
| 180 | def normalize_point_cloud(pc, method='sphere'): |
| 181 | """ |
| 182 | Normalize point cloud coordinates. |
| 183 | |
| 184 | Args: |
| 185 | pc (ndarray or Tensor): [N, 3] 点云坐标 (x, y, z) |
| 186 | method (str): 'sphere' 将点云归一化到单位球; |
| 187 | 'cube' 将点云归一化到[-1, 1]立方体 |
| 188 | |
| 189 | Returns: |
| 190 | pc_normalized (same type): 归一化后的点云 |
| 191 | centroid (ndarray): 原始质心 |
| 192 | scale (float): 缩放系数(半径或最大边长) |
| 193 | """ |
| 194 | if isinstance(pc, torch.Tensor): |
| 195 | is_tensor = True |
| 196 | pc_np = pc.detach().cpu().numpy() |
| 197 | else: |
| 198 | is_tensor = False |
| 199 | pc_np = pc |
| 200 | |
| 201 | # 1️⃣ 去中心化 |
| 202 | centroid = np.mean(pc_np, axis=0) |
| 203 | pc_np = pc_np - centroid |
| 204 | |
| 205 | # 2️⃣ 缩放到单位球 or 立方体 |
| 206 | if method == 'sphere': |
| 207 | scale = np.max(np.linalg.norm(pc_np, axis=1)) |
| 208 | elif method == 'cube': |
| 209 | scale = np.max(np.abs(pc_np)) |
| 210 | else: |
| 211 | raise ValueError("method must be 'sphere' or 'cube'") |
| 212 | |
| 213 | pc_np = pc_np / (scale + 1e-6) |
| 214 | |
| 215 | if is_tensor: |
| 216 | return torch.from_numpy(pc_np).to(pc.device).type(pc.dtype), torch.from_numpy(centroid).to(pc.device), scale |
| 217 | else: |
| 218 | return pc_np, centroid, scale |
| 219 | |
| 220 | def get_generated_points( |
| 221 | root_path=None |
nothing calls this directly
no outgoing calls
no test coverage detected