// File: /workspace/github_cpp_makefile_star2_O2/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 0x449e2
jnp 0x44bcf
movq %rdi, %rbx
movsd 0x84aa3(%rip), %xmm1    # 0xc9490
movsd %xmm0, (%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq (%rdi), %rax
movslq 0x14(%rax), %r15
leaq (,%r15,8), %rax
testq %r15, %r15
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x21040
movq %rax, %r14
movq 0x410(%rbx), %rax
xorl %ecx, %ecx
testl %r15d, %r15d
movl $0x0, %edx
cmovgl %r15d, %edx
cmpq %rcx, %rdx
je 0x44a47
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
incq %rcx
jmp 0x44a32
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
mulsd 0x84b7c(%rip), %xmm1    # 0xc95e0
movsd %xmm1, (%rsp)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x8001e
movsd (%rsp), %xmm1
xorl %r13d, %r13d
movsd 0x84602(%rip), %xmm2    # 0xc9088
movq (%rbx), %rdi
movslq 0x14(%rdi), %rax
cmpq %rax, %r13
jge 0x44ba1
movq 0x410(%rbx), %rax
movsd (%rax,%r13,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x44aaf
jnp 0x44b99
movq 0x8(%rdi), %rax
movq (%rax,%r13,8), %rsi
movapd %xmm1, %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x57fd8
movq %rax, %r12
xorpd %xmm3, %xmm3
xorl %ebp, %ebp
xorpd %xmm4, %xmm4
movsd (%rsp), %xmm1
movsd 0x845a9(%rip), %xmm2    # 0xc9088
movslq 0x1c(%rsp), %rax
cmpq %rax, %rbp
jge 0x44b64
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movslq 0x70(%rax), %rax
movsd (%r14,%rax,8), %xmm5
ucomisd %xmm2, %xmm5
jne 0x44b04
jnp 0x44b5c
movsd (%r12,%rax,8), %xmm0
ucomisd %xmm1, %xmm0
ja 0x44b5c
mulsd %xmm0, %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm3, 0x30(%rsp)
movsd %xmm4, 0x28(%rsp)
movsd %xmm5, 0x20(%rsp)
callq 0x22110
movsd 0x28(%rsp), %xmm4
movsd 0x30(%rsp), %xmm3
movsd 0x84543(%rip), %xmm2    # 0xc9088
movsd (%rsp), %xmm1
movsd 0x20(%rsp), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm5, %xmm3
addsd %xmm0, %xmm4
incq %rbp
jmp 0x44adf
ucomisd 0x862f4(%rip), %xmm4    # 0xcae60
jbe 0x44b7f
divsd %xmm4, %xmm3
movq 0x410(%rbx), %rax
movsd %xmm3, (%rax,%r13,8)
testq %r12, %r12
je 0x44b99
movq %r12, %rdi
callq 0x21c00
movsd 0x844f4(%rip), %xmm2    # 0xc9088
movsd (%rsp), %xmm1
incq %r13
jmp 0x44a86
movq %r14, %rdi
callq 0x21c00
movaps 0x86850(%rip), %xmm0    # 0xcb400
movups %xmm0, 0x418(%rbx)
movups %xmm0, 0x428(%rbx)
movups %xmm0, 0x438(%rbx)
leaq 0x10(%rsp), %rdi
callq 0x8008c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8008c
movq %rbx, %rdi
callq 0x220c0
nop