// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::PadWithZero(int, int, int, int, int, int)
void R3Grid::
PadWithZero(int xresolution, int yresolution, int zresolution,
            int xoffset, int yoffset, int zoffset)
{
  // Add zeros to achieve desired resolution
  if ((XResolution() >= xresolution) && (YResolution() >= yresolution) && (ZResolution() >= zresolution)) return;

  // Copy this grid
  R3Grid copy(*this);

  // Set grid resolution
  grid_resolution[0] = xresolution;
  grid_resolution[1] = yresolution;
  grid_resolution[2] = zresolution;
  grid_row_size = xresolution;
  grid_sheet_size = grid_row_size * yresolution;
  grid_size = grid_sheet_size * zresolution;

  // Allocate grid values
  if (grid_values) delete [] grid_values;
  if (grid_size == 0) grid_values = NULL;
  else grid_values = new RNScalar [ grid_size ];
  assert(!grid_size || grid_values);

  // Set all values to zero
  for (int i = 0; i < grid_size; i++) grid_values[i] = 0;

  // Copy original values
  for (int iz = 0; iz < copy.ZResolution(); iz++) {
    if (iz + zoffset >= zresolution) continue; 
    for (int iy = 0; iy < copy.YResolution(); iy++) {
      if (iy + yoffset >= yresolution) continue; 
      for (int ix = 0; ix < copy.XResolution(); ix++) {
        if (ix + xoffset >= xresolution) continue; 
        RNScalar value = copy.GridValue(ix, iy, iz);
       SetGridValue(ix + xoffset, iy + yoffset, iz + zoffset, value);
      }
    }
  }
}

// Assembly:
subq $0x2d8, %rsp            # imm = 0x2D8
movl 0x2e0(%rsp), %eax
movq %rdi, 0x2d0(%rsp)
movl %esi, 0x2cc(%rsp)
movl %edx, 0x2c8(%rsp)
movl %ecx, 0x2c4(%rsp)
movl %r8d, 0x2c0(%rsp)
movl %r9d, 0x2bc(%rsp)
movq 0x2d0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x138c0
cmpl 0x2cc(%rsp), %eax
jl 0x5ec01
movq 0x38(%rsp), %rdi
callq 0x138e0
cmpl 0x2c8(%rsp), %eax
jl 0x5ec01
movq 0x38(%rsp), %rdi
callq 0x13900
cmpl 0x2c4(%rsp), %eax
jl 0x5ec01
jmp 0x5eed6
movq 0x38(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x568c0
movq 0x38(%rsp), %rax
movl 0x2cc(%rsp), %ecx
movl %ecx, 0x238(%rax)
movl 0x2c8(%rsp), %ecx
movl %ecx, 0x23c(%rax)
movl 0x2c4(%rsp), %ecx
movl %ecx, 0x240(%rax)
movl 0x2cc(%rsp), %ecx
movl %ecx, 0x244(%rax)
movl 0x244(%rax), %ecx
imull 0x2c8(%rsp), %ecx
movl %ecx, 0x248(%rax)
movl 0x248(%rax), %ecx
imull 0x2c4(%rsp), %ecx
movl %ecx, 0x24c(%rax)
cmpq $0x0, 0x230(%rax)
je 0x5ec9e
movq 0x38(%rsp), %rax
movq 0x230(%rax), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0x5ec9c
movq 0x30(%rsp), %rdi
callq 0xf670
jmp 0x5ec9e
movq 0x38(%rsp), %rax
cmpl $0x0, 0x24c(%rax)
jne 0x5ecbe
movq 0x38(%rsp), %rax
movq $0x0, 0x230(%rax)
jmp 0x5ed1c
movq 0x38(%rsp), %rax
movslq 0x24c(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0xf030
movq %rax, 0x28(%rsp)
jmp 0x5ecec
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x230(%rax)
jmp 0x5ed1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x56960
jmp 0x5eede
movl $0x0, 0x58(%rsp)
movq 0x38(%rsp), %rcx
movl 0x58(%rsp), %eax
cmpl 0x24c(%rcx), %eax
jge 0x5ed5b
movq 0x38(%rsp), %rax
movq 0x230(%rax), %rax
movslq 0x58(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x5ed24
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movl %eax, 0x20(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x13900
movl %eax, 0x24(%rsp)
jmp 0x5ed7b
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5eecc
movl 0x54(%rsp), %eax
addl 0x2e0(%rsp), %eax
cmpl 0x2c4(%rsp), %eax
jl 0x5eda4
jmp 0x5eebc
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x138e0
movl %eax, 0x1c(%rsp)
jmp 0x5edc4
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5eeba
movl 0x50(%rsp), %eax
addl 0x2bc(%rsp), %eax
cmpl 0x2c8(%rsp), %eax
jl 0x5eded
jmp 0x5eeaa
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x138c0
movl %eax, 0x14(%rsp)
jmp 0x5ee0d
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5eea8
movl 0x4c(%rsp), %eax
addl 0x2c0(%rsp), %eax
cmpl 0x2cc(%rsp), %eax
jl 0x5ee33
jmp 0x5ee98
movl 0x4c(%rsp), %esi
movl 0x50(%rsp), %edx
movl 0x54(%rsp), %ecx
leaq 0x68(%rsp), %rdi
callq 0x6bad0
movsd %xmm0, 0x8(%rsp)
jmp 0x5ee51
movq 0x38(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl 0x4c(%rsp), %esi
movl 0x2c0(%rsp), %eax
addl %eax, %esi
movl 0x50(%rsp), %edx
movl 0x2bc(%rsp), %eax
addl %eax, %edx
movl 0x54(%rsp), %ecx
movl 0x2e0(%rsp), %eax
addl %eax, %ecx
movsd 0x40(%rsp), %xmm0
callq 0x6bc60
jmp 0x5ee96
jmp 0x5ee98
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x5edf5
jmp 0x5eeaa
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x5edac
jmp 0x5eebc
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x5ed63
leaq 0x68(%rsp), %rdi
callq 0x56960
addq $0x2d8, %rsp            # imm = 0x2D8
retq
movq 0x60(%rsp), %rdi
callq 0xf890
nopl (%rax,%rax)