// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3MeshProperty.cpp
// Function: gaps::R3MeshProperty::Blur(double)
void R3MeshProperty::
Blur(RNScalar sigma)
{
  // Blur across mesh

  // Get convenient variables
  if (sigma == 0) return;
  RNScalar radius = 3 * sigma;
  RNScalar denom = -2 * sigma * sigma;

  // Make copy of values
  RNScalar *old_values = new RNScalar [ mesh->NVertices() ];
  for (int i = 0; i < mesh->NVertices(); i++) old_values[i] = values[i];

  // Allocate array of vertices within blur filter
  RNArray<R3MeshVertex *> neighbor_vertices;

  // Blur value at every vertex
  for (int i = 0; i < mesh->NVertices(); i++) {
    R3MeshVertex *vertex = mesh->Vertex(i);
    if (values[i] == RN_UNKNOWN) continue;

    // Compute distances
    RNLength *distances = mesh->DijkstraDistances(vertex, radius, neighbor_vertices);

    // 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 = old_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;
    }

    // Assign blurred value (normalized by total weight)
    if (total_weight > 0) {
      values[i] = total_value / total_weight;
    }

    // Delete distances
    delete [] distances;
  }

  // Delete copy of values
  delete [] old_values;

  // Reset statistics
  ResetStatistics();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4a9d8
jnp 0x4abde
movq %rdi, %rbx
movsd %xmm0, (%rsp)
movq (%rdi), %r15
movslq 0x14(%r15), %rax
leaq (,%rax,8), %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x21040
movq %rax, %r14
movslq 0x14(%r15), %rax
testq %rax, %rax
jle 0x4aa2a
movq 0x410(%rbx), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%r14,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4aa17
leaq 0x8(%rsp), %rdi
callq 0x8cefc
movq (%rbx), %rdi
cmpl $0x0, 0x14(%rdi)
movsd (%rsp), %xmm1
jle 0x4abac
movsd 0x96a42(%rip), %xmm0    # 0xe1490
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
mulsd 0x96b7c(%rip), %xmm1    # 0xe15e0
xorl %r13d, %r13d
movsd 0x96621(%rip), %xmm2    # 0xe1090
leaq 0x8(%rsp), %r15
movsd %xmm1, (%rsp)
movq 0x410(%rbx), %rax
movsd (%rax,%r13,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x4aa92
jnp 0x4ab99
movq 0x8(%rdi), %rax
movq (%rax,%r13,8), %rsi
movapd %xmm1, %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6139a
movq %rax, %r12
cmpl $0x0, 0x14(%rsp)
jle 0x4ab4f
xorpd %xmm3, %xmm3
xorl %ebp, %ebp
xorpd %xmm4, %xmm4
movsd (%rsp), %xmm1
movsd 0x965c3(%rip), %xmm2    # 0xe1090
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rax
movslq 0x70(%rax), %rax
movsd (%r14,%rax,8), %xmm5
ucomisd %xmm2, %xmm5
jne 0x4aae8
jnp 0x4ab40
movsd (%r12,%rax,8), %xmm0
ucomisd %xmm1, %xmm0
ja 0x4ab40
mulsd %xmm0, %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm3, 0x30(%rsp)
movsd %xmm4, 0x28(%rsp)
movsd %xmm5, 0x20(%rsp)
callq 0x22100
movsd 0x28(%rsp), %xmm4
movsd 0x30(%rsp), %xmm3
movsd 0x96567(%rip), %xmm2    # 0xe1090
movsd (%rsp), %xmm1
movsd 0x20(%rsp), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm5, %xmm4
addsd %xmm0, %xmm3
incq %rbp
movslq 0x14(%rsp), %rax
cmpq %rax, %rbp
jl 0x4aacd
jmp 0x4ab64
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
movsd (%rsp), %xmm1
movsd 0x9652c(%rip), %xmm2    # 0xe1090
ucomisd 0x9650c(%rip), %xmm3    # 0xe1078
jbe 0x4ab7f
divsd %xmm3, %xmm4
movq 0x410(%rbx), %rax
movsd %xmm4, (%rax,%r13,8)
testq %r12, %r12
je 0x4ab99
movq %r12, %rdi
callq 0x21c10
movsd 0x964fc(%rip), %xmm2    # 0xe1090
movsd (%rsp), %xmm1
incq %r13
movq (%rbx), %rdi
movslq 0x14(%rdi), %rax
cmpq %rax, %r13
jl 0x4aa79
movq %r14, %rdi
callq 0x21c10
movapd 0x98874(%rip), %xmm0    # 0xe3430
movupd %xmm0, 0x418(%rbx)
movupd %xmm0, 0x428(%rbx)
movupd %xmm0, 0x438(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x8cf66
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8cf66
movq %rbx, %rdi
callq 0x220b0