in c3dm/tools/vis_utils.py [0:0]
def visdom_plotly_cameras(
viz,
cameras,
visdom_env='main',
visdom_win=None,
title=None,
markersize=2,
nmax=5000,
in_subplots=False,
camera_scale=0.05, # in multiples of std_dev of the scene pointcloud
height=1000,
width=1000,
):
titles = [title]
fig = make_subplots(
rows = 1, cols = 1,
specs=[[{"type": "scene"}]],
subplot_titles=titles,
column_widths=[1.],
)
all_pts = []
# add cameras
R = cameras[:,:,:3]
t = cameras[:,:,3:]
C = -np.matmul(R.transpose(0, 2, 1), t)
all_pts = C[:,:,0]
scene_std = all_pts.std(0).mean()
cam_lines_canonical = _get_camera_wireframe(scale=camera_scale*scene_std)
cmap = cm.get_cmap('rainbow')
camera_colors = cmap(np.linspace(0., 1., R.shape[0]))[:, :3]
# mult by 220 here to make the colors a bit darker
camera_colors = ['rgb(%s)' % ','.join(
[str(int(c*220.)) for c in clr]
) for clr in camera_colors]
for clr_, R_, t_ in zip(camera_colors, R, t):
cam_lines_world = R_.T @ (cam_lines_canonical.T - t_)
x, y, z = cam_lines_world
fig.add_trace(
go.Scatter3d(
x=x, y=y, z=z,
marker=dict(
size=2,
# colorscale='Spectral',
color=clr_,
),
line=dict(
# colorscale='Spectral',
color=clr_,
width=2,
)
),
row=1,
col=1,
)
pcl_c = all_pts.mean(0)
maxextent = (all_pts.max(axis=0) - all_pts.min(axis=0)).max()
bounds = np.stack((pcl_c.T-maxextent, pcl_c.T+maxextent))
fig.update_layout(height = height, width = width,
showlegend=False,
scene = dict(
xaxis=dict(range=[bounds[0,0], bounds[1,0]]),
yaxis=dict(range=[bounds[0,1], bounds[1,1]]),
zaxis=dict(range=[bounds[0,2], bounds[1,2]]),
aspectmode='cube',
)
)
viz.plotlyplot(fig, env=visdom_env, win=visdom_win)