// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointGraph.cpp
// Function: gaps::R3SurfelPointGraph::R3SurfelPointGraph(gaps::R3SurfelPointSet const&, int, double)
R3SurfelPointGraph::
R3SurfelPointGraph(const R3SurfelPointSet& set, int max_neighbors, RNLength max_distance)
  : set(set),
    neighbors(NULL),
    max_neighbors(max_neighbors),
    max_distance(max_distance)
{
  // Allocate neighbors
  neighbors = new RNArray<R3SurfelPoint *> [ NPoints() ];

  // Find neighbors with kdtree
  RNArray<R3SurfelPoint *> points;
  for (int i = 0; i < NPoints(); i++) points.Insert(Point(i));
  R3Kdtree<R3SurfelPoint *> kdtree(points, SurfelPointPosition, NULL);
  for (int i = 0; i < NPoints(); i++) {
    kdtree.FindClosest(Point(i), 0, max_distance, max_neighbors, neighbors[i]);
  }
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movl %edx, 0x114(%rsp)
movsd %xmm0, 0x108(%rsp)
movq 0x120(%rsp), %rdi
movq %rdi, 0x70(%rsp)
leaq 0x19165d(%rip), %rax    # 0x1ee998
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, 0x68(%rsp)
movq 0x118(%rsp), %rsi
callq 0x55ea0
movq 0x70(%rsp), %rdi
movq $0x0, 0x68(%rdi)
movl 0x114(%rsp), %eax
movl %eax, 0x70(%rdi)
movsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x78(%rdi)
callq 0x43e20
movl %eax, 0x78(%rsp)
jmp 0x5d384
movl 0x78(%rsp), %eax
cltq
movq %rax, 0x50(%rsp)
movl $0x10, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
movq $-0x1, %rax
cmovbq %rax, %rdi
testb %cl, %cl
cmovneq %rax, %rdi
movq %rdi, 0x58(%rsp)
callq 0x13030
movq %rax, 0x60(%rsp)
jmp 0x5d3c3
movq 0x50(%rsp), %rax
movq 0x60(%rsp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, 0x48(%rsp)
cmpq $0x0, %rax
je 0x5d426
movq 0x48(%rsp), %rax
movq 0x50(%rsp), %rdx
shlq $0x4, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x43e70
jmp 0x5d40e
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %rax
addq $0x10, %rax
cmpq %rcx, %rax
movq %rax, 0x40(%rsp)
jne 0x5d3fd
movq 0x70(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x68(%rax)
leaq 0xe8(%rsp), %rdi
callq 0x43e70
jmp 0x5d443
movl $0x0, 0xe4(%rsp)
movq 0x70(%rsp), %rdi
movl 0xe4(%rsp), %eax
movl %eax, 0x28(%rsp)
callq 0x43e20
movl %eax, 0x2c(%rsp)
jmp 0x5d469
movl 0x28(%rsp), %eax
movl 0x2c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5d54d
movq 0x70(%rsp), %rdi
movl 0xe4(%rsp), %esi
callq 0x43e40
movq %rax, 0x20(%rsp)
jmp 0x5d491
movq 0x20(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x43e80
jmp 0x5d4a5
jmp 0x5d4a7
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x5d44e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5d657
movq 0x48(%rsp), %rcx
movq %rax, %rsi
movq 0x30(%rsp), %rax
movq %rsi, 0x100(%rsp)
movl %edx, 0xfc(%rsp)
cmpq %rax, %rcx
movq %rax, 0x18(%rsp)
je 0x5d520
movq 0x18(%rsp), %rdi
addq $-0x10, %rdi
movq %rdi, 0x10(%rsp)
callq 0x43fb0
movq 0x48(%rsp), %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x18(%rsp)
jne 0x5d4f9
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0x13a90
jmp 0x5d657
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5d64a
leaq -0x7794(%rip), %rdx     # 0x55dc0
xorl %eax, %eax
movl %eax, %ecx
leaq 0x80(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x5b330
jmp 0x5d56f
movl $0x0, 0x7c(%rsp)
movq 0x70(%rsp), %rdi
movl 0x7c(%rsp), %eax
movl %eax, 0x8(%rsp)
callq 0x43e20
movl %eax, 0xc(%rsp)
jmp 0x5d58f
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5d628
movq 0x70(%rsp), %rdi
movl 0x7c(%rsp), %esi
callq 0x43e40
movq %rax, (%rsp)
jmp 0x5d5b3
movq (%rsp), %rsi
movq 0x70(%rsp), %rax
movsd 0x108(%rsp), %xmm1
movl 0x114(%rsp), %edx
movq 0x68(%rax), %rcx
movslq 0x7c(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %r8d
leaq 0x80(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0x5b5e0
jmp 0x5d5f3
jmp 0x5d5f5
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x5d577
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x5b670
jmp 0x5d64a
leaq 0x80(%rsp), %rdi
callq 0x5b670
leaq 0xe8(%rsp), %rdi
callq 0x43fb0
addq $0x128, %rsp            # imm = 0x128
retq
leaq 0xe8(%rsp), %rdi
callq 0x43fb0
movq 0x68(%rsp), %rdi
callq 0x56040
movq 0x100(%rsp), %rdi
callq 0x13970
nop