mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 06:35:36 +08:00
* Copy in `viser` communication infrastructure * Update background image * Add build directory to fix viser HTTP server May want to remove these later * Copy in `viser` communication infrastructure * Update background image * Pass dataset vis using viser * initial impl of ViewerParameter * idk what i did but brent and matt know * Suppress eslint typescript warnings * implement ViewerElement base class, then ViewerButton, ViewerSlider, etc * client -> server message setup * multi folder stuff * Stream controls over viser * import * add types to viewer_param.py * Move another message to viser * Update folder color * Use non throttled messages * multiple folders works * Cleanup, more porting * starting impl of control panel in viser * More porting * scenebox to viser * Cleanup * Fix render updates * More cleanup, docs, typing * start control_panel.py * set_hidden logic but not merged in * control_panel replicates behavior of existing control panel (visually), except for setting the list of output options. not yet integrated with viewer_utils.py for logic flow. also implemented set_disabled and set_hidden in javscript/ViewerElement side * Remove some original leva components * add some train util logic, attempt set_value, doesn't work on javascript side fully yet (value updates but not slider visually * bye zmq * missing call to decoder * 'gui_set' works properly, control panel now replicates behavior of original * remove print * Fix status viewer message * More cleanup * support set_options in dropdown * hiding buttons works correctly * fix set_options, switch from cur_value to get_value() * Fix slowdown * output options * colormap logic converted * add handle to cb_hook * fix some lambda bugs * cleanup * Save checkpoint logic readded * Cleanup and minor fixes * snappier ui * Refactoring * Fix state update bugs * Bug fixes * Write less to redux * added comments to reducer code * Render state machine (#1727) * state machine works, but train step throttling not implemented * more step logic, cleanup * remove random try catcH * mutex logic for render * Update lock logic * types and docs * added some state machine logic to help rerenders * merge --------- Co-authored-by: Justin <justin.g.kerr@gmail.com> * Refactor and cleanup * More cleanup and docs * docstring to gui_utils * docstrings, rename viewer_param.py to viewer_elements.py * Fix viewer, remove bridge stuff * Render on connect * Fix lint errors * More eslint fixes * render_freq logic * better rerender logic for crop * More cleanup * Purge * Cleanup * Lint fixes * Fix cache * better parsing logic * Fix infinite test * More cleanup * typo * Update webdocs * Update docs * rerender on custom hooks * add more docs * Use shared utilities in `viser.infra` * rework callback to use elements instead of handles * Fix ESlint errors * change naming of handle to element, add setter for value * cleanup --------- Co-authored-by: Matt Tancik <mattt4001@gmail.com> Co-authored-by: Justin <justin.g.kerr@gmail.com> Co-authored-by: Ethan Weber <eweb0124@gmail.com> Co-authored-by: Matthew Tancik <tancik@berkeley.edu>
82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
# Copyright 2022 The Nerfstudio Team. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
""" Utilites for generating custom gui elements in the viewer """
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, List, Tuple
|
|
|
|
from torch import nn
|
|
|
|
from nerfstudio.pipelines.base_pipeline import Pipeline
|
|
from nerfstudio.viewer.server.viewer_elements import ViewerElement
|
|
|
|
|
|
def parse_object(
|
|
obj: Any,
|
|
type_check,
|
|
tree_stub: str,
|
|
) -> List[Tuple[str, Any]]:
|
|
"""
|
|
obj: the object to parse
|
|
type_check: recursively adds instances of this type to the output
|
|
tree_stub: the path down the object tree to this object
|
|
|
|
Returns:
|
|
a list of (path/to/object, obj), which represents the path down the object tree
|
|
along with the object itself
|
|
"""
|
|
|
|
def add(ret: List[Tuple[str, Any]], ts: str, v: Any):
|
|
"""
|
|
helper that adds to ret, and if v exists already keeps the tree stub with
|
|
the shortest path
|
|
"""
|
|
for i, (t, o) in enumerate(ret):
|
|
if o == v:
|
|
if len(t.split("/")) > len(ts.split("/")):
|
|
ret[i] = (ts, v)
|
|
return
|
|
ret.append((ts, v))
|
|
|
|
if not hasattr(obj, "__dict__"):
|
|
return []
|
|
ret = []
|
|
# get a list of the properties of the object, sorted by whether things are instances of type_check
|
|
obj_props = [(k, getattr(obj, k)) for k in dir(obj)]
|
|
for (k, v) in obj_props:
|
|
if k[0] == "_":
|
|
continue
|
|
new_tree_stub = f"{tree_stub}/{k}"
|
|
if isinstance(v, type_check):
|
|
add(ret, new_tree_stub, v)
|
|
elif isinstance(v, nn.Module):
|
|
lower_rets = parse_object(v, type_check, new_tree_stub)
|
|
# check that the values aren't already in the tree
|
|
for ts, o in lower_rets:
|
|
add(ret, ts, o)
|
|
return ret
|
|
|
|
|
|
def get_viewer_elements(pipeline: Pipeline) -> List[Tuple[str, ViewerElement]]:
|
|
"""
|
|
Recursively parse the pipeline object and return a tree of all the ViewerElements contained
|
|
|
|
returns a list of (path/to/object, param), which represents the path down the object tree as well as
|
|
the ViewerElement itself
|
|
"""
|
|
ret = parse_object(pipeline, ViewerElement, "Custom")
|
|
return ret
|