4
0
mirror of https://github.com/nerfstudio-project/nerfstudio.git synced 2026-11-11 18:44:21 +08:00
nerfstudio/nerfactory/viewer/server/state/node.py
Ethan Weber 73fedc7593
Viewer refactor with state sync (#212)
* initial commit for viewer refactor

* updating name change to nerfactory

* adding headers

* making the rendering fix which broke from a merge

* things are starting to work. removing old commands now

* removed prints

* cleanup

* updating state works now even for nested dictionaries

* updating state in redux. listening for state changes. trying to draw three.js now

* added drawing functionality. need to fix translation of frustums and image planes

* images and frustums drawn correctly

* fixing lint

* github actions

* back to npm

* fixing eslint

* remove package.json from root

* new favicon

* some viewer cleanup

* notebook

* fixed camera drawings speed to avoid redraw

* trying to get Leva to update

* quick fix

* synced config panel

* adding notebook

* fixing output print error
2022-08-02 16:02:07 -05:00

66 lines
1.7 KiB
Python

# Copyright 2022 The Plenoptix 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.
"""
For tree logic code.
"""
from collections import defaultdict
from typing import Callable
class Node(defaultdict):
"""
The base class Node.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def get_tree(node_class: Callable) -> Callable:
"""
Get a tree from a node class.
This allows one to do tree["path"]["to"]["node"]
and it will return a new node if it doesn't exist
or the current node if it does.
"""
assert isinstance(node_class(), Node)
tree = lambda: node_class(tree)
return tree()
def find_node(tree, path):
if len(path) == 0:
return tree
else:
return find_node(tree[path[0]], path[1:])
def set_node_value(tree, path, value):
if len(path) == 0:
tree.data = value
else:
set_node_value(tree[path[0]], path[1:], value)
def walk(path, tree):
"""Walk the entire tree and return the values
Args:
tree: the root of the tree to start search
"""
yield path, tree
for k, v in tree.items():
yield from walk(path + "/" + k, v)