// File: /workspace/github_cpp_makefile_star2_O3/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 0x4a330
jnp 0x4a522
movq %rdi, %rbx
movsd %xmm0, (%rsp)
movq (%rdi), %rax
movslq 0x14(%rax), %r15
leaq (,%r15,8), %rax
testq %r15, %r15
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x21040
movq %rax, %r14
testq %r15, %r15
jle 0x4a37e
movq 0x410(%rbx), %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%r14,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x4a36b
leaq 0x8(%rsp), %rdi
callq 0x8bd1c
movq (%rbx), %rdi
cmpl $0x0, 0x14(%rdi)
movsd (%rsp), %xmm1
jle 0x4a4f0
movsd 0x950ee(%rip), %xmm0    # 0xdf490
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
mulsd 0x95228(%rip), %xmm1    # 0xdf5e0
xorl %r13d, %r13d
movsd 0x94ccd(%rip), %xmm2    # 0xdf090
leaq 0x8(%rsp), %r15
movsd %xmm1, (%rsp)
movq 0x410(%rbx), %rax
movsd (%rax,%r13,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x4a3e6
jnp 0x4a4dd
movq 0x8(%rdi), %rax
movq (%rax,%r13,8), %rsi
movapd %xmm1, %xmm0
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x607cc
movq %rax, %r12
movl 0x14(%rsp), %eax
testl %eax, %eax
movsd (%rsp), %xmm1
movsd 0x94c7e(%rip), %xmm2    # 0xdf090
jle 0x4a4c3
xorpd %xmm3, %xmm3
xorl %ebp, %ebp
xorpd %xmm4, %xmm4
movq 0x8(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movslq 0x70(%rcx), %rcx
movsd (%r14,%rcx,8), %xmm5
ucomisd %xmm2, %xmm5
jne 0x4a43d
jnp 0x4a499
movsd (%r12,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
ja 0x4a499
mulsd %xmm0, %xmm0
divsd 0x18(%rsp), %xmm0
movsd %xmm3, 0x30(%rsp)
movsd %xmm4, 0x28(%rsp)
movsd %xmm5, 0x20(%rsp)
callq 0x220f0
movsd 0x28(%rsp), %xmm4
movsd 0x30(%rsp), %xmm3
movsd 0x94c12(%rip), %xmm2    # 0xdf090
movsd (%rsp), %xmm1
movsd 0x20(%rsp), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm5, %xmm4
addsd %xmm0, %xmm3
movl 0x14(%rsp), %eax
incq %rbp
movslq %eax, %rcx
cmpq %rcx, %rbp
jl 0x4a422
ucomisd 0x94bc8(%rip), %xmm3    # 0xdf078
jbe 0x4a4c3
divsd %xmm3, %xmm4
movq 0x410(%rbx), %rax
movsd %xmm4, (%rax,%r13,8)
testq %r12, %r12
je 0x4a4dd
movq %r12, %rdi
callq 0x21c00
movsd 0x94bb8(%rip), %xmm2    # 0xdf090
movsd (%rsp), %xmm1
incq %r13
movq (%rbx), %rdi
movslq 0x14(%rdi), %rax
cmpq %rax, %r13
jl 0x4a3cd
movq %r14, %rdi
callq 0x21c00
movapd 0x96f20(%rip), %xmm0    # 0xe1420
movupd %xmm0, 0x418(%rbx)
movupd %xmm0, 0x428(%rbx)
movupd %xmm0, 0x438(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x8bd86
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8bd86
movq %rbx, %rdi
callq 0x220a0