// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3MeshProperty.cpp
// Function: gaps::R3MeshProperty::NonExtremumSuppression(double, int, int)
void R3MeshProperty::
NonExtremumSuppression(RNLength radius, RNBoolean keep_local_minima, RNBoolean keep_local_maxima)
{
  // Set every value to unknown if it has a neighbor with a more extreme value
  R3MeshProperty copy(*this);
  for (int i = 0; i < mesh->NVertices(); i++) {
    if (copy.VertexValue(i) == RN_UNKNOWN) continue;
    R3MeshVertex *vertex = mesh->Vertex(i);
    RNScalar vertex_value = copy.VertexValue(i);

    // Find neighborhood of vertex
    RNArray<R3MeshVertex *> neighbor_vertices;
    RNLength *distances = mesh->DijkstraDistances(vertex, radius, neighbor_vertices); 
    for (int j = 0; j < mesh->VertexValence(vertex); j++) neighbor_vertices.Insert(mesh->VertexOnVertex(vertex, j));
    delete [] distances;

    // Check value of vertices within neighborhood
    RNBoolean local_minimum = TRUE;
    RNBoolean local_maximum = TRUE;
    for (int j = 0; j < neighbor_vertices.NEntries(); j++) {
      R3MeshVertex *neighbor_vertex = neighbor_vertices.Kth(j);
      RNScalar neighbor_value = copy.VertexValue(neighbor_vertex);
      if (neighbor_value == RN_UNKNOWN) continue;
      if (neighbor_value < vertex_value) local_minimum = FALSE;
      if (neighbor_value > vertex_value) local_maximum = FALSE;
    }

    // Mask this vertex if not extremum
    if (keep_local_minima && local_minimum) continue;
    if (keep_local_maxima && local_maximum) continue;
    SetVertexValue(i, RN_UNKNOWN);
  }

  // Reset statistics
  ResetStatistics();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %edx, 0x4(%rsp)
movl %esi, (%rsp)
movsd %xmm0, 0x20(%rsp)
movq %rdi, %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x488d0
movq (%rbx), %rax
cmpl $0x0, 0x14(%rax)
jle 0x4a19e
xorl %ebp, %ebp
movsd 0x97095(%rip), %xmm0    # 0xe1090
leaq 0x10(%rsp), %r15
xorl %r14d, %r14d
movq %rbx, 0x8(%rsp)
movq 0x440(%rsp), %rcx
movsd (%rcx,%r14,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x4a022
jnp 0x4a18b
movsd %xmm1, 0x28(%rsp)
movq 0x8(%rax), %rax
movq (%rax,%r14,8), %r12
movq %r15, %rdi
callq 0x8cefc
movq (%rbx), %rdi
movq %r12, %rsi
movsd 0x20(%rsp), %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6139a
movq %rax, %r13
cmpl $0x0, 0x14(%r12)
jle 0x4a093
xorl %ebx, %ebx
movq 0x8(%r12), %rax
movq (%rax,%rbx,8), %rax
testq %rax, %rax
je 0x4a078
movq 0x8(%rax), %rsi
cmpq %r12, %rsi
jne 0x4a07a
movq 0x10(%rax), %rsi
jmp 0x4a07a
xorl %esi, %esi
movl 0x1c(%rsp), %edx
movq %r15, %rdi
callq 0x8cf92
incq %rbx
movslq 0x14(%r12), %rax
cmpq %rax, %rbx
jl 0x4a05b
testq %r13, %r13
je 0x4a0a0
movq %r13, %rdi
callq 0x21c10
movslq 0x1c(%rsp), %rax
testq %rax, %rax
jle 0x4a124
movq 0x10(%rsp), %rdx
movl $0x1, %ecx
movq 0x440(%rsp), %rsi
xorl %edi, %edi
movl $0x1, %r8d
movq 0x8(%rsp), %rbx
movsd 0x96fbf(%rip), %xmm1    # 0xe1090
movsd 0x28(%rsp), %xmm2
movq (%rdx,%rdi,8), %r9
movslq 0x70(%r9), %r9
movsd (%rsi,%r9,8), %xmm0
ucomisd %xmm0, %xmm2
movl %r8d, %r9d
cmoval %ebp, %r9d
ucomisd %xmm2, %xmm0
movl %ecx, %r10d
cmoval %ebp, %r10d
ucomisd %xmm1, %xmm0
cmovnel %r9d, %r8d
cmovpl %r9d, %r8d
cmovnel %r10d, %ecx
cmovpl %r10d, %ecx
incq %rdi
cmpq %rdi, %rax
jne 0x4a0d7
testl %r8d, %r8d
setne %dl
testl %ecx, %ecx
setne %al
jmp 0x4a12d
movb $0x1, %dl
movb $0x1, %al
movq 0x8(%rsp), %rbx
cmpl $0x0, 0x4(%rsp)
setne %cl
cmpl $0x0, (%rsp)
setne %sil
testb %dl, %sil
jne 0x4a17b
andb %al, %cl
jne 0x4a17b
movq 0x410(%rbx), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, (%rax,%r14,8)
movapd 0x992cd(%rip), %xmm0    # 0xe3430
movupd %xmm0, 0x418(%rbx)
movupd %xmm0, 0x428(%rbx)
movupd %xmm0, 0x438(%rbx)
movq %r15, %rdi
callq 0x8cf66
movsd 0x96f05(%rip), %xmm0    # 0xe1090
incq %r14
movq (%rbx), %rax
movslq 0x14(%rax), %rcx
cmpq %rcx, %r14
jl 0x4a008
movaps 0x9928b(%rip), %xmm0    # 0xe3430
movups %xmm0, 0x418(%rbx)
movups %xmm0, 0x428(%rbx)
movups %xmm0, 0x438(%rbx)
movq 0x440(%rsp), %rdi
testq %rdi, %rdi
je 0x4a1cc
callq 0x21c10
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4a1e5
movq %rax, %rbx
jmp 0x4a1f2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8cf66
movq 0x440(%rsp), %rdi
testq %rdi, %rdi
je 0x4a204
callq 0x21c10
movq %rbx, %rdi
callq 0x220b0