-
Notifications
You must be signed in to change notification settings - Fork 1
/
vis.py
127 lines (118 loc) · 3.48 KB
/
vis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import nerfvis
import numpy as np
class NerfvisCallback():
def __init__(self, vis_blocking=True):
self.vis_blocking = vis_blocking
self.vis = nerfvis.Scene("nerf")
def display(self, port=8889):
self.vis.display(port=port, serve_nonblocking=(not self.vis_blocking))
def render_nerf(self, aabb, eval_fn):
# occ_non_vis = occupancy_grid.get_non_visiable()
# for level, occ_i in enumerate(occ_non_vis):
# occ_i = occ_i.cpu().numpy()
# print(occ_i.shape)
# vis.add_points(
# f"occ_{level}",
# occ_i,
# point_size=2**(5 - level),
# )
# def nerfvis_eval_fn(x, dirs):
# t = torch.zeros(*x.shape[:-1], 1, device=x.device)
# density, embedding = radiance_field.query_density(
# x, t, return_feat=True
# )
# embedding = embedding.expand(-1, dirs.shape[1], -1)
# dirs = dirs.expand(embedding.shape[0], -1, -1)
# rgb = radiance_field._query_rgb(
# dirs, embedding=embedding, apply_act=False
# )
# return rgb, density
self.vis.remove("nerf")
self.vis.add_nerf(
name="nerf",
eval_fn=eval_fn,
center=((aabb[3:] + aabb[:3]) / 2.0).tolist(),
radius=((aabb[3:] - aabb[:3]) / 2.0).max().item(),
use_dirs=True,
reso=128,
sigma_thresh=1.0,
)
self.vis.display(port=8889, serve_nonblocking=True)
def add_camera_frustum(
self,
name,
focal_length,
image_width,
image_height,
z, r, t,
):
self.vis.add_camera_frustum(
name,
focal_length=focal_length,
image_width=image_width,
image_height=image_height,
z=z,
r=r,
t=t,
)
def add_boxes(self, aabb, aabb_bkgd):
p1 = aabb[:3]
p2 = aabb[3:]
verts, segs = [
[p1[0], p1[1], p1[2]],
[p1[0], p1[1], p2[2]],
[p1[0], p2[1], p2[2]],
[p1[0], p2[1], p1[2]],
[p2[0], p1[1], p1[2]],
[p2[0], p1[1], p2[2]],
[p2[0], p2[1], p2[2]],
[p2[0], p2[1], p1[2]],
], [
[0, 1],
[1, 2],
[2, 3],
[3, 0],
[4, 5],
[5, 6],
[6, 7],
[7, 4],
[0, 4],
[1, 5],
[2, 6],
[3, 7],
]
self.vis.add_lines(
"aabb",
np.array(verts).astype(dtype=np.float32),
segs=np.array(segs),
)
p1 = aabb_bkgd[:3]
p2 = aabb_bkgd[3:]
verts, segs = [
[p1[0], p1[1], p1[2]],
[p1[0], p1[1], p2[2]],
[p1[0], p2[1], p2[2]],
[p1[0], p2[1], p1[2]],
[p2[0], p1[1], p1[2]],
[p2[0], p1[1], p2[2]],
[p2[0], p2[1], p2[2]],
[p2[0], p2[1], p1[2]],
], [
[0, 1],
[1, 2],
[2, 3],
[3, 0],
[4, 5],
[5, 6],
[6, 7],
[7, 4],
[0, 4],
[1, 5],
[2, 6],
[3, 7],
]
self.vis.add_lines(
"aabb_bkgd",
np.array(verts).astype(dtype=np.float32),
segs=np.array(segs),
)