Update documentation guides (#208)

This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-07-26 16:07:45 -07:00
1 parent 1cd697366e
commit 828365ad30
12 files changed
+148411 -148307

No files matched your search

+6 -6
View File
@@ -338,28 +338,28 @@ class EquirectangularCamera(Camera):
s_theta = torch.sin(theta)
c_theta = torch.cos(theta)
directions = torch.cat([c_theta * s_phi, s_theta * s_phi, c_phi], dim=-1)
directions = torch.cat([c_theta * s_phi, c_phi, s_theta * s_phi], dim=-1)
origins = camera_to_world[..., :3, 3] # (num_rays, 3)
## Calculate area directly
dirx_min = normalize(
torch.cat([torch.cos(d_theta_min) * s_phi, torch.sin(d_theta_min) * s_phi, c_phi], -1), dim=-1
torch.cat([torch.cos(d_theta_min) * s_phi, c_phi, torch.sin(d_theta_min) * s_phi], -1), dim=-1
)
dirx_max = normalize(
torch.cat([torch.cos(d_theta_max) * s_phi, torch.sin(d_theta_max) * s_phi, c_phi], -1), dim=-1
torch.cat([torch.cos(d_theta_max) * s_phi, c_phi, torch.sin(d_theta_max) * s_phi], -1), dim=-1
)
diry_min = normalize(
torch.cat([c_theta * torch.sin(d_phi_min), s_theta * torch.sin(d_phi_min), torch.cos(d_phi_min)], -1),
torch.cat([c_theta * torch.sin(d_phi_min), torch.cos(d_phi_min), s_theta * torch.sin(d_phi_min)], -1),
dim=-1,
)
diry_max = normalize(
torch.cat([c_theta * torch.sin(d_phi_max), s_theta * torch.sin(d_phi_max), torch.cos(d_phi_max)], -1),
torch.cat([c_theta * torch.sin(d_phi_max), torch.cos(d_phi_max), s_theta * torch.sin(d_phi_max)], -1),
dim=-1,
)
dx = torch.sqrt(torch.sum((dirx_max - dirx_min) ** 2, dim=-1))
dy = torch.sqrt(torch.sum((diry_max - diry_min) ** 2, dim=-1))
pixel_area = dx * dy
return RayBundle(origins=origins, directions=directions, pixel_area=pixel_area)
return RayBundle(origins=origins, directions=directions, pixel_area=pixel_area[..., None])
def get_intrinsics_from_intrinsics_matrix(intrinsics_matrix: TensorType[3, 3]):
+55
View File
@@ -24,6 +24,7 @@ import torch
from plotly import express as ex
from torchtyping import TensorType
from nerfactory.cameras.cameras import Camera
from nerfactory.cameras.rays import Frustums, RayBundle
from nerfactory.utils.math import Gaussians
@@ -435,3 +436,57 @@ def get_ray_bundle_lines(
name="Ray Bundle",
line=dict(color=color, width=width),
)
def vis_camera_rays(camera: Camera) -> go.Figure:
"""Visualize camera rays.
Args:
camera: Camera to visualize.
Returns:
Plotly lines
"""
coords = camera.get_image_coords()
coords[..., 0] /= camera.get_image_height()
coords[..., 1] /= camera.get_image_width()
coords = torch.cat([coords, torch.ones((*coords.shape[:-1], 1))], dim=-1)
ray_bundle = camera.get_camera_ray_bundle()
origins = ray_bundle.origins.view(-1, 3)
directions = ray_bundle.directions.view(-1, 3)
coords = coords.view(-1, 3)
lines = torch.empty((origins.shape[0] * 2, 3))
lines[0::2] = origins
lines[1::2] = origins + directions
colors = torch.empty((coords.shape[0] * 2, 3))
colors[0::2] = coords
colors[1::2] = coords
fig = go.Figure(
data=go.Scatter3d(
x=lines[:, 0],
y=lines[:, 2],
z=lines[:, 1],
marker=dict(
size=4,
color=colors,
),
line=dict(color="lightblue", width=1),
)
)
fig.update_layout(
scene=dict(
xaxis=dict(title="x", showspikes=False),
yaxis=dict(title="z", showspikes=False),
zaxis=dict(title="y", showspikes=False),
),
margin=dict(r=0, b=10, l=0, t=10),
hovermode=False,
)
return fig