// File: /workspace/github_cpp_makefile_star2_O1/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, (%rsp)
testq %r12, %r12
je 0x142aa
shlq $0x3, %r12
leaq (%r12,%r12,2), %r14
xorl %r12d, %r12d
movq (%rsp), %rax
leaq (%rax,%r12), %rdi
callq 0x3ca24
addq $0x18, %r12
cmpq %r12, %r14
jne 0x14294
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq (%rsp), %r15
jbe 0x144c8
xorl %eax, %eax
leaq 0xa0(%rsp), %r13
movq %rbx, 0x10(%rsp)
movq %r13, %r12
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x14(%rbx)
jle 0x14309
movq %r15, %r13
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rsi
addq $0x18, %rsi
movq %r13, %rdi
callq 0x3cd94
incq %r14
movslq 0x14(%rbx), %rax
addq $0x18, %r13
cmpq %rax, %r14
jl 0x142e5
cmpl $0x0, 0x14(%rbx)
movq %r12, %r13
jle 0x144aa
xorl %ecx, %ecx
movq 0x8(%rbx), %rax
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx,8), %rbp
movslq 0x70(%rbp), %rax
leaq (%rax,%rax,2), %rax
leaq (%r15,%rax,8), %rsi
movq %r13, %rdi
callq 0x3ca36
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x12ce6
movsd %xmm0, 0x28(%rsp)
cmpl $0x0, 0x14(%rbp)
movsd 0x8dce2(%rip), %xmm0    # 0xa2038
jle 0x14417
xorl %r14d, %r14d
movsd 0x8dcd1(%rip), %xmm0    # 0xa2038
movq 0x8(%rbp), %rax
movq (%rax,%r14,8), %r13
movq 0x8(%r13), %rax
cmpq %rbp, %rax
jne 0x1437c
movq 0x10(%r13), %rax
movsd %xmm0, 0x38(%rsp)
movslq 0x70(%rax), %r15
testb $0x2, 0x38(%r13)
jne 0x1439e
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
movq %r13, %rsi
callq *0x2b8(%rax)
leaq (%r15,%r15,2), %rax
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movsd 0x28(%r13), %xmm0
movapd %xmm0, %xmm1
divsd 0x28(%rsp), %xmm1
mulsd %xmm0, %xmm0
movapd %xmm1, %xmm2
mulsd 0x8de36(%rip), %xmm2    # 0xa2200
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
callq 0xe7f0
movsd %xmm0, 0x30(%rsp)
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3d470
movq %r12, %r13
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3d366
movsd 0x38(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
incq %r14
movslq 0x14(%rbp), %rax
cmpq %rax, %r14
jl 0x14367
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x3d492
movslq 0x70(%rbp), %rax
leaq (%rax,%rax,2), %rax
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movsd 0x8ddc4(%rip), %xmm0    # 0xa2208
callq 0x3d470
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x3d4be
leaq 0x88(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3d44d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq (%rsp), %r15
callq 0x13808
movq 0x20(%rsp), %rcx
incq %rcx
movslq 0x14(%rbx), %rax
cmpq %rax, %rcx
jl 0x14318
movq 0x18(%rsp), %rax
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x142d1
movq %r15, %rdi
callq 0xe5b0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq (%rsp), %rdi
movq %r15, %rsi
callq 0xe8c0
movq %rbx, %rdi
callq 0xe7e0
nop