// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3Segmentation.cpp
// Function: gaps::R3Segmentation::UpdatePoints()
int R3Segmentation::
UpdatePoints(void)
{
  // Update normal, tangent, radii, and area from neighbors
  for (int i = 0; i < points.NEntries(); i++) {
    R3SegmentationPoint *point = points.Kth(i);
    if (point->neighbors.NEntries() < 2) continue;
    if (!point->normal.IsZero() && !point->tangent.IsZero() &&
        (point->radius1 > 0) && (point->radius2 > 0)) continue;

    // Create array of neighborhood positions
    RNArray<R3Point *> positions;
    positions.Insert(&point->position);
    for (int j = 0; j < point->neighbors.NEntries(); j++) {
      positions.Insert(&point->neighbors[j]->position);
    }

    // Compute principle axes
    RNScalar variances[3];
    R3Point centroid = R3Centroid(positions);
    R3Triad axes = R3PrincipleAxes(centroid, positions, NULL, variances);
    if (RNIsZero(variances[1])) continue;

    // Update point
    point->normal = axes[2];
    point->tangent = axes[0];
    point->radius1 = sqrt(variances[0]);
    point->radius2 = sqrt(variances[1]);
    point->area = point->radius1 * point->radius2;
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x100(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0xfc(%rsp)
movq 0x40(%rsp), %rdi
movl 0xfc(%rsp), %eax
movl %eax, 0x3c(%rsp)
callq 0x1ecf0
movl %eax, %ecx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jge 0x43c16
movq 0x40(%rsp), %rdi
movl 0xfc(%rsp), %esi
callq 0x1f6a0
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rdi
addq $0xb0, %rdi
callq 0x1ecf0
cmpl $0x2, %eax
jge 0x43971
jmp 0x43c00
movq 0xf0(%rsp), %rdi
addq $0x20, %rdi
callq 0x47cf0
cmpl $0x0, %eax
jne 0x439ce
movq 0xf0(%rsp), %rdi
addq $0x38, %rdi
callq 0x47cf0
cmpl $0x0, %eax
jne 0x439ce
movq 0xf0(%rsp), %rax
movsd 0x50(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x439ce
movq 0xf0(%rsp), %rax
movsd 0x58(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x439ce
jmp 0x43c00
leaq 0xe0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x47720
movq 0x30(%rsp), %rdi
movq 0xf0(%rsp), %rsi
addq $0x8, %rsi
callq 0x47730
jmp 0x439f8
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0xf0(%rsp), %rdi
addq $0xb0, %rdi
callq 0x1ecf0
movl %eax, 0x2c(%rsp)
jmp 0x43a28
movl 0x28(%rsp), %eax
movl 0x2c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x43aaf
movq 0xf0(%rsp), %rdi
addq $0xb0, %rdi
movl 0xd0(%rsp), %esi
callq 0x47770
movq %rax, 0x20(%rsp)
jmp 0x43a56
movq 0x20(%rsp), %rax
movq (%rax), %rsi
addq $0x8, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x47730
jmp 0x43a71
jmp 0x43a73
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x43a03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x47760
jmp 0x43c23
xorl %eax, %eax
movl %eax, %edx
leaq 0x98(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xc66c0
jmp 0x43aca
xorl %eax, %eax
movl %eax, %ecx
leaq 0x50(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
leaq 0xb0(%rsp), %r8
callq 0xc67e0
jmp 0x43af2
movsd 0xb8(%rsp), %xmm0
leaq 0x224c46(%rip), %rax    # 0x268748
movsd (%rax), %xmm1
callq 0x27e80
movl %eax, 0x1c(%rsp)
jmp 0x43b11
movl 0x1c(%rsp), %eax
cmpl $0x0, %eax
je 0x43b27
movl $0x4, 0x4c(%rsp)
jmp 0x43be5
leaq 0x50(%rsp), %rdi
movl $0x2, %esi
callq 0x36020
movq %rax, 0x10(%rsp)
jmp 0x43b3d
movq 0x10(%rsp), %rsi
movq 0xf0(%rsp), %rdi
addq $0x20, %rdi
callq 0x12cb70
jmp 0x43b55
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x36020
movq %rax, 0x8(%rsp)
jmp 0x43b68
movq 0x8(%rsp), %rsi
movq 0xf0(%rsp), %rdi
addq $0x38, %rdi
callq 0x12cb70
jmp 0x43b80
movsd 0xb0(%rsp), %xmm0
callq 0x165a0
movq 0xf0(%rsp), %rax
movsd %xmm0, 0x50(%rax)
movsd 0xb8(%rsp), %xmm0
callq 0x165a0
movq 0xf0(%rsp), %rax
movsd %xmm0, 0x58(%rax)
movq 0xf0(%rsp), %rax
movsd 0x50(%rax), %xmm0
movq 0xf0(%rsp), %rax
mulsd 0x58(%rax), %xmm0
movq 0xf0(%rsp), %rax
movsd %xmm0, 0x70(%rax)
movl $0x0, 0x4c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x47760
movl 0x4c(%rsp), %eax
testl %eax, %eax
je 0x43bfe
jmp 0x43bfc
jmp 0x43c00
jmp 0x43c00
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x43917
movl $0x1, %eax
addq $0x108, %rsp            # imm = 0x108
retq
movq 0xd8(%rsp), %rdi
callq 0x16ca0