// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVScanline.cpp
// Function: gaps::GSVScanline::LoadPoints(gaps::RNFlags) const
void GSVScanline::
LoadPoints(RNFlags flags) const
{
  // Just checking
  if (NPoints() == 0) return;
  assert(points);

  // Draw points with different color schemes
  if (flags & GSV_DRAW_POINTS_WITH_VIEWPOINT_DISTANCE_COLOR) {
    // Get viewpoint
    R3Point v = Pose().Viewpoint();

    // Load points
    for (int i = 0; i < NPoints(); i++) {
      const R3Point& p = PointPosition(i);
      double dx = v[0] - p[0];
      double dy = v[1] - p[1];
      double dz = v[2] - p[2];
      double d2 = dx*dx + dy*dy + dz*dz;
      // double value = 0.0025 * d2;
      double value = 0.001 * d2;
      LoadColor(value);
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_HEIGHT_COLOR) {
    // Get height
    RNCoord ground_z = EstimatedGroundZ();

    // Load points
    for (int i = 0; i < NPoints(); i++) {
      const R3Point& p = PointPosition(i);
      double dz = p[2] - ground_z;
      double value = 0.25 * dz;
      LoadColor(value);
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_ELEVATION_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      LoadColor(0.5 * sqrt(PointElevation(i)));
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_REFLECTIVITY_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      LoadColor(sqrt(PointReflectivity(i)/255.0));
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_GROUND_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      if (PointFlags(i) & GSV_POINT_ON_GROUND_FLAG) RNLoadRgb(1, 0, 0);
      else RNLoadRgb(0, 0, 1);
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_RGB_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      RNLoadRgb(PointColor(i));
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_NORMAL_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      R3Vector vector = 0.5 * (PointNormal(i) + R3ones_vector);
      RNLoadRgb(vector.Coords());
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_POINT_IDENTIFIER_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      LoadColor(PointIdentifier(i));
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_CLUSTER_IDENTIFIER_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      LoadColor(PointClusterIdentifier(i));
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_CATEGORY_IDENTIFIER_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      LoadColor(PointCategoryIdentifier(i));
      R3LoadPoint(PointPosition(i));
    }
  }
  else if (flags & GSV_DRAW_POINTS_WITH_CATEGORY_CONFIDENCE_COLOR) {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      LoadColor(PointCategoryConfidence(i));
      R3LoadPoint(PointPosition(i));
    }
  }
  else {
    // Load points
    for (int i = 0; i < NPoints(); i++) {
      R3LoadPoint(PointPosition(i));
    }
  }
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rsi, 0x2e0(%rsp)
movq %rdi, 0x2d8(%rsp)
movq 0x2d8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x3a120
cmpl $0x0, %eax
jne 0x57cd3
jmp 0x58683
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x2, %rax
cmpq $0x0, %rax
je 0x57ee5
movq 0x58(%rsp), %rdi
callq 0x44c60
movq %rax, %rdi
callq 0x3a330
movq %rax, %rsi
leaq 0x2c0(%rsp), %rdi
callq 0x17fdd0
movl $0x0, 0x2bc(%rsp)
movq 0x58(%rsp), %rdi
movl 0x2bc(%rsp), %eax
movl %eax, 0x54(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x54(%rsp), %eax
cmpl %ecx, %eax
jge 0x57ee0
movq 0x58(%rsp), %rsi
movl 0x2bc(%rsp), %edx
leaq 0x298(%rsp), %rdi
callq 0x59950
leaq 0x298(%rsp), %rax
movq %rax, 0x2b0(%rsp)
leaq 0x2c0(%rsp), %rdi
xorl %esi, %esi
callq 0x44530
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x2b0(%rsp), %rdi
xorl %esi, %esi
callq 0x38ac0
movaps %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x290(%rsp)
leaq 0x2c0(%rsp), %rdi
movl $0x1, %esi
callq 0x44530
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x1, %esi
callq 0x38ac0
movaps %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x288(%rsp)
leaq 0x2c0(%rsp), %rdi
movl $0x2, %esi
callq 0x44530
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x2, %esi
callq 0x38ac0
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x280(%rsp)
movsd 0x290(%rsp), %xmm1
movsd 0x290(%rsp), %xmm2
movsd 0x288(%rsp), %xmm0
mulsd 0x288(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x280(%rsp), %xmm0
movsd 0x280(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x278(%rsp)
movsd 0x20f124(%rip), %xmm0   # 0x266fa8
mulsd 0x278(%rsp), %xmm0
movsd %xmm0, 0x270(%rsp)
movsd 0x270(%rsp), %xmm0
callq 0x58690
movq 0x58(%rsp), %rsi
movl 0x2bc(%rsp), %edx
leaq 0x258(%rsp), %rdi
callq 0x59950
leaq 0x258(%rsp), %rdi
callq 0x38e20
movl 0x2bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2bc(%rsp)
jmp 0x57d1b
jmp 0x58683
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x4, %rax
cmpq $0x0, %rax
je 0x57ff7
movq 0x58(%rsp), %rdi
callq 0x570a0
movsd %xmm0, 0x250(%rsp)
movl $0x0, 0x24c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x24c(%rsp), %eax
movl %eax, 0x34(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jge 0x57ff2
movq 0x58(%rsp), %rsi
movl 0x24c(%rsp), %edx
leaq 0x228(%rsp), %rdi
callq 0x59950
leaq 0x228(%rsp), %rax
movq %rax, 0x240(%rsp)
movq 0x240(%rsp), %rdi
movl $0x2, %esi
callq 0x38ac0
subsd 0x250(%rsp), %xmm0
movsd %xmm0, 0x220(%rsp)
movsd 0x20e112(%rip), %xmm0   # 0x2660a8
mulsd 0x220(%rsp), %xmm0
movsd %xmm0, 0x218(%rsp)
movsd 0x218(%rsp), %xmm0
callq 0x58690
movq 0x58(%rsp), %rsi
movl 0x24c(%rsp), %edx
leaq 0x200(%rsp), %rdi
callq 0x59950
leaq 0x200(%rsp), %rdi
callq 0x38e20
movl 0x24c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24c(%rsp)
jmp 0x57f1e
jmp 0x58681
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x200, %rax            # imm = 0x200
cmpq $0x0, %rax
je 0x580a9
movl $0x0, 0x1fc(%rsp)
movq 0x58(%rsp), %rdi
movl 0x1fc(%rsp), %eax
movl %eax, 0x30(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x30(%rsp), %eax
cmpl %ecx, %eax
jge 0x580a4
movq 0x58(%rsp), %rdi
movl 0x1fc(%rsp), %esi
callq 0x59c20
callq 0x298d0
movaps %xmm0, %xmm1
movsd 0x20dff1(%rip), %xmm0   # 0x266050
mulsd %xmm1, %xmm0
callq 0x58690
movq 0x58(%rsp), %rsi
movl 0x1fc(%rsp), %edx
leaq 0x1e0(%rsp), %rdi
callq 0x59950
leaq 0x1e0(%rsp), %rdi
callq 0x38e20
movl 0x1fc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1fc(%rsp)
jmp 0x5801f
jmp 0x5867f
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x800, %rax            # imm = 0x800
cmpq $0x0, %rax
je 0x5815c
movl $0x0, 0x1dc(%rsp)
movq 0x58(%rsp), %rdi
movl 0x1dc(%rsp), %eax
movl %eax, 0x2c(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0x58157
movq 0x58(%rsp), %rdi
movl 0x1dc(%rsp), %esi
callq 0x59c50
cvtsi2sd %eax, %xmm0
movsd 0x20dfc3(%rip), %xmm1   # 0x2660d0
divsd %xmm1, %xmm0
callq 0x298d0
callq 0x58690
movq 0x58(%rsp), %rsi
movl 0x1dc(%rsp), %edx
leaq 0x1c0(%rsp), %rdi
callq 0x59950
leaq 0x1c0(%rsp), %rdi
callq 0x38e20
movl 0x1dc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1dc(%rsp)
jmp 0x580d1
jmp 0x5867d
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x400, %rax            # imm = 0x400
cmpq $0x0, %rax
je 0x5821e
movl $0x0, 0x1bc(%rsp)
movq 0x58(%rsp), %rdi
movl 0x1bc(%rsp), %eax
movl %eax, 0x28(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x28(%rsp), %eax
cmpl %ecx, %eax
jge 0x58219
movq 0x58(%rsp), %rdi
movl 0x1bc(%rsp), %esi
callq 0x59c80
movzbl %al, %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x581cf
movl $0x1, %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x39820
jmp 0x581dd
xorl %esi, %esi
movl $0x1, %edx
movl %esi, %edi
callq 0x39820
movq 0x58(%rsp), %rsi
movl 0x1bc(%rsp), %edx
leaq 0x1a0(%rsp), %rdi
callq 0x59950
leaq 0x1a0(%rsp), %rdi
callq 0x38e20
movl 0x1bc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1bc(%rsp)
jmp 0x58184
jmp 0x5867b
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x8, %rax
cmpq $0x0, %rax
je 0x582c7
movl $0x0, 0x19c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x19c(%rsp), %eax
movl %eax, 0x24(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x582c2
movq 0x58(%rsp), %rsi
movl 0x19c(%rsp), %edx
leaq 0x180(%rsp), %rdi
callq 0x59cb0
leaq 0x180(%rsp), %rdi
callq 0x39130
movq 0x58(%rsp), %rsi
movl 0x19c(%rsp), %edx
leaq 0x168(%rsp), %rdi
callq 0x59950
leaq 0x168(%rsp), %rdi
callq 0x38e20
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x58244
jmp 0x58679
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x10, %rax
cmpq $0x0, %rax
je 0x583b8
movl $0x0, 0x164(%rsp)
movq 0x58(%rsp), %rdi
movl 0x164(%rsp), %eax
movl %eax, 0x20(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x20(%rsp), %eax
cmpl %ecx, %eax
jge 0x583b3
movq 0x58(%rsp), %rsi
movl 0x164(%rsp), %edx
leaq 0x118(%rsp), %rdi
callq 0x59cf0
leaq 0x130(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0x6ab068(%rip), %rdx    # 0x7033a8
callq 0x182270
leaq 0x148(%rsp), %rdi
movsd 0x20dcfb(%rip), %xmm0   # 0x266050
leaq 0x130(%rsp), %rsi
callq 0x38f20
leaq 0x148(%rsp), %rdi
callq 0x392b0
movq %rax, %rdi
callq 0x59d30
movq 0x58(%rsp), %rsi
movl 0x164(%rsp), %edx
leaq 0x100(%rsp), %rdi
callq 0x59950
leaq 0x100(%rsp), %rdi
callq 0x38e20
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0x582ed
jmp 0x58677
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x20, %rax
cmpq $0x0, %rax
je 0x58453
movl $0x0, 0xfc(%rsp)
movq 0x58(%rsp), %rdi
movl 0xfc(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x5844e
movq 0x58(%rsp), %rdi
movl 0xfc(%rsp), %esi
callq 0x59d40
movl %eax, %edi
callq 0x58880
movq 0x58(%rsp), %rsi
movl 0xfc(%rsp), %edx
leaq 0xe0(%rsp), %rdi
callq 0x59950
leaq 0xe0(%rsp), %rdi
callq 0x38e20
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x583de
jmp 0x58675
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x40, %rax
cmpq $0x0, %rax
je 0x584ee
movl $0x0, 0xdc(%rsp)
movq 0x58(%rsp), %rdi
movl 0xdc(%rsp), %eax
movl %eax, 0x18(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x18(%rsp), %eax
cmpl %ecx, %eax
jge 0x584e9
movq 0x58(%rsp), %rdi
movl 0xdc(%rsp), %esi
callq 0x59d70
movl %eax, %edi
callq 0x58880
movq 0x58(%rsp), %rsi
movl 0xdc(%rsp), %edx
leaq 0xc0(%rsp), %rdi
callq 0x59950
leaq 0xc0(%rsp), %rdi
callq 0x38e20
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x58479
jmp 0x58673
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x80, %rax
cmpq $0x0, %rax
je 0x5858b
movl $0x0, 0xbc(%rsp)
movq 0x58(%rsp), %rdi
movl 0xbc(%rsp), %eax
movl %eax, 0x14(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x58586
movq 0x58(%rsp), %rdi
movl 0xbc(%rsp), %esi
callq 0x59da0
movl %eax, %edi
callq 0x58880
movq 0x58(%rsp), %rsi
movl 0xbc(%rsp), %edx
leaq 0xa0(%rsp), %rdi
callq 0x59950
leaq 0xa0(%rsp), %rdi
callq 0x38e20
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x58516
jmp 0x58671
leaq 0x2e0(%rsp), %rdi
callq 0x38fe0
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0x5861f
movl $0x0, 0x9c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x9c(%rsp), %eax
movl %eax, 0x10(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jge 0x5861d
movq 0x58(%rsp), %rdi
movl 0x9c(%rsp), %esi
callq 0x59dd0
callq 0x58690
movq 0x58(%rsp), %rsi
movl 0x9c(%rsp), %edx
leaq 0x80(%rsp), %rdi
callq 0x59950
leaq 0x80(%rsp), %rdi
callq 0x38e20
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x585af
jmp 0x5866f
movl $0x0, 0x7c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x7c(%rsp), %eax
movl %eax, 0xc(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x5866d
movq 0x58(%rsp), %rsi
movl 0x7c(%rsp), %edx
leaq 0x60(%rsp), %rdi
callq 0x59950
leaq 0x60(%rsp), %rdi
callq 0x38e20
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x58627
jmp 0x5866f
jmp 0x58671
jmp 0x58673
jmp 0x58675
jmp 0x58677
jmp 0x58679
jmp 0x5867b
jmp 0x5867d
jmp 0x5867f
jmp 0x58681
jmp 0x58683
addq $0x2e8, %rsp            # imm = 0x2E8
retq
nopl (%rax,%rax)