mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-12 19:04:03 +08:00
* 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
269 KiB
269 KiB
In [72]:
# HIDDEN
%load_ext autoreload
%autoreload 2
import pprint
import torch
import numpy as np
import torch
import mediapy as media
from nerfactory.data.structs import SceneBounds
from nerfactory.cameras.cameras import PinholeCamera
import timeThe autoreload extension is already loaded. To reload it, use: %reload_ext autoreload
In [73]:
# from IPython.display import HTML
# url="http://localhost:4000/?localhost:18051"
# height = 500
# HTML("""
# <div style="height: {height}px; width: 100%; overflow-x: auto; overflow-y: hidden; resize: both">
# <iframe src="{url}" style="width: 100%; height: 100%; border: none"></iframe>
# </div>
# """.format(url=url, height=height))In [74]:
# connect to the viewer from Python
from nerfactory.viewer.server.visualizer import Viewer
vis = Viewer(zmq_url="tcp://127.0.0.1:6000")In [75]:
# draw scene bounds in the viewer
s = 1
scene_bounds = SceneBounds(aabb=torch.tensor([[-s, -s, -s], [s, s, s]]))
scene_bounds_json = scene_bounds.to_json()
# draw scene bounds in the viewer
vis["sceneState/sceneBounds"].write(scene_bounds_json)
# draw scene bounds in plotly
import plotly.graph_objects as go
# TODO:/sceneState/sceneBounds
In [76]:
# HIDDEN
def get_random_rotation_matrix():
roll = torch.randn(1)
yaw = torch.randn(1)
pitch = torch.randn(1)
tensor_0 = torch.zeros(1)
tensor_1 = torch.ones(1)
RX = torch.stack(
[
torch.stack([tensor_1, tensor_0, tensor_0]),
torch.stack([tensor_0, torch.cos(roll), -torch.sin(roll)]),
torch.stack([tensor_0, torch.sin(roll), torch.cos(roll)]),
]
).reshape(3, 3)
RY = torch.stack(
[
torch.stack([torch.cos(pitch), tensor_0, torch.sin(pitch)]),
torch.stack([tensor_0, tensor_1, tensor_0]),
torch.stack([-torch.sin(pitch), tensor_0, torch.cos(pitch)]),
]
).reshape(3, 3)
RZ = torch.stack(
[
torch.stack([torch.cos(yaw), -torch.sin(yaw), tensor_0]),
torch.stack([torch.sin(yaw), torch.cos(yaw), tensor_0]),
torch.stack([tensor_0, tensor_0, tensor_1]),
]
).reshape(3, 3)
R = torch.mm(RZ, RY)
R = torch.mm(R, RX)
return RIn [77]:
# delete any current cameras
vis[f"sceneState/cameras"].delete()
# draw a camera with with an image
image = torch.rand(256, 256, 3)
media.show_image(image)
camera = PinholeCamera(cx=100, cy=100, fx=50, fy=50)
camera_json = camera.to_json(image=image)
vis[f"sceneState/cameras/000000"].write(camera_json)
# draw a camera with rotation and translation (with a black image)
image = torch.zeros(256, 256, 3)
c2w = torch.eye(4)
c2w[:3, :3] = get_random_rotation_matrix()
random_translation = torch.rand(1) * 5
c2w[:3, 3] = random_translation
camera = PinholeCamera(cx=100, cy=100, fx=50, fy=50, camera_to_world=c2w)
camera_json = camera.to_json(image=image)
vis[f"sceneState/cameras/000001"].write(camera_json)Out [77]:
/sceneState/cameras
/sceneState/cameras/000000 /sceneState/cameras/000001
b'ok'
In [78]:
# delete a camera from the Nerfviewer
vis["sceneState/cameras/000000"].delete()Out [78]:
/sceneState/cameras/000000
b'ok'
In [79]:
# read the field of view
camera = vis[f"renderingState/camera"].read()
fov = camera["object"]["fov"]
print(fov)80
In [86]:
vis[f"renderingState/field_of_view"].write(40)Out [86]:
/renderingState/field_of_view
b'ok'
In [81]:
fov = vis[f"renderingState/camera/object/fov"].read()
print(fov)None
In [82]:
# set the field of view
camera = vis[f"renderingState/camera"].read()
fov = camera["object"]["fov"]In [83]:
vis[f"renderingState/minResolution"].write(20)Out [83]:
/renderingState/minResolution
b'ok'
In [84]:
# read from a slider
vis[f"renderingState/minResolution"].read()Out [84]:
20
In [87]:
# read from output choice
vis["renderingState/output_choice"].read()Out [87]:
'depth'
In [85]:
# read from a dropdown
output_options = vis[f"renderingState/output_options"].read()
print(output_options)
output_choice = vis[f"renderingState/output_choice"].read()
print(output_choice)['rgb', 'accumulation', 'depth', 'alive_ray_mask'] None
In [ ]: