From 6b4afed0a9a623346a2b18d056bcc65464ba6817 Mon Sep 17 00:00:00 2001 From: Gina Wu Date: Thu, 29 Aug 2024 16:08:35 -0700 Subject: [PATCH] ruff format exports --- nerfstudio/viewer/export_panel.py | 95 +++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 24 deletions(-) diff --git a/nerfstudio/viewer/export_panel.py b/nerfstudio/viewer/export_panel.py index 516e72425..91b61886c 100644 --- a/nerfstudio/viewer/export_panel.py +++ b/nerfstudio/viewer/export_panel.py @@ -15,11 +15,12 @@ from __future__ import annotations from pathlib import Path +from typing import cast import viser import viser.transforms as vtf -from typing_extensions import Literal, Tuple, List -from typing import cast +from typing_extensions import Literal, Tuple + from nerfstudio.data.scene_box import OrientedBox from nerfstudio.models.base_model import Model from nerfstudio.models.splatfacto import SplatfactoModel @@ -40,7 +41,9 @@ def populate_export_tab( def _(_) -> None: control_panel.crop_viewport = crop_output.value - server.gui.add_markdown("Export available after a checkpoint is saved (default minimum 2000 steps)") + server.gui.add_markdown( + "Export available after a checkpoint is saved (default minimum 2000 steps)" + ) with server.gui.add_folder("Splat"): populate_splat_tab(server, control_panel, config_path, viewing_gsplat) with server.gui.add_folder("Point Cloud"): @@ -91,7 +94,9 @@ def get_crop_string(obb: OrientedBox, crop_viewport: bool) -> str: rpystring = " ".join([f"{x:.10f}" for x in rpy]) posstring = " ".join([f"{x:.10f}" for x in pos]) scalestring = " ".join([f"{x:.10f}" for x in scale]) - return f"--obb_center {posstring} --obb_rotation {rpystring} --obb_scale {scalestring}" + return ( + f"--obb_center {posstring} --obb_rotation {rpystring} --obb_scale {scalestring}" + ) Vec3f = Tuple[float, float, float] @@ -105,7 +110,11 @@ def get_crop_tuple(obb: OrientedBox, crop_viewport: bool): obb_rotation = [rpy.roll, rpy.pitch, rpy.yaw] obb_center = obb.T.squeeze().tolist() obb_scale = obb.S.squeeze().tolist() - return cast(Vec3f, tuple(obb_center)), cast(Vec3f, tuple(obb_rotation)), cast(Vec3f, tuple(obb_scale)) + return ( + cast(Vec3f, tuple(obb_center)), + cast(Vec3f, tuple(obb_rotation)), + cast(Vec3f, tuple(obb_scale)), + ) def populate_point_cloud_tab( @@ -115,8 +124,12 @@ def populate_point_cloud_tab( viewing_gsplat: bool, ) -> None: if not viewing_gsplat: - server.gui.add_markdown("Render depth, project to an oriented point cloud, and filter ") - num_points = server.gui.add_number("# Points", initial_value=1_000_000, min=1, max=None, step=1) + server.gui.add_markdown( + "Render depth, project to an oriented point cloud, and filter " + ) + num_points = server.gui.add_number( + "# Points", initial_value=1_000_000, min=1, max=None, step=1 + ) world_frame = server.gui.add_checkbox( "Save in world frame", False, @@ -134,10 +147,16 @@ def populate_point_cloud_tab( hint="Normal map source.", ) - output_dir = server.gui.add_text("Output Directory", initial_value="exports/pcd/") + output_dir = server.gui.add_text( + "Output Directory", initial_value="exports/pcd/" + ) export_button = server.gui.add_button("Export", icon=viser.Icon.FILE_EXPORT) - download_button = server.gui.add_button("Download Point Cloud", icon=viser.Icon.DOWNLOAD, disabled=True) - generate_command = server.gui.add_button("Generate Command", icon=viser.Icon.TERMINAL_2) + download_button = server.gui.add_button( + "Download Point Cloud", icon=viser.Icon.DOWNLOAD, disabled=True + ) + generate_command = server.gui.add_button( + "Generate Command", icon=viser.Icon.TERMINAL_2 + ) @export_button.on_click def _(event: viser.GuiEvent) -> None: @@ -203,13 +222,17 @@ def populate_point_cloud_tab( f"--remove-outliers {remove_outliers.value}", f"--normal-method {normals.value}", f"--save-world-frame {world_frame.value}", - get_crop_string(control_panel.crop_obb, control_panel.crop_viewport), + get_crop_string( + control_panel.crop_obb, control_panel.crop_viewport + ), ] ) show_command_modal(event.client, "point cloud", command) else: - server.gui.add_markdown("Point cloud export is not currently supported with Gaussian Splatting") + server.gui.add_markdown( + "Point cloud export is not currently supported with Gaussian Splatting" + ) def populate_mesh_tab( @@ -230,14 +253,24 @@ def populate_mesh_tab( hint="Source for normal maps.", ) num_faces = server.gui.add_number("# Faces", initial_value=50_000, min=1) - texture_resolution = server.gui.add_number("Texture Resolution", min=8, initial_value=2048) - num_points = server.gui.add_number("# Points", initial_value=1_000_000, min=1, max=None, step=1) + texture_resolution = server.gui.add_number( + "Texture Resolution", min=8, initial_value=2048 + ) + num_points = server.gui.add_number( + "# Points", initial_value=1_000_000, min=1, max=None, step=1 + ) remove_outliers = server.gui.add_checkbox("Remove outliers", True) - output_dir = server.gui.add_text("Output Directory", initial_value="exports/mesh/") + output_dir = server.gui.add_text( + "Output Directory", initial_value="exports/mesh/" + ) export_button = server.gui.add_button("Export", icon=viser.Icon.FILE_EXPORT) - download_button = server.gui.add_button("Download Mesh", icon=viser.Icon.DOWNLOAD, disabled=True) - generate_command = server.gui.add_button("Generate Command", icon=viser.Icon.TERMINAL_2) + download_button = server.gui.add_button( + "Download Mesh", icon=viser.Icon.DOWNLOAD, disabled=True + ) + generate_command = server.gui.add_button( + "Generate Command", icon=viser.Icon.TERMINAL_2 + ) @export_button.on_click def _(event: viser.GuiEvent) -> None: @@ -305,13 +338,17 @@ def populate_mesh_tab( f"--num-points {num_points.value}", f"--remove-outliers {remove_outliers.value}", f"--normal-method {normals.value}", - get_crop_string(control_panel.crop_obb, control_panel.crop_viewport), + get_crop_string( + control_panel.crop_obb, control_panel.crop_viewport + ), ] ) show_command_modal(event.client, "mesh", command) else: - server.gui.add_markdown("Mesh export is not currently supported with Gaussian Splatting") + server.gui.add_markdown( + "Mesh export is not currently supported with Gaussian Splatting" + ) def populate_splat_tab( @@ -322,10 +359,16 @@ def populate_splat_tab( ) -> None: if viewing_gsplat: server.gui.add_markdown("Generate ply export of Gaussian Splat") - output_dir = server.gui.add_text("Output Directory", initial_value="exports/splat/") + output_dir = server.gui.add_text( + "Output Directory", initial_value="exports/splat/" + ) export_button = server.gui.add_button("Export", icon=viser.Icon.FILE_EXPORT) - download_button = server.gui.add_button("Download Splat", icon=viser.Icon.DOWNLOAD, disabled=True) - generate_command = server.gui.add_button("Generate Command", icon=viser.Icon.TERMINAL_2) + download_button = server.gui.add_button( + "Download Splat", icon=viser.Icon.DOWNLOAD, disabled=True + ) + generate_command = server.gui.add_button( + "Generate Command", icon=viser.Icon.TERMINAL_2 + ) @export_button.on_click def _(event: viser.GuiEvent) -> None: @@ -383,10 +426,14 @@ def populate_splat_tab( "ns-export gaussian-splat", f"--load-config {config_path}", f"--output-dir {output_dir.value}", - get_crop_string(control_panel.crop_obb, control_panel.crop_viewport), + get_crop_string( + control_panel.crop_obb, control_panel.crop_viewport + ), ] ) show_command_modal(event.client, "splat", command) else: - server.gui.add_markdown("Splat export is only supported with Gaussian Splatting methods") + server.gui.add_markdown( + "Splat export is only supported with Gaussian Splatting methods" + )