// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movl %edx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, %r14
leaq 0x1a8(%rsp), %r13
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r13, %rdi
callq 0x45d4c
leaq 0x58(%rsp), %rdi
callq 0x45d4a
leaq 0x190(%rsp), %r12
movsd 0x8a851(%rip), %xmm2    # 0xa8008
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r12, %rdi
callq 0x45d4c
leaq 0xa0(%rsp), %rdi
callq 0x45d4a
leaq 0xe8(%rsp), %rdi
movsd 0x8a846(%rip), %xmm0    # 0xa8028
xorps %xmm1, %xmm1
movsd 0x8a81b(%rip), %xmm2    # 0xa8008
callq 0x45d4c
leaq 0x88(%rsp), %rdi
callq 0x45d4a
leaq 0xd0(%rsp), %rdi
xorps %xmm0, %xmm0
movsd 0x8a816(%rip), %xmm1    # 0xa8028
movsd 0x8a7ee(%rip), %xmm2    # 0xa8008
callq 0x45d4c
leaq 0x70(%rsp), %rdi
callq 0x45d4a
leaq 0x100(%rsp), %rbx
movl $0xba2, %edi            # imm = 0xBA2
movq %rbx, %rsi
callq 0x11570
leaq 0x240(%rsp), %rbp
movl $0xba6, %edi            # imm = 0xBA6
movq %rbp, %rsi
callq 0x116b0
leaq 0x1c0(%rsp), %r15
movl $0xba7, %edi            # imm = 0xBA7
movq %r15, %rsi
callq 0x116b0
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
movsd 0x10(%r13), %xmm2
leaq 0x60(%rsp), %r8
leaq 0x68(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0x58(%rsp), %rcx
callq 0x11b50
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0xa8(%rsp), %r8
leaq 0xb0(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0xa0(%rsp), %r12
movq %r12, %rcx
callq 0x11b50
leaq 0xe8(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movsd 0x10(%rax), %xmm2
leaq 0x90(%rsp), %r8
leaq 0x98(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0x88(%rsp), %r13
movq %r13, %rcx
callq 0x11b50
leaq 0xd0(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movsd 0x10(%rax), %xmm2
leaq 0x78(%rsp), %r8
leaq 0x80(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0x70(%rsp), %r15
movq %r15, %rcx
callq 0x11b50
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x58(%rsp), %rdx
callq 0x45f29
movq %rbx, %rdi
callq 0x4680e
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x45f29
movq %rbx, %rdi
callq 0x4680e
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x45f29
movq %rbx, %rdi
callq 0x4680e
cmpl $0x2, 0xc(%rsp)
jne 0x1d9cf
movl $0xb57, %edi            # imm = 0xB57
callq 0x11550
movl $0x408, %edi            # imm = 0x408
movl $0x1602, %esi           # imm = 0x1602
callq 0x113b0
movl $0xb50, %edi            # imm = 0xB50
callq 0x11550
movq (%r14), %rax
movq %r14, %rdi
movl 0xc(%rsp), %esi
callq *0xf0(%rax)
pushq $0x7
popq %rdi
callq 0x11150
leaq 0x28(%rsp), %rdi
callq 0x45d4a
xorl %r12d, %r12d
leaq 0xda2fd(%rip), %rbp     # 0xf7cf8
leaq 0x160(%rsp), %r15
movq %r14, 0x18(%rsp)
movl 0x28(%r14), %eax
decl %eax
cmpl %eax, %r12d
jge 0x1dc3f
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %ebx, %ebx
movl %r12d, 0x14(%rsp)
movl 0x2c(%r14), %eax
decl %eax
cmpl %eax, %ebx
jge 0x1dc35
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x1fade
movapd %xmm0, %xmm2
movsd (%rbp), %xmm0
movapd %xmm0, %xmm1
xorpd 0x8a5f7(%rip), %xmm1    # 0xa8050
ucomisd %xmm1, %xmm2
jb 0x1da69
ucomisd %xmm2, %xmm0
jae 0x1dc2c
cvtsi2sd %ebx, %xmm1
movq %r15, %rdi
movsd 0x20(%rsp), %xmm0
movsd %xmm2, (%rsp)
callq 0x66640
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
movq %r14, %rdx
callq 0x15bef
movsd (%rsp), %xmm0
testl %eax, %eax
je 0x1dc2c
divsd 0x140(%r14), %xmm0
cmpl $0x1, 0xc(%rsp)
movsd %xmm0, (%rsp)
jne 0x1dacf
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movl %ebx, %ecx
callq 0x1c31e
movq %r15, %rdi
callq 0x1b8bb
movsd (%rsp), %xmm0
leaq 0x130(%rsp), %r12
movq %r12, %rdi
movq %r15, %r13
leaq 0xb8(%rsp), %r15
movq %r15, %rsi
callq 0x46c02
leaq 0x148(%rsp), %r14
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x4649d
leaq 0x118(%rsp), %rbp
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movsd (%rsp), %xmm0
callq 0x46c02
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x4649d
movq %r13, %rdi
callq 0x11170
movq %r12, %rdi
movq %r15, %rsi
movsd (%rsp), %xmm0
callq 0x46c02
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x46013
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movq %r13, %r15
movsd (%rsp), %xmm0
callq 0x46c02
movq %r13, %rdi
movq %r14, %rsi
movq %r14, %r13
movq %rbp, %rdx
callq 0x4649d
movq %r15, %rdi
callq 0x11170
movq %r12, %rdi
leaq 0xb8(%rsp), %r14
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x46c02
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x46013
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movsd (%rsp), %xmm0
callq 0x46c02
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x46013
movq %r15, %rdi
callq 0x11170
movq %r12, %rdi
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x46c02
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
movl 0x14(%rsp), %r12d
callq 0x4649d
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movsd (%rsp), %xmm0
callq 0x46c02
movq %r15, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %r14
movq %rbp, %rdx
callq 0x46013
movq %r15, %rdi
callq 0x11170
leaq 0xda0cc(%rip), %rbp     # 0xf7cf8
addl 0x10(%rsp), %ebx
jmp 0x1da29
addl 0x10(%rsp), %r12d
jmp 0x1da08
callq 0x117d0
cmpl $0x2, 0xc(%rsp)
jne 0x1dc5f
movl $0xb57, %edi            # imm = 0xB57
callq 0x111a0
movl $0xb50, %edi            # imm = 0xB50
callq 0x111a0
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop