| 240 | |
| 241 | |
| 242 | class ViserPointCloudPane: |
| 243 | EMPTY_POINTS = np.zeros((0, 3), dtype=np.float32) |
| 244 | EMPTY_COLORS = np.zeros((0, 3), dtype=np.uint8) |
| 245 | |
| 246 | def __init__( |
| 247 | self, |
| 248 | args: argparse.Namespace, |
| 249 | intrinsics: CameraIntrinsics, |
| 250 | name: str, |
| 251 | label: str, |
| 252 | port: int, |
| 253 | ): |
| 254 | try: |
| 255 | import viser |
| 256 | except ImportError as exc: |
| 257 | raise RuntimeError("viser is required for --show-viser; install it with `uv pip install viser`.") from exc |
| 258 | |
| 259 | self.name = name |
| 260 | self.label_text = label |
| 261 | self.projector = DepthPointCloudProjector(intrinsics, args.pointcloud_stride) |
| 262 | self.server = viser.ViserServer(host=args.viser_host, port=port, label=label) |
| 263 | self.server.scene.set_up_direction("+z") |
| 264 | self.server.initial_camera.position = (0.0, -1.3, 0.55) |
| 265 | self.server.initial_camera.look_at = (0.0, 0.85, 0.0) |
| 266 | self.server.initial_camera.up = (0.0, 0.0, 1.0) |
| 267 | self.server.initial_camera.far = 10.0 |
| 268 | self.server.gui.configure_theme(control_layout="collapsible", control_width="medium", dark_mode=True) |
| 269 | |
| 270 | self.data_lock = threading.Lock() |
| 271 | self.current_points = self.EMPTY_POINTS |
| 272 | self.current_pixels = np.zeros((0, 2), dtype=np.int32) |
| 273 | self.latest_depth_m: np.ndarray | None = None |
| 274 | self.latest_min_depth_m = float(args.pointcloud_min_depth) |
| 275 | self.latest_max_depth_m = float(args.pointcloud_max_depth) |
| 276 | |
| 277 | self.axis = self.server.scene.add_frame(f"/{name}/camera", axes_length=0.12, axes_radius=0.006) |
| 278 | self.label = self.server.scene.add_label( |
| 279 | f"/{name}/label", |
| 280 | label, |
| 281 | position=(0.0, -0.08, 0.42), |
| 282 | anchor="center-center", |
| 283 | ) |
| 284 | self.cloud = self.server.scene.add_point_cloud( |
| 285 | f"/{name}/points", |
| 286 | self.EMPTY_POINTS, |
| 287 | self.EMPTY_COLORS, |
| 288 | point_size=args.pointcloud_point_size, |
| 289 | point_shape="rounded", |
| 290 | point_shading="flat", |
| 291 | precision=args.pointcloud_precision, |
| 292 | ) |
| 293 | self.selection_marker = self.server.scene.add_icosphere( |
| 294 | f"/{name}/selection_marker", |
| 295 | radius=0.012, |
| 296 | color=(255, 230, 0), |
| 297 | position=(0.0, 0.0, 0.0), |
| 298 | visible=False, |
| 299 | ) |