// File: /workspace/github_cpp_makefile_star2_O3/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 0x96d6d(%rip), %xmm0    # 0xdf090
ucomisd %xmm0, %xmm1
jne 0x4832f
jnp 0x48499
movapd %xmm1, 0x40(%rsp)
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jne 0x4834c
jp 0x4834c
movapd 0x40(%rsp), %xmm0
jmp 0x48499
movq %rsi, %r14
movq %rdi, %rbx
movsd 0x97286(%rip), %xmm0    # 0xdf5e0
movsd %xmm2, 0x20(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rsp, %r15
movq %r15, %rdi
callq 0x8bd1c
movq (%rbx), %rdi
movq %r14, %rsi
movsd 0x10(%rsp), %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x607cc
movq %rax, %r14
testq %rax, %rax
je 0x4839b
movq %r14, %rdi
callq 0x21c00
movl 0xc(%rsp), %eax
xorpd %xmm1, %xmm1
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
testl %eax, %eax
jle 0x4846a
movsd 0x970d5(%rip), %xmm0    # 0xdf490
movsd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x30(%rsp)
xorpd %xmm2, %xmm2
xorl %r15d, %r15d
movsd 0x96cb2(%rip), %xmm4    # 0xdf090
movq (%rsp), %rcx
movq (%rcx,%r15,8), %rcx
movslq 0x70(%rcx), %rcx
movq 0x410(%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm5
ucomisd %xmm4, %xmm5
jne 0x483fe
jnp 0x4845b
movsd (%r14,%rcx,8), %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x4845b
mulsd %xmm0, %xmm0
divsd 0x30(%rsp), %xmm0
movapd %xmm2, 0x20(%rsp)
movapd %xmm3, 0x50(%rsp)
movsd %xmm5, 0x38(%rsp)
callq 0x220f0
movsd 0x96c5b(%rip), %xmm4    # 0xdf090
movapd 0x50(%rsp), %xmm3
movapd 0x20(%rsp), %xmm2
xorpd %xmm1, %xmm1
movsd 0x38(%rsp), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm5, %xmm2
addsd %xmm0, %xmm3
movl 0xc(%rsp), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x483de
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 0x8bd86
movapd 0x10(%rsp), %xmm0
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8bd86
movq %rbx, %rdi
callq 0x220a0