// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::Sharpen(double)
void R3Mesh::
Sharpen(RNScalar factor)
{
  // Allocate buffer for copy of vertex positions
  R3Point *positions = new R3Point [ NVertices() ];
  if (!positions) RNAbort("Unable to allocate vertex positions");
  
  // Iteratively average vertex positions
  for (int iter = 0; iter < factor; iter++) {
    // Copy vertex positions
    for (int i = 0; i < NVertices(); i++) {
      R3MeshVertex *vertex = Vertex(i);
      positions[i] = VertexPosition(vertex);
    }

    // Update vertex positions
    for (int i = 0; i < NVertices(); i++) {
      R3MeshVertex *vertex = Vertex(i);
      RNScalar weight = 1;
      R3Point position = positions[vertex->id];
      RNLength radius = VertexAverageEdgeLength(vertex);
      for (int j = 0; j < VertexValence(vertex); j++) {
        R3MeshEdge *edge = EdgeOnVertex(vertex, j);
        R3MeshVertex *neighbor_vertex = VertexAcrossEdge(edge, vertex);
        const R3Point& neighbor_position = positions[neighbor_vertex->id];
        RNLength length = EdgeLength(edge);
        RNLength sigma = length / radius;
        RNScalar w = exp((length * length) / (-2.0 * sigma * sigma));
        position += w * neighbor_position;
        weight += w;
      }

      // Update vertex position
      R3Point smooth_position = position / weight;
      R3Point sharpen_position = 2 * positions[vertex->id] - smooth_position.Vector();
      SetVertexPosition(vertex, sharpen_position);
    }
  }
  
  // Delete copy of vertex positions
  delete [] positions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
movslq 0x14(%rdi), %r12
movl $0x18, %ecx
movq %r12, %rax
mulq %rcx
movq $-0x1, %r15
cmovnoq %rax, %r15
movq %r15, %rdi
callq 0xe030
movq %rax, %r13
testq %r12, %r12
je 0x142d3
shlq $0x3, %r12
leaq (%r12,%r12,2), %r14
xorl %r12d, %r12d
leaq (%r12,%r13), %rdi
callq 0x3c530
addq $0x18, %r12
cmpq %r12, %r14
jne 0x142c1
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x144ea
movl 0x14(%rbx), %eax
xorl %r15d, %r15d
movq %r13, 0x18(%rsp)
testl %eax, %eax
jle 0x144cf
movq %r13, %r12
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rsi
addq $0x18, %rsi
movq %r13, %rdi
callq 0x3c89a
incq %r14
movslq 0x14(%rbx), %rax
addq $0x18, %r13
cmpq %rax, %r14
jl 0x14300
testl %eax, %eax
movq %r12, %r13
jle 0x144cf
movq %r15, 0x10(%rsp)
xorl %ecx, %ecx
leaq 0x70(%rsp), %r15
movq 0x8(%rbx), %rax
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx,8), %rbp
movslq 0x70(%rbp), %rax
leaq (%rax,%rax,2), %rax
leaq (,%rax,8), %rsi
addq %r13, %rsi
movq %r15, %rdi
callq 0x3c542
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x12d4e
movsd %xmm0, 0x28(%rsp)
cmpl $0x0, 0x14(%rbp)
movsd 0x8dcb8(%rip), %xmm0    # 0xa2038
jle 0x1443d
xorl %r14d, %r14d
movsd 0x8dca7(%rip), %xmm0    # 0xa2038
movq 0x8(%rbp), %rax
movq (%rax,%r14,8), %r13
movq 0x8(%r13), %rax
cmpq %rbp, %rax
jne 0x143a6
movq 0x10(%r13), %rax
movsd %xmm0, 0x38(%rsp)
movslq 0x70(%rax), %r15
testb $0x2, 0x38(%r13)
jne 0x143c6
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
callq *0x2b8(%rax)
leaq (%r15,%r15,2), %rax
leaq (%r12,%rax,8), %r15
movsd 0x28(%r13), %xmm0
movapd %xmm0, %xmm1
divsd 0x28(%rsp), %xmm1
mulsd %xmm0, %xmm0
movapd %xmm1, %xmm2
mulsd 0x8de12(%rip), %xmm2    # 0xa2200
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
callq 0xe7f0
movsd %xmm0, 0x30(%rsp)
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x3cf76
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x3ce6c
movsd 0x38(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
incq %r14
movslq 0x14(%rbp), %rax
cmpq %rax, %r14
jl 0x14391
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x3cf98
movslq 0x70(%rbp), %rax
leaq (%rax,%rax,2), %rax
leaq (%r12,%rax,8), %rsi
leaq 0x58(%rsp), %rdi
movsd 0x8dda5(%rip), %xmm0    # 0xa2208
callq 0x3cf76
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x3cfc6
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movq %r14, %rdx
callq 0x3cf53
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq 0x18(%rsp), %r13
callq 0x13858
movq 0x20(%rsp), %rcx
incq %rcx
movslq 0x14(%rbx), %rax
cmpq %rax, %rcx
jl 0x1433b
movq 0x10(%rsp), %r15
incl %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x142f2
movq %r13, %rdi
callq 0xe5b0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r13, %rdi
movq %r15, %rsi
callq 0xe8c0
movq %rbx, %rdi
callq 0xe7e0