// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::Resample(int, int, int)
void R3Grid::
Resample(int xresolution, int yresolution, int zresolution)
{
  // Resample grid values at new resolution
  RNScalar *new_grid_values = NULL;
  int new_grid_size = xresolution * yresolution * zresolution;
  if (new_grid_size > 0) {
    new_grid_values = new RNScalar [ new_grid_size ];
    assert(new_grid_values);
    RNScalar *new_grid_valuesp = new_grid_values;
    RNScalar xscale = (RNScalar) (grid_resolution[0]-1) / (RNScalar) (xresolution - 1);
    RNScalar yscale = (RNScalar) (grid_resolution[1]-1) / (RNScalar) (yresolution - 1);
    RNScalar zscale = (RNScalar) (grid_resolution[2]-1) / (RNScalar) (zresolution - 1);
    for (int k = 0; k < zresolution; k++) {
      RNScalar z = (k == zresolution-1) ? grid_resolution[2]-1 : k * zscale;
      for (int j = 0; j < yresolution; j++) {
        RNScalar y = (j == yresolution-1) ? grid_resolution[1]-1 : j * yscale;
        for (int i = 0; i < xresolution; i++) {
          RNScalar x = (i == xresolution-1) ? grid_resolution[0]-1 : i * xscale;
          *(new_grid_valuesp++) = GridValue(x, y, z);
        }
      }
    }
  }

  // Reset grid variables
  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;
  if (grid_values) delete [] grid_values;
  grid_values = new_grid_values;

  // Reset transformations
  SetWorldToGridTransformation(WorldBox());
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movl %esi, 0xec(%rsp)
movl %edx, 0xe8(%rsp)
movl %ecx, 0xe4(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0xd8(%rsp)
movl 0xec(%rsp), %eax
imull 0xe8(%rsp), %eax
imull 0xe4(%rsp), %eax
movl %eax, 0xd4(%rsp)
cmpl $0x0, 0xd4(%rsp)
jle 0x5ea81
movslq 0xd4(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xf030
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0xd8(%rsp)
movq 0xd8(%rsp), %rcx
movq %rcx, 0xc8(%rsp)
movl 0x238(%rax), %ecx
subl $0x1, %ecx
cvtsi2sd %ecx, %xmm0
movl 0xec(%rsp), %ecx
subl $0x1, %ecx
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
movl 0x23c(%rax), %ecx
subl $0x1, %ecx
cvtsi2sd %ecx, %xmm0
movl 0xe8(%rsp), %ecx
subl $0x1, %ecx
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movl 0x240(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movl 0xe4(%rsp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
movl $0x0, 0xac(%rsp)
movl 0xac(%rsp), %eax
cmpl 0xe4(%rsp), %eax
jge 0x5ea7f
movl 0xac(%rsp), %eax
movl 0xe4(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x5e8e8
movq 0x30(%rsp), %rax
movl 0x240(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0x5e900
cvtsi2sdl 0xac(%rsp), %xmm0
mulsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0xe8(%rsp), %eax
jge 0x5ea67
movl 0x9c(%rsp), %eax
movl 0xe8(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x5e95d
movq 0x30(%rsp), %rax
movl 0x23c(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x5e975
cvtsi2sdl 0x9c(%rsp), %xmm0
mulsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
movl $0x0, 0x8c(%rsp)
movl 0x8c(%rsp), %eax
cmpl 0xec(%rsp), %eax
jge 0x5ea4f
movl 0x8c(%rsp), %eax
movl 0xec(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x5e9d2
movq 0x30(%rsp), %rax
movl 0x238(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x5e9ea
cvtsi2sdl 0x8c(%rsp), %xmm0
mulsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x30(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x80(%rsp), %xmm0
movsd 0x90(%rsp), %xmm1
movsd 0xa0(%rsp), %xmm2
callq 0x56e50
movq 0xc8(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0xc8(%rsp)
movsd %xmm0, (%rax)
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x5e98f
jmp 0x5ea51
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x5e91a
jmp 0x5ea69
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x5e8a5
jmp 0x5ea81
movq 0x30(%rsp), %rax
movl 0xec(%rsp), %ecx
movl %ecx, 0x238(%rax)
movl 0xe8(%rsp), %ecx
movl %ecx, 0x23c(%rax)
movl 0xe4(%rsp), %ecx
movl %ecx, 0x240(%rax)
movl 0xec(%rsp), %ecx
movl %ecx, 0x244(%rax)
movl 0x244(%rax), %ecx
imull 0xe8(%rsp), %ecx
movl %ecx, 0x248(%rax)
movl 0x248(%rax), %ecx
imull 0xe4(%rsp), %ecx
movl %ecx, 0x24c(%rax)
cmpq $0x0, 0x230(%rax)
je 0x5eb0f
movq 0x30(%rsp), %rax
movq 0x230(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x5eb0d
movq 0x10(%rsp), %rdi
callq 0xf670
jmp 0x5eb0f
movq 0x30(%rsp), %rsi
movq 0xd8(%rsp), %rax
movq %rax, 0x230(%rsi)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x6bb40
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x559e0
jmp 0x5eb43
leaq 0x48(%rsp), %rdi
callq 0x36a80
addq $0xf8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x36a80
movq 0x40(%rsp), %rdi
callq 0xf890
nopw (%rax,%rax)