Spaces:
Sleeping
Sleeping
Download utils/pointcloud_tools.py from shin0624/Factory_Layout_Simulator: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/shin0624/Factory_Layout_Simulator/resolve/main/utils/pointcloud_tools.py
- Command line
-
hf download hf://spaces/shin0624/Factory_Layout_Simulator/utils/pointcloud_tools.py
-
curl -L -o pointcloud_tools.py https://huggingface.co/spaces/shin0624/Factory_Layout_Simulator/resolve/main/utils/pointcloud_tools.py
1.72 kB
| # utils/pointcloud_tools.py | |
| import numpy as np | |
| import trimesh | |
| from typing import List | |
| class PointCloudProcessor: | |
| def normalize_points(points: np.ndarray) -> np.ndarray: | |
| """ํฌ์ธํธ ํด๋ผ์ฐ๋ ์ ๊ทํ""" | |
| if len(points) == 0: | |
| return points | |
| # Z-score ์ ๊ทํ | |
| mean = np.mean(points, axis=0) | |
| std = np.std(points, axis=0) | |
| # ํ์คํธ์ฐจ๊ฐ 0์ธ ๊ฒฝ์ฐ ๋๋น | |
| std = np.where(std < 1e-8, 1, std) | |
| return (points - mean) / std | |
| def filter_outliers(points: np.ndarray, z_thresh=3.0) -> np.ndarray: | |
| """์ด์์น ์ ๊ฑฐ""" | |
| if len(points) == 0: | |
| return points | |
| if len(points) <= 3: # ํฌ์ธํธ๊ฐ ๋๋ฌด ์ ์ผ๋ฉด ํํฐ๋ง ์๋ต | |
| return points | |
| z_scores = np.abs(points - np.mean(points, axis=0)) / (np.std(points, axis=0) + 1e-8) | |
| mask = (z_scores < z_thresh).all(axis=1) | |
| # ๋ชจ๋ ํฌ์ธํธ๊ฐ ํํฐ๋ง๋์ง ์๋๋ก ๋ณดํธ | |
| if not np.any(mask): | |
| return points | |
| return points[mask] | |
| def create_mesh(points: np.ndarray) -> trimesh.Trimesh: | |
| """ํฌ์ธํธ ํด๋ผ์ฐ๋์์ ๋ฉ์ฌ ์์ฑ""" | |
| return trimesh.points.PointCloud(points) | |
| def merge_pointclouds(clouds: List[np.ndarray]) -> np.ndarray: | |
| """๋ค์ค ํฌ์ธํธ ํด๋ผ์ฐ๋ ๋ณํฉ""" | |
| return np.vstack(clouds) if clouds else np.array([]) | |
| def save_as_obj(points: np.ndarray, filename: str): | |
| """OBJ ํ์ผ๋ก ์ ์ฅ""" | |
| mesh = trimesh.points.PointCloud(points) | |
| mesh.export(filename) |