// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
movq %rdi, %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x42bdc
xorl %ebp, %ebp
leaq 0x20(%rsp), %r15
xorl %r14d, %r14d
movq %rbx, 0x8(%rsp)
movq (%rbx), %rax
movslq 0x14(%rax), %rcx
cmpq %rcx, %r14
jge 0x442c1
movq 0x440(%rsp), %rcx
movsd (%rcx,%r14,8), %xmm0
ucomisd 0x84f1b(%rip), %xmm0    # 0xc9088
jne 0x44175
jnp 0x442b9
movsd %xmm0, 0x18(%rsp)
movq 0x8(%rax), %rax
movq (%rax,%r14,8), %r12
movq %r15, %rdi
callq 0x8001e
movq (%rbx), %rdi
movq %r12, %rsi
movsd 0x10(%rsp), %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x57fd8
movq %rax, %r13
xorl %ebx, %ebx
movslq 0x14(%r12), %rax
cmpq %rax, %rbx
jge 0x441dc
movq 0x8(%r12), %rax
movq (%rax,%rbx,8), %rax
testq %rax, %rax
je 0x441cd
movq 0x8(%rax), %rsi
cmpq %r12, %rsi
jne 0x441cf
movq 0x10(%rax), %rsi
jmp 0x441cf
xorl %esi, %esi
movq %r15, %rdi
callq 0x26aa0
incq %rbx
jmp 0x441a6
testq %r13, %r13
je 0x441e9
movq %r13, %rdi
callq 0x21c00
movl 0x2c(%rsp), %eax
movq 0x20(%rsp), %rcx
testl %eax, %eax
cmovlel %ebp, %eax
movq 0x440(%rsp), %rdi
xorl %r8d, %r8d
pushq $0x1
popq %rdx
movl %edx, %esi
movq 0x8(%rsp), %rbx
cmpq %r8, %rax
je 0x44258
movq (%rcx,%r8,8), %r9
movslq 0x70(%r9), %r9
movsd (%rdi,%r9,8), %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl %esi, %r9d
cmoval %ebp, %r9d
ucomisd %xmm1, %xmm0
movl %edx, %r10d
cmoval %ebp, %r10d
ucomisd 0x84e45(%rip), %xmm0    # 0xc9088
cmovnel %r9d, %esi
cmovpl %r9d, %esi
cmovnel %r10d, %edx
cmovpl %r10d, %edx
incq %r8
jmp 0x4420c
cmpl $0x0, 0x4(%rsp)
setne %al
cmpl $0x0, (%rsp)
setne %dil
testl %esi, %esi
setne %sil
testl %edx, %edx
setne %cl
testb %sil, %dil
jne 0x442b1
andb %cl, %al
jne 0x442b1
movq 0x410(%rbx), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, (%rax,%r14,8)
movapd 0x87167(%rip), %xmm0    # 0xcb400
movupd %xmm0, 0x418(%rbx)
movupd %xmm0, 0x428(%rbx)
movupd %xmm0, 0x438(%rbx)
movq %r15, %rdi
callq 0x8008c
incq %r14
jmp 0x44147
movaps 0x87138(%rip), %xmm0    # 0xcb400
movups %xmm0, 0x418(%rbx)
movups %xmm0, 0x428(%rbx)
movups %xmm0, 0x438(%rbx)
leaq 0x30(%rsp), %rdi
callq 0x42c80
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x44300
movq %rax, %rbx
jmp 0x4430d
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x8008c
leaq 0x30(%rsp), %rdi
callq 0x42c80
movq %rbx, %rdi
callq 0x220c0
nop