// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::Laplacian(int)
void R2Grid::
Laplacian(RNDimension dim)
{
  // Set up 1D Laplacian filter
  const RNScalar filter[3] = { -1, 2, -1 };

  // Make temporary copy of grid
  R2Grid copy(*this);

  // Mark boundaries unknown
  for (int i = 0; i < XResolution(); i++) { 
    SetGridValue(i, 0, R2_GRID_UNKNOWN_VALUE);
    SetGridValue(i, YResolution()-1, R2_GRID_UNKNOWN_VALUE);
  }
  for (int j = 0; j < YResolution(); j++) { 
    SetGridValue(0, j, R2_GRID_UNKNOWN_VALUE);
    SetGridValue(XResolution()-1, j, R2_GRID_UNKNOWN_VALUE);
  }

  // Convolve grid with 3x1 filter
  for (int j = 1; j < YResolution()-1; j++) { 
    for (int i = 1; i < XResolution()-1; i++) { 
      RNScalar value = copy.GridValue(i, j);
      if (value != R2_GRID_UNKNOWN_VALUE) {
        RNScalar sum = 0;
        RNBoolean unknown = FALSE;
        for (int k = -1; k <= 1; k++) {
          if (dim == 0) value = copy.GridValue(i + k, j);
          else value = copy.GridValue(i, j + k);
          if (value == R2_GRID_UNKNOWN_VALUE) { unknown = TRUE; break; }
          else sum += filter[k+1] * value;
        }
        if (unknown) SetGridValue(i, j, R2_GRID_UNKNOWN_VALUE);
        else SetGridValue(i, j, sum);
      }
    }
  }
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movl %esi, 0x17c(%rsp)
movq 0x180(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq 0x88676(%rip), %rax     # 0x1361b0
movq %rax, 0x160(%rsp)
movq 0x8866f(%rip), %rax     # 0x1361b8
movq %rax, 0x168(%rsp)
movq 0x88668(%rip), %rax     # 0x1361c0
movq %rax, 0x170(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xa73a0
movl $0x0, 0x8c(%rsp)
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %eax
movl %eax, 0x48(%rsp)
callq 0xb9260
movl %eax, 0x4c(%rsp)
jmp 0xadb93
movl 0x48(%rsp), %eax
movl 0x4c(%rsp), %ecx
cmpl %ecx, %eax
jge 0xadc34
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %esi
xorl %edx, %edx
movsd 0x862f7(%rip), %xmm0    # 0x133eb0
callq 0x6bc00
jmp 0xadbc0
movq 0x50(%rsp), %rdi
movl 0x8c(%rsp), %eax
movl %eax, 0x40(%rsp)
callq 0xb9280
movl %eax, 0x44(%rsp)
jmp 0xadbdb
movl 0x40(%rsp), %esi
movq 0x50(%rsp), %rdi
movl 0x44(%rsp), %edx
decl %edx
movsd 0x862be(%rip), %xmm0    # 0x133eb0
callq 0x6bc00
jmp 0xadbf9
jmp 0xadbfb
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0xadb78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xa7690
jmp 0xadec9
movl $0x0, 0x78(%rsp)
movq 0x50(%rsp), %rdi
movl 0x78(%rsp), %eax
movl %eax, 0x38(%rsp)
callq 0xb9280
movl %eax, 0x3c(%rsp)
jmp 0xadc54
movl 0x38(%rsp), %eax
movl 0x3c(%rsp), %ecx
cmpl %ecx, %eax
jge 0xadcb7
movq 0x50(%rsp), %rdi
movl 0x78(%rsp), %edx
xorl %esi, %esi
movsd 0x8623d(%rip), %xmm0    # 0x133eb0
callq 0x6bc00
jmp 0xadc7a
movq 0x50(%rsp), %rdi
callq 0xb9260
movl %eax, 0x34(%rsp)
jmp 0xadc8a
movq 0x50(%rsp), %rdi
movl 0x34(%rsp), %esi
decl %esi
movl 0x78(%rsp), %edx
movsd 0x8620f(%rip), %xmm0    # 0x133eb0
callq 0x6bc00
jmp 0xadca8
jmp 0xadcaa
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0xadc3c
movl $0x1, 0x74(%rsp)
movq 0x50(%rsp), %rdi
movl 0x74(%rsp), %eax
movl %eax, 0x2c(%rsp)
callq 0xb9280
movl %eax, 0x30(%rsp)
jmp 0xadcd7
movl 0x2c(%rsp), %eax
movl 0x30(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xadeb4
movl $0x1, 0x70(%rsp)
movq 0x50(%rsp), %rdi
movl 0x70(%rsp), %eax
movl %eax, 0x24(%rsp)
callq 0xb9260
movl %eax, 0x28(%rsp)
jmp 0xadd0a
movl 0x24(%rsp), %eax
movl 0x28(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xadea2
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
leaq 0x90(%rsp), %rdi
callq 0xb92a0
movsd %xmm0, 0x18(%rsp)
jmp 0xadd3a
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x8615c(%rip), %xmm1    # 0x133eb0
ucomisd %xmm1, %xmm0
jne 0xadd61
jp 0xadd61
jmp 0xade90
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
cmpl $0x1, 0x58(%rsp)
jg 0xade4d
cmpl $0x0, 0x17c(%rsp)
jne 0xaddc0
movl 0x70(%rsp), %esi
movl 0x58(%rsp), %eax
addl %eax, %esi
movl 0x74(%rsp), %edx
leaq 0x90(%rsp), %rdi
callq 0xb92a0
movsd %xmm0, 0x10(%rsp)
jmp 0xaddb2
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0xaddef
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movl 0x58(%rsp), %eax
addl %eax, %edx
leaq 0x90(%rsp), %rdi
callq 0xb92a0
movsd %xmm0, 0x8(%rsp)
jmp 0xadde3
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
movsd 0x860b3(%rip), %xmm1    # 0x133eb0
ucomisd %xmm1, %xmm0
jne 0xade0f
jp 0xade0f
movl $0x1, 0x5c(%rsp)
jmp 0xade4d
movl 0x58(%rsp), %eax
addl $0x1, %eax
cltq
movsd 0x160(%rsp,%rax,8), %xmm0
movsd 0x68(%rsp), %xmm2
movsd 0x60(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0xade3d
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0xadd7a
cmpl $0x0, 0x5c(%rsp)
je 0xade72
movq 0x50(%rsp), %rdi
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movsd 0x86047(%rip), %xmm0    # 0x133eb0
callq 0x6bc00
jmp 0xade70
jmp 0xade8e
movq 0x50(%rsp), %rdi
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movsd 0x60(%rsp), %xmm0
callq 0x6bc00
jmp 0xade8c
jmp 0xade8e
jmp 0xade90
jmp 0xade92
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0xadcf2
jmp 0xadea4
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0xadcbf
leaq 0x90(%rsp), %rdi
callq 0xa7690
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x80(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)