// File: /workspace/github_cpp_makefile_star2_O1/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 0x4be46
leaq 0x60(%rsp), %rdi
callq 0x4be44
leaq 0x190(%rsp), %r12
movsd 0x9df2b(%rip), %xmm2    # 0xbd038
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r12, %rdi
callq 0x4be46
leaq 0xd8(%rsp), %rdi
callq 0x4be44
leaq 0x108(%rsp), %rdi
movsd 0x9def0(%rip), %xmm0    # 0xbd028
xorps %xmm1, %xmm1
movsd 0x9def5(%rip), %xmm2    # 0xbd038
callq 0x4be46
leaq 0xc0(%rsp), %rdi
callq 0x4be44
leaq 0xf0(%rsp), %rdi
xorps %xmm0, %xmm0
movsd 0x9dec0(%rip), %xmm1    # 0xbd028
movsd 0x9dec8(%rip), %xmm2    # 0xbd038
callq 0x4be46
leaq 0xa8(%rsp), %rdi
callq 0x4be44
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 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 0x68(%rsp), %r8
leaq 0x70(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
leaq 0x60(%rsp), %rcx
callq 0x11b40
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 0x11b40
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 0x11b40
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 0x11b40
leaq 0x178(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x60(%rsp), %rdx
callq 0x4c0a8
movq %rbx, %rdi
callq 0x4cc00
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4c0a8
movq %rbx, %rdi
callq 0x4cc00
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x4c0a8
movq %rbx, %rdi
callq 0x4cc00
cmpl $0x2, 0x14(%rsp)
jne 0x1f32e
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 0x4be44
cmpl $0x2, 0x28(%r14)
jl 0x1f5fe
leaq 0x78(%rsp), %rbx
xorl %ebp, %ebp
movq %r14, 0x20(%rsp)
cmpl $0x2, 0x2c(%r14)
jl 0x1f5ec
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 0x1f3d2
movq 0x18(%r14), %rax
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x1f3bc
movq 0xb8(%rax), %rcx
movl 0xc8(%rax), %eax
imull %r12d, %eax
addl %ebp, %eax
cltq
movsd (%rcx,%rax,8), %xmm2
jmp 0x1f3d2
leaq 0x9eb4b(%rip), %rdi     # 0xbdf0e
xorl %eax, %eax
callq 0x79092
movsd 0x9dc46(%rip), %xmm2    # 0xbd018
leaq 0xe790f(%rip), %rax     # 0x106ce8
movsd (%rax), %xmm0
movapd %xmm0, %xmm1
xorpd 0x9dc67(%rip), %xmm1    # 0xbd050
ucomisd %xmm1, %xmm2
jb 0x1f3f9
ucomisd %xmm2, %xmm0
jae 0x1f5d8
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
movsd %xmm2, 0x8(%rsp)
callq 0x6fee6
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x16443
movsd 0x8(%rsp), %xmm0
testl %eax, %eax
je 0x1f5d8
divsd 0x140(%r14), %xmm0
cmpl $0x1, 0x14(%rsp)
movsd %xmm0, 0x8(%rsp)
jne 0x1f47c
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x1d9d8
movsd 0x78(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x88(%rsp), %xmm2
callq 0x11900
movsd 0x8(%rsp), %xmm0
leaq 0x148(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %r14
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x4d2ae
leaq 0x160(%rsp), %r15
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
callq 0x4c86d
leaq 0x130(%rsp), %r13
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4c86d
movq %r14, %rdi
callq 0x11170
movq %rbp, %rdi
movq %rbx, %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %r15, %rdi
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x4c191
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4c86d
movq %r14, %rdi
callq 0x11170
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x4c191
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4c191
movq %r14, %rdi
callq 0x11170
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
movq %r14, %rbx
movq 0x20(%rsp), %r14
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
movl 0x1c(%rsp), %ebp
callq 0x4c86d
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
movsd 0x8(%rsp), %xmm0
callq 0x4d2ae
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4c191
movq %rbx, %rdi
callq 0x11170
addl 0x18(%rsp), %r12d
movl 0x2c(%r14), %eax
decl %eax
cmpl %eax, %r12d
jl 0x1f388
addl 0x18(%rsp), %ebp
movl 0x28(%r14), %eax
decl %eax
cmpl %eax, %ebp
jl 0x1f369
callq 0x117d0
cmpl $0x2, 0x14(%rsp)
jne 0x1f61e
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