// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movq %rdi, %r14
leaq 0x1a8(%rsp), %r13
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r13, %rdi
callq 0x4b602
leaq 0x60(%rsp), %rdi
callq 0x4b600
leaq 0x190(%rsp), %r12
movsd 0x9c1d1(%rip), %xmm2    # 0xbb038
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r12, %rdi
callq 0x4b602
leaq 0xd8(%rsp), %rdi
callq 0x4b600
leaq 0x108(%rsp), %rdi
movsd 0x9c196(%rip), %xmm0    # 0xbb028
xorps %xmm1, %xmm1
movsd 0x9c19b(%rip), %xmm2    # 0xbb038
callq 0x4b602
leaq 0xc0(%rsp), %rdi
callq 0x4b600
leaq 0xf0(%rsp), %rdi
xorps %xmm0, %xmm0
movsd 0x9c166(%rip), %xmm1    # 0xbb028
movsd 0x9c16e(%rip), %xmm2    # 0xbb038
callq 0x4b602
leaq 0xa8(%rsp), %rdi
callq 0x4b600
leaq 0x120(%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 0x116a0
leaq 0x1c0(%rsp), %r15
movl $0xba7, %edi            # imm = 0xBA7
movq %r15, %rsi
callq 0x116a0
movsd (%r13), %xmm0
movsd 0x8(%r13), %xmm1
movsd 0x10(%r13), %xmm2
leaq 0x68(%rsp), %r8
leaq 0x70(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0x60(%rsp), %rcx
callq 0x11b30
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0xe0(%rsp), %r8
leaq 0xe8(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0xd8(%rsp), %r12
movq %r12, %rcx
callq 0x11b30
leaq 0x108(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movsd 0x10(%rax), %xmm2
leaq 0xc8(%rsp), %r8
leaq 0xd0(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0xc0(%rsp), %r13
movq %r13, %rcx
callq 0x11b30
leaq 0xf0(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movsd 0x10(%rax), %xmm2
leaq 0xb0(%rsp), %r8
leaq 0xb8(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0xa8(%rsp), %r15
movq %r15, %rcx
callq 0x11b30
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x60(%rsp), %rdx
callq 0x4b85e
movq %rbx, %rdi
callq 0x4c3ac
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4b85e
movq %rbx, %rdi
callq 0x4c3ac
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4b85e
movq %rbx, %rdi
callq 0x4c3ac
cmpl $0x2, 0x14(%rsp)
jne 0x1f088
movl $0xb57, %edi            # imm = 0xB57
callq 0x11540
movl $0x408, %edi            # imm = 0x408
movl $0x1602, %esi           # imm = 0x1602
callq 0x113b0
movl $0xb50, %edi            # imm = 0xB50
callq 0x11540
movq (%r14), %rax
movq %r14, %rdi
movl 0x14(%rsp), %esi
callq *0xf0(%rax)
movl $0x7, %edi
callq 0x11150
leaq 0x30(%rsp), %rdi
callq 0x4b600
movl 0x28(%r14), %ecx
cmpl $0x2, %ecx
jl 0x1f35e
movl 0x2c(%r14), %eax
leaq 0x78(%rsp), %rbx
xorl %ebp, %ebp
movq %r14, 0x20(%rsp)
cmpl $0x2, %eax
jl 0x1f34f
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r12d, %r12d
movl %ebp, 0x1c(%rsp)
xorpd %xmm2, %xmm2
cmpl $0x4, 0x24(%r14)
jl 0x1f130
movq 0x18(%r14), %rax
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1f11a
movq 0xb8(%rax), %rcx
movl 0xc8(%rax), %eax
imull %r12d, %eax
addl %ebp, %eax
cltq
movsd (%rcx,%rax,8), %xmm2
jmp 0x1f130
leaq 0x9cded(%rip), %rdi     # 0xbbf0e
xorl %eax, %eax
callq 0x77f42
movsd 0x9bee8(%rip), %xmm2    # 0xbb018
leaq 0xe5ba1(%rip), %rax     # 0x104cd8
movsd (%rax), %xmm0
movapd %xmm0, %xmm1
xorpd 0x9bf09(%rip), %xmm1    # 0xbb050
ucomisd %xmm1, %xmm2
jb 0x1f157
ucomisd %xmm2, %xmm0
jae 0x1f336
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
movsd %xmm2, 0x8(%rsp)
callq 0x6f0d6
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x16377
movsd 0x8(%rsp), %xmm0
testl %eax, %eax
je 0x1f336
divsd 0x140(%r14), %xmm0
cmpl $0x1, 0x14(%rsp)
movsd %xmm0, 0x8(%rsp)
jne 0x1f1da
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x1d72e
movsd 0x78(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x88(%rsp), %xmm2
callq 0x118f0
movsd 0x8(%rsp), %xmm0
leaq 0x148(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %r14
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x4ca32
leaq 0x160(%rsp), %r15
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
callq 0x4c023
leaq 0x130(%rsp), %r13
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4c023
movq %r14, %rdi
callq 0x11170
movq %rbp, %rdi
movq %rbx, %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %r15, %rdi
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x4b947
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4c023
movq %r14, %rdi
callq 0x11170
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x4b947
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4b947
movq %r14, %rdi
callq 0x11170
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
movq %r14, %rbx
movq 0x20(%rsp), %r14
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
movl 0x1c(%rsp), %ebp
callq 0x4c023
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4ca32
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4b947
movq %rbx, %rdi
callq 0x11170
addl 0x18(%rsp), %r12d
movl 0x2c(%r14), %eax
leal -0x1(%rax), %ecx
cmpl %ecx, %r12d
jl 0x1f0e6
movl 0x28(%r14), %ecx
addl 0x18(%rsp), %ebp
leal -0x1(%rcx), %edx
cmpl %edx, %ebp
jl 0x1f0c9
callq 0x117c0
cmpl $0x2, 0x14(%rsp)
jne 0x1f37e
movl $0xb57, %edi            # imm = 0xB57
callq 0x11180
movl $0xb50, %edi            # imm = 0xB50
callq 0x11180
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq