// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointSet.cpp
// Function: gaps::R3SurfelPointSet::Draw(gaps::RNFlags) const
void R3SurfelPointSet::
Draw(RNFlags flags) const
{
  // Get convenient variables
  int c = flags[R3_SURFEL_COLOR_DRAW_FLAG];
  int n = flags[R3_SURFEL_NORMAL_DRAW_FLAG];
  int d = flags[R3_SURFEL_DISC_DRAW_FLAG];
  int id = flags[R3_SURFEL_IDENTIFIER_DRAW_FLAG];

  // Draw discs
  if (d) {
    const int nsides = 6;
    RNGrfxBegin(RN_GRFX_TRIANGLES);
    for (int i = 0; i < NPoints(); i++) {
      const R3SurfelPoint *point = Point(i);
      R3Point position = point->Position();
      R3Vector normal = point->Normal();
      R3Vector tangent1 = point->Tangent();
      R3Vector tangent2 = tangent1 % normal;
      double r1 = point->Radius(0);
      double r2 = point->Radius(1);
      if (r1 <= 0) r1 = 0.1;
      if (r2 <= 0) r2 = r1;
      if (c) RNLoadRgb(point->Color());
      if (id) RNLoadRgba(point->Identifier());
      else if (n) R3LoadNormal(normal);
      R3Point p[nsides];
      for (int j = 0; j < nsides; j++) {
        double angle = RN_TWO_PI*j/nsides;
        p[j] = position;
        p[j] += cos(angle) * r1 * tangent1;
        p[j] += sin(angle) * r2 * tangent2;
      }
      for (int j = 0; j < nsides; j++) {
        R3LoadPoint(position);
        R3LoadPoint(p[(j+1)%nsides]);
        R3LoadPoint(p[j]);
      }
    }
    RNGrfxEnd();
  }
  else {
    // Draw surfels with color
    RNGrfxBegin(RN_GRFX_POINTS);
    for (int i = 0; i < NPoints(); i++) {
      const R3SurfelPoint *point = Point(i);
      if (c) RNLoadRgb(point->Color());
      if (id) RNLoadRgba(point->Identifier());
      else if (n) R3LoadNormal(point->Normal());
      R3LoadPoint(point->Position());
    }
    RNGrfxEnd();
  }
}

// Assembly:
subq $0x218, %rsp            # imm = 0x218
movq %rsi, 0x210(%rsp)
movq %rdi, 0x208(%rsp)
movq 0x208(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x1f8(%rsp), %rdi
movl $0x1, %esi
callq 0x1b970
movq 0x1f8(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x31a20
movl %eax, 0x204(%rsp)
leaq 0x1e8(%rsp), %rdi
movl $0x2, %esi
callq 0x1b970
movq 0x1e8(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x31a20
movl %eax, 0x1f4(%rsp)
leaq 0x1d8(%rsp), %rdi
movl $0x10, %esi
callq 0x1b970
movq 0x1d8(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x31a20
movl %eax, 0x1e4(%rsp)
leaq 0x1c8(%rsp), %rdi
movl $0x4, %esi
callq 0x1b970
movq 0x1c8(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x31a20
movl %eax, 0x1d4(%rsp)
cmpl $0x0, 0x1e4(%rsp)
je 0x5a3eb
movl $0x6, 0x1c4(%rsp)
movl $0x4, %edi
callq 0x4ff50
movl $0x0, 0x1c0(%rsp)
movq 0x28(%rsp), %rdi
movl 0x1c0(%rsp), %eax
movl %eax, 0x24(%rsp)
callq 0x18700
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x5a3e1
movq 0x28(%rsp), %rdi
movl 0x1c0(%rsp), %esi
callq 0x18710
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x18730
movq 0x1b8(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x4f8d0
movq 0x1b8(%rsp), %rsi
leaq 0x170(%rsp), %rdi
callq 0x4f940
leaq 0x158(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x188(%rsp), %rdx
callq 0xfa2f0
movq 0x1b8(%rsp), %rdi
xorl %esi, %esi
callq 0x4f9b0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x150(%rsp)
movq 0x1b8(%rsp), %rdi
movl $0x1, %esi
callq 0x4f9b0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x148(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x150(%rsp), %xmm0
jb 0x5a18c
movsd 0x14a215(%rip), %xmm0   # 0x1a4398
movsd %xmm0, 0x150(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x148(%rsp), %xmm0
jb 0x5a1ac
movsd 0x150(%rsp), %xmm0
movsd %xmm0, 0x148(%rsp)
cmpl $0x0, 0x204(%rsp)
je 0x5a1cb
movq 0x1b8(%rsp), %rdi
callq 0x4fa20
movq %rax, %rdi
callq 0x4ff70
cmpl $0x0, 0x1d4(%rsp)
je 0x5a1eb
movq 0x1b8(%rsp), %rdi
callq 0x4fad0
movl %eax, %edi
callq 0x4ff90
jmp 0x5a204
cmpl $0x0, 0x1f4(%rsp)
je 0x5a202
leaq 0x188(%rsp), %rdi
callq 0x4ffe0
jmp 0x5a204
leaq 0xb0(%rsp), %rax
movq %rax, %rcx
addq $0x90, %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xf8340
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0x18(%rsp)
jne 0x5a220
movl $0x0, 0xac(%rsp)
cmpl $0x6, 0xac(%rsp)
jge 0x5a361
leaq 0x14f0b9(%rip), %rax    # 0x1a9320
movsd (%rax), %xmm0
cvtsi2sdl 0xac(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x14a120(%rip), %xmm1   # 0x1a43a0
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movslq 0xac(%rsp), %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x1a0(%rsp), %rsi
callq 0xf89e0
movsd 0xa0(%rsp), %xmm0
callq 0x13a30
mulsd 0x150(%rsp), %xmm0
leaq 0x88(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x31980
movslq 0xac(%rsp), %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x88(%rsp), %rsi
callq 0xf8a90
movsd 0xa0(%rsp), %xmm0
callq 0x13110
mulsd 0x148(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x31980
movslq 0xac(%rsp), %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0xf8a90
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5a252
movl $0x0, 0x6c(%rsp)
cmpl $0x6, 0x6c(%rsp)
jge 0x5a3c9
leaq 0x1a0(%rsp), %rdi
callq 0x50050
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl $0x6, %ecx
cltd
idivl %ecx
movslq %edx, %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x50050
movslq 0x6c(%rsp), %rax
leaq 0xb0(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x50050
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x5a369
jmp 0x5a3cb
movl 0x1c0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c0(%rsp)
jmp 0x5a09a
callq 0x50070
jmp 0x5a4b9
xorl %edi, %edi
callq 0x4ff50
movl $0x0, 0x68(%rsp)
movq 0x28(%rsp), %rdi
movl 0x68(%rsp), %eax
movl %eax, 0x4(%rsp)
callq 0x18700
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x5a4b4
movq 0x28(%rsp), %rdi
movl 0x68(%rsp), %esi
callq 0x18710
movq %rax, 0x60(%rsp)
cmpl $0x0, 0x204(%rsp)
je 0x5a449
movq 0x60(%rsp), %rdi
callq 0x4fa20
movq %rax, %rdi
callq 0x4ff70
cmpl $0x0, 0x1d4(%rsp)
je 0x5a466
movq 0x60(%rsp), %rdi
callq 0x4fad0
movl %eax, %edi
callq 0x4ff90
jmp 0x5a48b
cmpl $0x0, 0x1f4(%rsp)
je 0x5a489
movq 0x60(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x4f8d0
leaq 0x48(%rsp), %rdi
callq 0x4ffe0
jmp 0x5a48b
movq 0x60(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x18730
leaq 0x30(%rsp), %rdi
callq 0x50050
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x5a3fa
callq 0x50070
addq $0x218, %rsp            # imm = 0x218
retq
nopw %cs:(%rax,%rax)