// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movsd %xmm0, (%rsp)
movq %rdi, %rbx
movslq 0x14(%rdi), %r12
pushq $0x18
popq %rcx
movq %r12, %rax
mulq %rcx
pushq $-0x1
popq %r15
cmovnoq %rax, %r15
movq %r15, %rdi
callq 0xe030
movq %rax, %r14
testq %r12, %r12
je 0x135db
imulq $0x18, %r12, %r12
xorl %r13d, %r13d
leaq (%r14,%r13), %rdi
callq 0x37b4a
addq $0x18, %r13
cmpq %r13, %r12
jne 0x135c9
xorl %eax, %eax
leaq 0x90(%rsp), %r12
cvtsi2sd %eax, %xmm0
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x13781
movq %rax, 0x8(%rsp)
movq %r14, %rbp
xorl %r15d, %r15d
movslq 0x14(%rbx), %rax
cmpq %rax, %r15
jge 0x13629
movq 0x8(%rbx), %rax
movq (%rax,%r15,8), %rsi
addq $0x18, %rsi
movq %rbp, %rdi
callq 0x37e36
incq %r15
addq $0x18, %rbp
jmp 0x13603
xorl %ecx, %ecx
cltq
cmpq %rax, %rcx
jge 0x13775
movq 0x8(%rbx), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %rbp
movslq 0x70(%rbp), %rax
imulq $0x18, %rax, %rsi
addq %r14, %rsi
leaq 0x30(%rsp), %rdi
callq 0x37b5c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x12380
movsd %xmm0, 0x18(%rsp)
xorl %r15d, %r15d
movsd 0x7f994(%rip), %xmm0    # 0x93008
movslq 0x14(%rbp), %rax
cmpq %rax, %r15
jge 0x13708
movsd %xmm0, 0x28(%rsp)
movq 0x8(%rbp), %rax
movq (%rax,%r15,8), %rsi
movq 0x8(%rsi), %rax
cmpq %rbp, %rax
jne 0x1369c
movq 0x10(%rsi), %rax
movslq 0x70(%rax), %rax
imulq $0x18, %rax, %r13
addq %r14, %r13
movq %rbx, %rdi
callq 0x10db2
movapd %xmm0, %xmm1
divsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm0
movapd %xmm1, %xmm2
mulsd 0x7fb37(%rip), %xmm2    # 0x93200
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
callq 0xe820
movsd %xmm0, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x382c0
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x381b6
movsd 0x28(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
incq %r15
jmp 0x13674
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x382e2
movslq 0x70(%rbp), %rax
imulq $0x18, %rax, %rsi
addq %r14, %rsi
leaq 0x48(%rsp), %rdi
movsd 0x7fadb(%rip), %xmm0    # 0x93208
callq 0x382c0
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x212f8
leaq 0x78(%rsp), %r15
movq %r15, %rdi
leaq 0x48(%rsp), %rsi
movq %r13, %rdx
callq 0x3829d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x12ccc
movq 0x10(%rsp), %rcx
incq %rcx
movl 0x14(%rbx), %eax
jmp 0x1362b
movq 0x8(%rsp), %rax
incl %eax
jmp 0x135e5
movq %r14, %rdi
callq 0xe5d0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0xe8f0
movq %rbx, %rdi
callq 0xe810
nop