// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointGraph.cpp
// Function: gaps::R3SurfelPointGraph::UpdateNormals() const
void R3SurfelPointGraph::
UpdateNormals(void) const
{
  // Declare variables (fill it only if needed)
  R3Point *positions = NULL;

  // Compute normals for all points that don't already have them
  for (int i = 0; i < NPoints(); i++) {
    R3SurfelPoint *point = Point(i);
    if (point->HasNormal()) continue;

    // Allocate array of positions
    if (!positions) {
      positions = new R3Point [MaxNeighbors() + 1];
      if (!positions) RNAbort("Unable to allocate positions to update normals");
    }

    // Create array of positions for neighborhood
    int npositions = 0;
    positions[npositions++] = point->Position();
    for (int j = 0; j < NNeighbors(i); j++) {
      R3SurfelPoint *neighbor = Neighbor(i, j);
      positions[npositions++] = neighbor->Position();
    }

    // Compute normal with PCA of neighborhood
    R3Point centroid = R3Centroid(npositions, positions);
    R3Triad triad = R3PrincipleAxes(centroid, npositions, positions);
    R3Vector normal = triad[2];

    // Assign normal
    point->SetNormal(normal);
  }

  // Delete data
  if (positions) delete [] positions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
cmpl $0x0, 0x18(%rdi)
jle 0x37055
movq %rdi, %rbx
xorl %ebp, %ebp
leaq 0x50(%rsp), %r15
xorl %r13d, %r13d
movq 0x10(%rbx), %rcx
movq %rbp, %r14
shlq $0x4, %r14
movq 0x8(%rcx,%r14), %rax
testb $0x40, 0x2f(%rax)
jne 0x37043
testq %r13, %r13
movq %rbp, 0x10(%rsp)
jne 0x36f27
movq %rcx, 0x8(%rsp)
movl 0x70(%rbx), %r12d
leal 0x1(%r12), %eax
movslq %eax, %r13
movq %r13, %rax
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
movq %rdi, 0x18(%rsp)
callq 0x13030
movq %rax, %rbp
incl %r12d
je 0x36f1a
shlq $0x3, %r13
leaq (%r13,%r13,2), %r13
xorl %r12d, %r12d
leaq (%r12,%rbp), %rdi
callq 0x84d7c
addq $0x18, %r12
cmpq %r12, %r13
jne 0x36f08
movq %rbp, %r13
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %rcx
addq %r14, %rcx
movq (%rcx), %rax
movq %rcx, 0x8(%rsp)
movq 0x8(%rcx), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rcx), %xmm0
addsd 0x10(%rax), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rcx), %xmm1
addsd 0x18(%rax), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rcx), %xmm2
addsd 0x20(%rax), %xmm2
movq %r15, %rdi
callq 0x84d7e
movq %r13, %rdi
movq %r15, %rsi
callq 0x850ec
movq 0x68(%rbx), %rax
cmpl $0x0, 0xc(%rax,%r14)
jle 0x36fef
movq %r13, %rbp
addq $0x18, %r13
xorl %r12d, %r12d
movq (%rax,%r14), %rax
movq (%rax,%r12,8), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
addsd 0x10(%rcx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax), %xmm1
addsd 0x18(%rcx), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax), %xmm2
addsd 0x20(%rcx), %xmm2
movq %r15, %rdi
callq 0x84d7e
movq %r13, %rdi
movq %r15, %rsi
callq 0x850ec
incq %r12
movq 0x68(%rbx), %rax
movslq 0xc(%rax,%r14), %rcx
addq $0x18, %r13
cmpq %rcx, %r12
jl 0x36f85
incl %r12d
movq %rbp, %r13
movq 0x10(%rsp), %rbp
jmp 0x36ff5
movl $0x1, %r12d
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movl %r12d, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x5501d
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movq %r13, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x550a7
leaq 0x20(%rsp), %r14
movq %r14, %rdi
leaq 0x80(%rsp), %rsi
callq 0x85826
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x326e2
incq %rbp
movslq 0x18(%rbx), %rax
cmpq %rax, %rbp
jl 0x36e9c
jmp 0x37058
xorl %r13d, %r13d
testq %r13, %r13
je 0x37065
movq %r13, %rdi
callq 0x13680
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
callq 0x139b0
movq %rbx, %rdi
callq 0x138b0
nop