// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::SetScene(gaps::R3SurfelScene*)
void R3SurfelViewer::
SetScene(R3SurfelScene *scene)
{
  // Remember scene
  this->scene = scene;

  // Set center point
  center_point = scene->Centroid();
  // center_point[1] = scene->BBox().YMin();

  // Set focus radius
  focus_radius = 400;
  if (focus_radius > scene->BBox().DiagonalRadius()) {
    focus_radius = scene->BBox().DiagonalRadius();
  }

  // Set camera and viewport
  R3Box bbox = scene->BBox();
  RNLength r = bbox.DiagonalRadius();
  static const R3Vector up(0, 1, 0);
  static const R3Vector towards(0, 0, -1);
  R3Point eye = scene->Centroid() - towards * (2 * r); 
  R3Camera camera(eye, towards, up, 0.4, 0.4, 0.01, 100000.0);
  R2Viewport viewport(0, 0, window_width, window_height);
  viewer.SetViewport(viewport);
  viewer.SetCamera(camera);

  // Lock coarsest blocks in memory (~500MB)
  // ReadCoarsestBlocks(1 * 1024 * 1024);

  // Update ground z grid
  // UpdateGroundZGrid();

  // Update working set
  UpdateWorkingSet();
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x178(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x178(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x3e990
movq 0x18(%rsp), %rdi
addq $0x2b0, %rdi            # imm = 0x2B0
leaq 0x160(%rsp), %rsi
callq 0x162950
movq 0x18(%rsp), %rax
movsd 0x208bd5(%rip), %xmm0   # 0x241530
movsd %xmm0, 0x478(%rax)
movsd 0x478(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x178(%rsp), %rdi
callq 0x3d7d0
movq %rax, %rdi
callq 0x3e0a0
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x389b7
movq 0x178(%rsp), %rdi
callq 0x3d7d0
movq %rax, %rdi
callq 0x3e0a0
movq 0x18(%rsp), %rax
movsd %xmm0, 0x478(%rax)
movq 0x178(%rsp), %rdi
callq 0x3d7d0
movq %rax, %rsi
leaq 0x128(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x133e40
movq 0x8(%rsp), %rdi
callq 0x3e0a0
movsd %xmm0, 0x10(%rsp)
jmp 0x389eb
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
cmpb $0x0, 0x299b3f(%rip)    # 0x2d2540
jne 0x38a3c
leaq 0x299b36(%rip), %rdi    # 0x2d2540
callq 0x29360
cmpl $0x0, %eax
je 0x38a3c
leaq 0x299b0d(%rip), %rdi    # 0x2d2528
movsd 0x2085ed(%rip), %xmm1   # 0x241010
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
callq 0x163420
jmp 0x38a30
leaq 0x299b09(%rip), %rdi    # 0x2d2540
callq 0x286a0
cmpb $0x0, 0x299b1d(%rip)    # 0x2d2560
jne 0x38a7e
leaq 0x299b14(%rip), %rdi    # 0x2d2560
callq 0x29360
cmpl $0x0, %eax
je 0x38a7e
leaq 0x299aeb(%rip), %rdi    # 0x2d2548
xorps %xmm1, %xmm1
movsd 0x2085a0(%rip), %xmm2   # 0x241008
movaps %xmm1, %xmm0
callq 0x163420
jmp 0x38a72
leaq 0x299ae7(%rip), %rdi    # 0x2d2560
callq 0x286a0
movq 0x178(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x3e990
jmp 0x38a95
movsd 0x120(%rsp), %xmm0
addsd %xmm0, %xmm0
leaq 0x299a9f(%rip), %rsi    # 0x2d2548
leaq 0xc8(%rsp), %rdi
callq 0x1642f0
jmp 0x38ab8
leaq 0xf8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x163220
jmp 0x38ad7
leaq 0x299a6a(%rip), %rdx    # 0x2d2548
leaq 0x299a43(%rip), %rcx    # 0x2d2528
leaq 0x38(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
movsd 0x208526(%rip), %xmm1   # 0x241020
movsd 0x208526(%rip), %xmm2   # 0x241028
movsd 0x208526(%rip), %xmm3   # 0x241030
movaps %xmm1, %xmm0
callq 0xd09a0
jmp 0x38b14
movq 0x18(%rsp), %rax
movl 0x494(%rax), %r8d
movl 0x498(%rax), %ecx
leaq 0x28(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xd1eb0
jmp 0x38b36
movq 0x18(%rsp), %rdi
addq $0x78, %rdi
leaq 0x28(%rsp), %rsi
callq 0xcd5f0
jmp 0x38b4b
movq 0x18(%rsp), %rdi
addq $0x78, %rdi
leaq 0x38(%rsp), %rsi
callq 0xcd540
jmp 0x38b60
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
movq 0x310(%rax), %rax
callq *%rax
jmp 0x38b73
leaq 0x128(%rsp), %rdi
callq 0x3d220
addq $0x188, %rsp            # imm = 0x188
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
jmp 0x38be0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x299987(%rip), %rdi    # 0x2d2540
callq 0x28680
jmp 0x38be0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x118(%rsp)
movl %eax, 0x114(%rsp)
leaq 0x299985(%rip), %rdi    # 0x2d2560
callq 0x28680
leaq 0x128(%rsp), %rdi
callq 0x3d220
movq 0x118(%rsp), %rdi
callq 0x292e0
nopw (%rax,%rax)