MCPcopy
hub / github.com/NVlabs/imaginaire / __init__

Method __init__

imaginaire/model_utils/gancraft/camctl.py:296–384  ·  view source on GitHub ↗
(self, voxel, maxstep=128)

Source from the content-addressed store, hash-verified

294
295class TourCameraController:
296 def __init__(self, voxel, maxstep=128):
297 self.voxel = voxel
298 self.maxstep = maxstep
299 self.camera_poses = [] # ori, dir, up, f
300 circle = torch.linspace(0, 2*np.pi, steps=maxstep//4)
301 size = min(voxel.voxel_t.size(1), voxel.voxel_t.size(2)) / 2
302 # Shrink the circle a bit
303 shift = size * 0.2
304 size = size * 0.8
305
306 for i in range(maxstep//4):
307 farpoint = torch.tensor([
308 70,
309 torch.sin(circle[i])*size + voxel.voxel_t.size(1)/2 + shift,
310 torch.cos(circle[i])*size + voxel.voxel_t.size(2)/2 + shift])
311
312 farpoint[0] = self._get_height(farpoint[1], farpoint[2], farpoint[0])
313
314 nearpoint = torch.tensor([
315 60,
316 torch.sin(circle[i]+0.5*np.pi)*size*0.5 + voxel.voxel_t.size(1)/2 + shift,
317 torch.cos(circle[i]+0.5*np.pi)*size*0.5 + voxel.voxel_t.size(2)/2 + shift])
318 cam_ori = self.voxel.world2local(farpoint)
319 cam_dir = self.voxel.world2local(nearpoint - farpoint, is_vec=True)
320 cam_up = self.voxel.world2local(torch.tensor([1, 0, 0], dtype=torch.float32), is_vec=True)
321 cam_f = 0.5/np.tan(np.deg2rad(73/2)) # about 24mm fov
322
323 self.camera_poses.append((cam_ori, cam_dir, cam_up, cam_f))
324
325 zoom = torch.linspace(1.0, 0.25, steps=maxstep//4)
326 for i in range(maxstep//4):
327 farpoint = torch.tensor([
328 90,
329 torch.sin(circle[i])*size + voxel.voxel_t.size(1)/2 + shift,
330 torch.cos(circle[i])*size + voxel.voxel_t.size(2)/2 + shift])
331
332 farpoint[0] = self._get_height(farpoint[1], farpoint[2], farpoint[0])
333
334 nearpoint = torch.tensor([
335 60,
336 torch.sin(circle[i]-0.3*np.pi)*size*0.3 + voxel.voxel_t.size(1)/2 + shift,
337 torch.cos(circle[i]-0.3*np.pi)*size*0.3 + voxel.voxel_t.size(2)/2 + shift])
338 cam_ori = self.voxel.world2local(farpoint)
339 cam_dir = self.voxel.world2local(nearpoint - farpoint, is_vec=True)
340 cam_up = self.voxel.world2local(torch.tensor([1, 0, 0], dtype=torch.float32), is_vec=True)
341 cam_f = 0.5/np.tan(np.deg2rad(73/2)*zoom[i]) # about 24mm fov
342
343 self.camera_poses.append((cam_ori, cam_dir, cam_up, cam_f))
344
345 move = torch.linspace(1.0, 0.2, steps=maxstep//4)
346 for i in range(maxstep//4):
347 farpoint = torch.tensor([
348 90,
349 torch.sin(circle[i])*size*move[i] + voxel.voxel_t.size(1)/2 + shift,
350 torch.cos(circle[i])*size*move[i] + voxel.voxel_t.size(2)/2 + shift])
351
352 farpoint[0] = self._get_height(farpoint[1], farpoint[2], farpoint[0])
353

Callers

nothing calls this directly

Calls 2

_get_heightMethod · 0.95
world2localMethod · 0.80

Tested by

no test coverage detected