// File: /workspace/github_cpp_makefile_star2_O3/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 0x4823c
movq (%rbx), %rax
cmpl $0x0, 0x14(%rax)
jle 0x49b20
xorl %ebp, %ebp
movsd 0x95713(%rip), %xmm0    # 0xdf090
leaq 0x10(%rsp), %r15
xorl %r14d, %r14d
movq %rbx, 0x8(%rsp)
movq 0x440(%rsp), %rcx
movsd (%rcx,%r14,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x499a4
jnp 0x49b10
movsd %xmm1, 0x28(%rsp)
movq 0x8(%rax), %rax
movq (%rax,%r14,8), %r12
movq %r15, %rdi
callq 0x8bd1c
movq (%rbx), %rdi
movq %r12, %rsi
movsd 0x20(%rsp), %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x607cc
movq %rax, %r13
cmpl $0x0, 0x14(%r12)
jle 0x49a15
xorl %ebx, %ebx
movq 0x8(%r12), %rax
movq (%rax,%rbx,8), %rax
testq %rax, %rax
je 0x499fa
movq 0x8(%rax), %rsi
cmpq %r12, %rsi
jne 0x499fc
movq 0x10(%rax), %rsi
jmp 0x499fc
xorl %esi, %esi
movl 0x1c(%rsp), %edx
movq %r15, %rdi
callq 0x8bdb2
incq %rbx
movslq 0x14(%r12), %rax
cmpq %rax, %rbx
jl 0x499dd
testq %r13, %r13
je 0x49a22
movq %r13, %rdi
callq 0x21c00
movslq 0x1c(%rsp), %rax
testq %rax, %rax
jle 0x49aa6
movq 0x10(%rsp), %rdx
movl $0x1, %ecx
movq 0x440(%rsp), %rsi
xorl %edi, %edi
movl $0x1, %r8d
movq 0x8(%rsp), %rbx
movsd 0x9563d(%rip), %xmm1    # 0xdf090
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 0x49a59
testl %r8d, %r8d
setne %dl
testl %ecx, %ecx
setne %al
jmp 0x49aaf
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 0x49afd
andb %al, %cl
jne 0x49afd
movq 0x410(%rbx), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, (%rax,%r14,8)
movapd 0x9793b(%rip), %xmm0    # 0xe1420
movupd %xmm0, 0x418(%rbx)
movupd %xmm0, 0x428(%rbx)
movupd %xmm0, 0x438(%rbx)
movq %r15, %rdi
callq 0x8bd86
movq (%rbx), %rax
movsd 0x95580(%rip), %xmm0    # 0xdf090
incq %r14
movslq 0x14(%rax), %rcx
cmpq %rcx, %r14
jl 0x4998a
movaps 0x978f9(%rip), %xmm0    # 0xe1420
movups %xmm0, 0x418(%rbx)
movups %xmm0, 0x428(%rbx)
movups %xmm0, 0x438(%rbx)
movq 0x440(%rsp), %rdi
testq %rdi, %rdi
je 0x49b4e
callq 0x21c00
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x49b67
movq %rax, %rbx
jmp 0x49b74
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8bd86
movq 0x440(%rsp), %rdi
testq %rdi, %rdi
je 0x49b86
callq 0x21c00
movq %rbx, %rdi
callq 0x220a0