// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDImage.cpp
// Function: gaps::RGBDImage::DrawSurfels(int, int) const
void RGBDImage::
DrawSurfels(int color_scheme, int skip) const
{
  // Get info about current view
  GLint viewport[4];
  GLdouble modelview_matrix[16];
  GLdouble projection_matrix[16];
  R3Point c0(0, 0, 0), w0;
  R3Point c1(0, 0, -1), w1;
  R3Point c2(1, 0, -1), w2;
  R3Point c3(0, 1, -1), w3;
  glGetIntegerv(GL_VIEWPORT, viewport);
  glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
  glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
  gluUnProject(c0[0], c0[1], c0[2], modelview_matrix, projection_matrix, viewport, &(w0[0]), &(w0[1]), &(w0[2]));
  gluUnProject(c1[0], c1[1], c1[2], modelview_matrix, projection_matrix, viewport, &(w1[0]), &(w1[1]), &(w1[2]));
  gluUnProject(c2[0], c2[1], c2[2], modelview_matrix, projection_matrix, viewport, &(w2[0]), &(w2[1]), &(w2[2]));
  gluUnProject(c3[0], c3[1], c3[2], modelview_matrix, projection_matrix, viewport, &(w3[0]), &(w3[1]), &(w3[2]));
  R3Vector view_towards = w1 - w0; view_towards.Normalize();
  R3Vector view_right = w2 - w1; view_right.Normalize();
  R3Vector view_up = w3 - w1; view_up.Normalize();

  // Enable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glEnable(GL_LIGHTING);
  }

  // Draw color
  LoadColor(color_scheme);

  // Draw little quads
  RNGrfxBegin(RN_GRFX_QUADS);
  R3Point world_position;
  for (int ix = 0; ix < NPixels(RN_X)-1; ix += skip) {
    for (int iy = 0; iy < NPixels(RN_Y)-1; iy += skip) {
      RNScalar depth = PixelDepth(ix, iy);
      if (RNIsZero(depth)) continue;
      if (!RGBDTransformImageToWorld(R2Point(ix, iy), world_position, this)) continue;
      RNScalar r = depth / Intrinsics()[0][0];
      if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix, iy));
      R3LoadPoint(world_position - r*view_right - r*view_up);
      R3LoadPoint(world_position + r*view_right - r*view_up);
      R3LoadPoint(world_position + r*view_right + r*view_up);
      R3LoadPoint(world_position - r*view_right + r*view_up);
    }
  }
  RNGrfxEnd();
  
  // Disable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_LIGHTING);
  }
}

// Assembly:
subq $0x528, %rsp            # imm = 0x528
movq %rdi, 0x520(%rsp)
movl %esi, 0x51c(%rsp)
movl %edx, 0x518(%rsp)
movq 0x520(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x3e8(%rsp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x8a9a0
leaq 0x3d0(%rsp), %rdi
callq 0x8a990
leaq 0x3b8(%rsp), %rdi
xorps %xmm1, %xmm1
movsd 0x13a658(%rip), %xmm2   # 0x166018
movaps %xmm1, %xmm0
callq 0x8a9a0
leaq 0x3a0(%rsp), %rdi
callq 0x8a990
leaq 0x388(%rsp), %rdi
movsd 0x13a64b(%rip), %xmm0   # 0x166030
xorps %xmm1, %xmm1
movsd 0x13a628(%rip), %xmm2   # 0x166018
callq 0x8a9a0
leaq 0x370(%rsp), %rdi
callq 0x8a990
leaq 0x358(%rsp), %rdi
xorps %xmm0, %xmm0
movsd 0x13a61b(%rip), %xmm1   # 0x166030
movsd 0x13a5fb(%rip), %xmm2   # 0x166018
callq 0x8a9a0
leaq 0x340(%rsp), %rdi
callq 0x8a990
leaq 0x500(%rsp), %rsi
movl $0xba2, %edi            # imm = 0xBA2
callq 0x12680
leaq 0x480(%rsp), %rsi
movl $0xba6, %edi            # imm = 0xBA6
callq 0x12800
leaq 0x400(%rsp), %rsi
movl $0xba7, %edi            # imm = 0xBA7
callq 0x12800
leaq 0x3e8(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x3e8(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x3e8(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x480(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x400(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x500(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x3d0(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x50(%rsp)
leaq 0x3d0(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x58(%rsp)
leaq 0x3d0(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq %rax, %r9
callq 0x12d20
leaq 0x3b8(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x3b8(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x3b8(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x480(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x400(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x500(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x3a0(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x90(%rsp)
leaq 0x3a0(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x98(%rsp)
leaq 0x3a0(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd 0x60(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
movsd 0x70(%rsp), %xmm2
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
movq %rax, %r9
callq 0x12d20
leaq 0x388(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
leaq 0x388(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0x388(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0xb0(%rsp)
leaq 0x480(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0x400(%rsp), %rax
movq %rax, 0xc0(%rsp)
leaq 0x500(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x370(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0xd0(%rsp)
leaq 0x370(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0xd8(%rsp)
leaq 0x370(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd 0xa0(%rsp), %xmm0
movsd 0xa8(%rsp), %xmm1
movsd 0xb0(%rsp), %xmm2
movq 0xb8(%rsp), %rdi
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0xd0(%rsp), %rcx
movq 0xd8(%rsp), %r8
movq %rax, %r9
callq 0x12d20
leaq 0x358(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
leaq 0x358(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0xe8(%rsp)
leaq 0x358(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0xf0(%rsp)
leaq 0x480(%rsp), %rax
movq %rax, 0xf8(%rsp)
leaq 0x400(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x500(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x340(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x110(%rsp)
leaq 0x340(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x118(%rsp)
leaq 0x340(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd 0xe0(%rsp), %xmm0
movsd 0xe8(%rsp), %xmm1
movsd 0xf0(%rsp), %xmm2
movq 0xf8(%rsp), %rdi
movq 0x100(%rsp), %rsi
movq 0x108(%rsp), %rdx
movq 0x110(%rsp), %rcx
movq 0x118(%rsp), %r8
movq %rax, %r9
callq 0x12d20
leaq 0x328(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
leaq 0x3d0(%rsp), %rdx
callq 0x8ad00
leaq 0x328(%rsp), %rdi
callq 0x8c260
leaq 0x310(%rsp), %rdi
leaq 0x370(%rsp), %rsi
leaq 0x3a0(%rsp), %rdx
callq 0x8ad00
leaq 0x310(%rsp), %rdi
callq 0x8c260
leaq 0x2f8(%rsp), %rdi
leaq 0x340(%rsp), %rsi
leaq 0x3a0(%rsp), %rdx
callq 0x8ad00
leaq 0x2f8(%rsp), %rdi
callq 0x8c260
cmpl $0x2, 0x51c(%rsp)
jne 0x2bf28
movl $0xb57, %edi            # imm = 0xB57
callq 0x12640
movl $0x408, %edi            # imm = 0x408
movl $0x1602, %esi           # imm = 0x1602
callq 0x12460
movl $0xb50, %edi            # imm = 0xB50
callq 0x12640
movq 0x18(%rsp), %rdi
movl 0x51c(%rsp), %esi
movq (%rdi), %rax
callq *0xf0(%rax)
movl $0x7, %edi
callq 0x27c00
leaq 0x2e0(%rsp), %rdi
callq 0x8a990
movl $0x0, 0x2dc(%rsp)
movq 0x18(%rsp), %rdi
movl 0x2dc(%rsp), %eax
movl %eax, 0x14(%rsp)
xorl %esi, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x14(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2c2fc
movl $0x0, 0x2d8(%rsp)
movq 0x18(%rsp), %rdi
movl 0x2d8(%rsp), %eax
movl %eax, 0x10(%rsp)
movl $0x1, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x10(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2c2e0
movq 0x18(%rsp), %rdi
movl 0x2dc(%rsp), %esi
movl 0x2d8(%rsp), %edx
callq 0x30570
movsd %xmm0, 0x2d0(%rsp)
movsd 0x2d0(%rsp), %xmm0
leaq 0x185ed2(%rip), %rax    # 0x1b1ec0
movsd (%rax), %xmm1
callq 0x1a370
cmpl $0x0, %eax
je 0x2c001
jmp 0x2c2c6
cvtsi2sdl 0x2dc(%rsp), %xmm0
cvtsi2sdl 0x2d8(%rsp), %xmm1
leaq 0x2c0(%rsp), %rdi
callq 0xcfd80
movq 0x18(%rsp), %rdx
leaq 0x2c0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x1ae00
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c048
jmp 0x2c04d
jmp 0x2c2c6
movq 0x18(%rsp), %rdi
movsd 0x2d0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x226a0
movq %rax, %rdi
xorl %esi, %esi
callq 0x238a0
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
movsd %xmm0, 0x2b8(%rsp)
cmpl $0x1, 0x51c(%rsp)
jne 0x2c0ba
movq 0x18(%rsp), %rsi
movl 0x2dc(%rsp), %edx
movl 0x2d8(%rsp), %ecx
leaq 0x2a0(%rsp), %rdi
callq 0x29420
leaq 0x2a0(%rsp), %rdi
callq 0x27c20
movsd 0x2b8(%rsp), %xmm0
leaq 0x258(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x227f0
leaq 0x270(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0x258(%rsp), %rdx
callq 0x8b900
movsd 0x2b8(%rsp), %xmm0
leaq 0x240(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x227f0
leaq 0x288(%rsp), %rdi
leaq 0x270(%rsp), %rsi
leaq 0x240(%rsp), %rdx
callq 0x8b900
leaq 0x288(%rsp), %rdi
callq 0x27c90
movsd 0x2b8(%rsp), %xmm0
leaq 0x1f8(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x227f0
leaq 0x210(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0x1f8(%rsp), %rdx
callq 0x8af60
movsd 0x2b8(%rsp), %xmm0
leaq 0x1e0(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x227f0
leaq 0x228(%rsp), %rdi
leaq 0x210(%rsp), %rsi
leaq 0x1e0(%rsp), %rdx
callq 0x8b900
leaq 0x228(%rsp), %rdi
callq 0x27c90
movsd 0x2b8(%rsp), %xmm0
leaq 0x198(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x227f0
leaq 0x1b0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0x198(%rsp), %rdx
callq 0x8af60
movsd 0x2b8(%rsp), %xmm0
leaq 0x180(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x227f0
leaq 0x1c8(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
leaq 0x180(%rsp), %rdx
callq 0x8af60
leaq 0x1c8(%rsp), %rdi
callq 0x27c90
movsd 0x2b8(%rsp), %xmm0
leaq 0x138(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x227f0
leaq 0x150(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
leaq 0x138(%rsp), %rdx
callq 0x8b900
movsd 0x2b8(%rsp), %xmm0
leaq 0x120(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x227f0
leaq 0x168(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x8af60
leaq 0x168(%rsp), %rdi
callq 0x27c90
movl 0x518(%rsp), %eax
addl 0x2d8(%rsp), %eax
movl %eax, 0x2d8(%rsp)
jmp 0x2bf92
jmp 0x2c2e2
movl 0x518(%rsp), %eax
addl 0x2dc(%rsp), %eax
movl %eax, 0x2dc(%rsp)
jmp 0x2bf5f
callq 0x27cd0
cmpl $0x2, 0x51c(%rsp)
jne 0x2c31f
movl $0xb57, %edi            # imm = 0xB57
callq 0x121c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x121c0
addq $0x528, %rsp            # imm = 0x528
retq
nopw (%rax,%rax)