// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDImage.cpp
// Function: gaps::RGBDImage::DrawPoints(int, int) const
void RGBDImage::
DrawPoints(int color_scheme, int skip) const
{
  // Push transformation
  CameraToWorld().Push();

  // 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);

  // Set point size
  glPointSize(2);

  // Draw points
  if (color_scheme != RGBD_RENDER_COLOR_SCHEME) {
    RNGrfxBegin(RN_GRFX_POINTS);
    R3Point world_position;
    for (int ix = 0; ix < NPixels(RN_X); ix += skip) {
      for (int iy = 0; iy < NPixels(RN_Y); iy += skip) {
        if (RGBDTransformImageToCamera(R2Point(ix+0.5, iy+0.5), world_position, this)) {
          if (color_scheme == RGBD_PHOTO_COLOR_SCHEME) RNLoadRgb(PixelColor(ix, iy));
          R3LoadPoint(world_position);
        }
      }
    }
    RNGrfxEnd();
  }
  else {
    RNGrfxBegin(RN_GRFX_POINTS);
    R3Point world_position, p1, p2;
    for (int ix = 0; ix < NPixels(RN_X); ix += skip) {
      for (int iy = 0; iy < NPixels(RN_Y); iy += skip) {
        if (!RGBDTransformImageToCamera(R2Point(ix+0.5, iy+0.5), world_position, this)) continue;
        if (!RGBDTransformImageToCamera(R2Point(ix+1, iy), p1, this)) continue;
        if (!RGBDTransformImageToCamera(R2Point(ix, iy+1), p2, this)) continue;
        R3Plane plane(world_position, p1, p2);
        R3LoadNormal(plane.Normal());
        R3LoadPoint(world_position);
      }
    }
    RNGrfxEnd();
  }

  // Reset point size
  glPointSize(1);
  
  // Disable lighting and material
  if (color_scheme == RGBD_RENDER_COLOR_SCHEME) {
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_LIGHTING);
  }

  // Pop transformation
  CameraToWorld().Pop();
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movl %esi, 0x10c(%rsp)
movl %edx, 0x108(%rsp)
movq 0x110(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x22710
movq %rax, %rdi
movq (%rdi), %rax
callq *0xb0(%rax)
cmpl $0x2, 0x10c(%rsp)
jne 0x2b5c8
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 0x10c(%rsp), %esi
movq (%rdi), %rax
callq *0xf0(%rax)
movss 0x13ba63(%rip), %xmm0   # 0x167048
callq 0x120a0
cmpl $0x2, 0x10c(%rsp)
je 0x2b74b
xorl %edi, %edi
callq 0x27c00
leaq 0xf0(%rsp), %rdi
callq 0x8a990
movl $0x0, 0xec(%rsp)
movq 0x18(%rsp), %rdi
movl 0xec(%rsp), %eax
movl %eax, 0x14(%rsp)
xorl %esi, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x2b741
movl $0x0, 0xe8(%rsp)
movq 0x18(%rsp), %rdi
movl 0xe8(%rsp), %eax
movl %eax, 0x10(%rsp)
movl $0x1, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jge 0x2b725
cvtsi2sdl 0xec(%rsp), %xmm0
movsd 0x13a9a8(%rip), %xmm1   # 0x166028
addsd %xmm1, %xmm0
cvtsi2sdl 0xe8(%rsp), %xmm1
movsd 0x13a993(%rip), %xmm2   # 0x166028
addsd %xmm2, %xmm1
leaq 0xd8(%rsp), %rdi
callq 0xcfd80
movq 0x18(%rsp), %rdx
leaq 0xd8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
je 0x2b709
cmpl $0x1, 0x10c(%rsp)
jne 0x2b6fc
movq 0x18(%rsp), %rsi
movl 0xec(%rsp), %edx
movl 0xe8(%rsp), %ecx
leaq 0xc0(%rsp), %rdi
callq 0x29420
leaq 0xc0(%rsp), %rdi
callq 0x27c20
leaq 0xf0(%rsp), %rdi
callq 0x27c90
jmp 0x2b70b
movl 0x108(%rsp), %eax
addl 0xe8(%rsp), %eax
movl %eax, 0xe8(%rsp)
jmp 0x2b647
jmp 0x2b727
movl 0x108(%rsp), %eax
addl 0xec(%rsp), %eax
movl %eax, 0xec(%rsp)
jmp 0x2b617
callq 0x27cd0
jmp 0x2b913
xorl %edi, %edi
callq 0x27c00
leaq 0xa8(%rsp), %rdi
callq 0x8a990
leaq 0x90(%rsp), %rdi
callq 0x8a990
leaq 0x78(%rsp), %rdi
callq 0x8a990
movl $0x0, 0x74(%rsp)
movq 0x18(%rsp), %rdi
movl 0x74(%rsp), %eax
movl %eax, 0xc(%rsp)
xorl %esi, %esi
callq 0x1af30
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x2b90e
movl $0x0, 0x70(%rsp)
movq 0x18(%rsp), %rdi
movl 0x70(%rsp), %eax
movl %eax, 0x8(%rsp)
movl $0x1, %esi
callq 0x1af30
movl %eax, %ecx
movl 0x8(%rsp), %eax
cmpl %ecx, %eax
jge 0x2b8f8
cvtsi2sdl 0x74(%rsp), %xmm0
movsd 0x13a84d(%rip), %xmm1   # 0x166028
addsd %xmm1, %xmm0
cvtsi2sdl 0x70(%rsp), %xmm1
movsd 0x13a83b(%rip), %xmm2   # 0x166028
addsd %xmm2, %xmm1
leaq 0x60(%rsp), %rdi
callq 0xcfd80
movq 0x18(%rsp), %rdx
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b820
jmp 0x2b825
jmp 0x2b8e4
movl 0x74(%rsp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x70(%rsp), %xmm1
leaq 0x50(%rsp), %rdi
callq 0xcfd80
movq 0x18(%rsp), %rdx
leaq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b865
jmp 0x2b867
jmp 0x2b8e4
cvtsi2sdl 0x74(%rsp), %xmm0
movl 0x70(%rsp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
leaq 0x40(%rsp), %rdi
callq 0xcfd80
movq 0x18(%rsp), %rdx
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1aef0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b8a4
jmp 0x2b8a6
jmp 0x2b8e4
leaq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0x88490
leaq 0x20(%rsp), %rdi
callq 0x28110
movq %rax, %rdi
callq 0x27cb0
leaq 0xa8(%rsp), %rdi
callq 0x27c90
movl 0x108(%rsp), %eax
addl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp)
jmp 0x2b7a8
jmp 0x2b8fa
movl 0x108(%rsp), %eax
addl 0x74(%rsp), %eax
movl %eax, 0x74(%rsp)
jmp 0x2b77e
callq 0x27cd0
movss 0x13b731(%rip), %xmm0   # 0x16704c
callq 0x120a0
cmpl $0x2, 0x10c(%rsp)
jne 0x2b93e
movl $0xb57, %edi            # imm = 0xB57
callq 0x121c0
movl $0xb50, %edi            # imm = 0xB50
callq 0x121c0
movq 0x18(%rsp), %rdi
callq 0x22710
movq %rax, %rdi
movq (%rdi), %rax
callq *0xb8(%rax)
addq $0x118, %rsp            # imm = 0x118
retq
nopl (%rax)