// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3MeshProperty.cpp
// Function: gaps::R3MeshProperty::Gaussian(gaps::R3MeshVertex*, double) const
RNScalar R3MeshProperty::
Gaussian(R3MeshVertex *vertex, RNScalar sigma) const
{
  // Check vertex value
  RNScalar vertex_value = VertexValue(vertex);
  if (vertex_value == RN_UNKNOWN) return RN_UNKNOWN;
  if (sigma == 0) return vertex_value;

  // Get convenient variables
  RNScalar radius = 3 * sigma;
  RNScalar denom = -2 * sigma * sigma;

  // Compute array of vertices within blur filter
  RNArray<R3MeshVertex *> neighbor_vertices;
  RNLength *distances = mesh->DijkstraDistances(vertex, radius, neighbor_vertices);
  delete [] distances;

  // Compute blurred value
  RNScalar total_value = 0;
  RNScalar total_weight = 0;
  for (int j = 0; j < neighbor_vertices.NEntries(); j++) {
    R3MeshVertex *neighbor_vertex = neighbor_vertices.Kth(j);
    int neighbor_id = mesh->VertexID(neighbor_vertex);
    RNScalar value = values[neighbor_id];
    if (value == RN_UNKNOWN) continue;
    RNLength distance = distances[neighbor_id];
    if (distance > radius) continue;
    RNScalar weight = exp(distance * distance / denom); 
    total_value += weight * value;
    total_weight += weight;
  }

  // Check total weight
  if (total_weight == 0) return vertex_value;

  // Return value 
  return total_value / total_weight;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movapd %xmm0, %xmm2
movslq 0x70(%rsi), %rax
movq 0x410(%rdi), %rcx
movsd (%rcx,%rax,8), %xmm1
movsd 0x986d5(%rip), %xmm0    # 0xe1090
ucomisd %xmm0, %xmm1
jne 0x489c7
jnp 0x48b2e
movapd %xmm1, 0x40(%rsp)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jne 0x489e4
jp 0x489e4
movapd 0x40(%rsp), %xmm0
jmp 0x48b2e
movq %rsi, %r14
movq %rdi, %rbx
movsd 0x98bee(%rip), %xmm0    # 0xe15e0
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rsp, %r15
movq %r15, %rdi
callq 0x8cefc
movq (%rbx), %rdi
movq %r14, %rsi
movsd 0x10(%rsp), %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6139a
movq %rax, %r14
testq %rax, %rax
je 0x48a33
movq %r14, %rdi
callq 0x21c10
xorpd %xmm1, %xmm1
cmpl $0x0, 0xc(%rsp)
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
jle 0x48aff
movsd 0x98a3e(%rip), %xmm0    # 0xe1490
movsd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x30(%rsp)
xorpd %xmm2, %xmm2
xorl %r15d, %r15d
movsd 0x9861b(%rip), %xmm4    # 0xe1090
movq (%rsp), %rax
movq (%rax,%r15,8), %rax
movslq 0x70(%rax), %rax
movq 0x410(%rbx), %rcx
movsd (%rcx,%rax,8), %xmm5
ucomisd %xmm4, %xmm5
jne 0x48a95
jnp 0x48aee
movsd (%r14,%rax,8), %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x48aee
mulsd %xmm0, %xmm0
divsd 0x30(%rsp), %xmm0
movapd %xmm2, 0x20(%rsp)
movapd %xmm3, 0x50(%rsp)
movsd %xmm5, 0x38(%rsp)
callq 0x22100
movsd 0x985c4(%rip), %xmm4    # 0xe1090
movapd 0x50(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
xorpd %xmm1, %xmm1
movsd 0x38(%rsp), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm5, %xmm2
addsd %xmm0, %xmm3
incq %r15
movslq 0xc(%rsp), %rax
cmpq %rax, %r15
jl 0x48a75
divsd %xmm3, %xmm2
cmpeqsd %xmm3, %xmm1
movapd %xmm1, %xmm0
andnpd %xmm2, %xmm0
andpd 0x40(%rsp), %xmm1
orpd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movq %rsp, %rdi
callq 0x8cf66
movapd 0x10(%rsp), %xmm0
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8cf66
movq %rbx, %rdi
callq 0x220b0
nop