// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::RasterizeGridPoint(double, double, double, double, double, int)
void R3Grid::
RasterizeGridPoint(RNScalar x, RNScalar y, RNScalar z, RNScalar value, RNLength sigma, int operation)
{
  // Check if within bounds
  if ((x < 0) || (x > grid_resolution[0]-1)) return;
  if ((y < 0) || (y > grid_resolution[1]-1)) return;
  if ((z < 0) || (z > grid_resolution[2]-1)) return;

  // Determine filter extent
  int f = (int) (3 * sigma + 0.5);
  int xmin = (int) (x - f + 0.5);
  int xmax = (int) (x + f + 0.5);
  int ymin = (int) (y - f + 0.5);
  int ymax = (int) (y + f + 0.5);
  int zmin = (int) (z - f + 0.5);
  int zmax = (int) (z + f + 0.5);
  if (xmin < 0) xmin = 0;
  if (xmax > XResolution()-1) xmax = XResolution()-1;
  if (ymin < 0) ymin = 0;
  if (ymax > YResolution()-1) ymax = YResolution()-1;
  if (zmin < 0) zmin = 0;
  if (zmax > ZResolution()-1) zmax = ZResolution()-1;

  // Compute Gaussian weighting variables
  double a = sqrt(2.0 * RN_PI) * sigma;
  double fac = 1.0 / (a * a * a);
  double denom = 2.0 * sigma * sigma;

  // Compute total weight of Gaussian filter
  RNScalar weight = 0.0;
  for (int k = zmin; k <= zmax; k++) {
    for (int j = ymin; j <= ymax; j++) {
      for (int i = xmin; i <= xmax; i++) {
        RNScalar dx = x - i;
        RNScalar dy = y - j;
        RNScalar dz = z - k;
        RNScalar d = sqrt(dx*dx + dy*dy + dz*dz);
        RNScalar w = fac * exp(-d * d / denom);
        value += w * GridValue(i, j, k);
        weight += w;
      }
    }
  }

  // Splat values into grid (scaled by total weight of Gaussian filter)
  if (RNIsPositive(weight)) {
    for (int k = zmin; k <= zmax; k++) {
      for (int j = ymin; j <= ymax; j++) {
        for (int i = xmin; i <= xmax; i++) {
          RNScalar dx = x - i;
          RNScalar dy = y - j;
          RNScalar dz = z - k;
          RNScalar d = sqrt(dx*dx + dy*dy + dz*dz);
          RNScalar w = fac * exp(-d * d / denom);
          RasterizeGridValue(i, j, k, w * value / weight, operation);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movsd %xmm3, 0x50(%rsp)
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x18(%rsp)
xorpd %xmm1, %xmm1
movsd %xmm0, 0x30(%rsp)
ucomisd %xmm0, %xmm1
jbe 0x3055d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd 0x18(%rsp), %xmm1
ja 0x3054e
movq %rdi, %r14
movl 0x238(%rdi), %eax
leal -0x1(%rax), %r13d
cvtsi2sd %r13d, %xmm0
movsd 0x30(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3054e
xorpd %xmm0, %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x3054e
movl 0x23c(%r14), %ecx
leal -0x1(%rcx), %edx
movl %edx, 0xc(%rsp)
cvtsi2sd %edx, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3054e
movl %esi, %ebx
movl 0x240(%r14), %edx
leal -0x1(%rdx), %esi
movl %esi, 0x8(%rsp)
cvtsi2sd %esi, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3054e
movsd 0x62c03(%rip), %xmm1    # 0x931d8
mulsd %xmm4, %xmm1
movsd 0x62a2f(%rip), %xmm0    # 0x93010
addsd %xmm0, %xmm1
cvttpd2dq %xmm1, %xmm1
cvtdq2pd %xmm1, %xmm1
movsd 0x30(%rsp), %xmm3
movapd %xmm3, %xmm2
subsd %xmm1, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %r10d
movapd %xmm1, %xmm2
addsd %xmm3, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %esi
movsd 0x18(%rsp), %xmm3
movapd %xmm3, %xmm2
subsd %xmm1, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %r11d
movapd %xmm1, %xmm2
addsd %xmm3, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %edi
movsd 0x10(%rsp), %xmm3
movapd %xmm3, %xmm2
subsd %xmm1, %xmm2
addsd %xmm0, %xmm2
cvttsd2si %xmm2, %r8d
addsd %xmm3, %xmm1
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %r9d
xorl %ebp, %ebp
testl %r10d, %r10d
cmovlel %ebp, %r10d
movl %r10d, 0x24(%rsp)
cmpl %esi, %eax
cmovgl %esi, %r13d
testl %r11d, %r11d
cmovlel %ebp, %r11d
movl %r11d, 0x20(%rsp)
cmpl %edi, %ecx
movl 0xc(%rsp), %eax
cmovgl %edi, %eax
movl %eax, 0xc(%rsp)
testl %r8d, %r8d
cmovgl %r8d, %ebp
cmpl %r9d, %edx
movl 0x8(%rsp), %eax
cmovgl %r9d, %eax
movl %eax, 0x8(%rsp)
leaq 0x6a89f(%rip), %rax     # 0x9af48
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
movsd %xmm1, 0x38(%rsp)
ucomisd %xmm2, %xmm0
jb 0x306cb
sqrtsd %xmm0, %xmm0
jmp 0x306dc
movsd %xmm4, 0x28(%rsp)
callq 0xe350
movsd 0x28(%rsp), %xmm4
mulsd %xmm4, %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd 0x62914(%rip), %xmm0    # 0x93008
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movapd %xmm4, %xmm0
addsd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movsd %xmm0, 0x60(%rsp)
movl %ebp, %r15d
movl %ebx, 0x5c(%rsp)
cmpl 0x8(%rsp), %r15d
jg 0x30818
cvtsi2sd %r15d, %xmm0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, 0x40(%rsp)
movl 0x20(%rsp), %r12d
cmpl 0xc(%rsp), %r12d
jg 0x30810
cvtsi2sd %r12d, %xmm0
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, 0x48(%rsp)
movl 0x24(%rsp), %ebx
cmpl %r13d, %ebx
jg 0x30804
cvtsi2sd %ebx, %xmm0
movsd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
addsd 0x48(%rsp), %xmm1
addsd 0x40(%rsp), %xmm1
sqrtsd %xmm1, %xmm1
movapd %xmm1, %xmm0
xorpd 0x62891(%rip), %xmm0    # 0x93030
mulsd %xmm1, %xmm0
divsd 0x60(%rsp), %xmm0
callq 0xe820
mulsd 0x28(%rsp), %xmm0
movq 0x230(%r14), %rax
movl 0x248(%r14), %ecx
imull %r15d, %ecx
movl 0x244(%r14), %edx
imull %r12d, %edx
addl %ecx, %edx
addl %ebx, %edx
movslq %edx, %rcx
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
mulsd (%rax,%rcx,8), %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
incl %ebx
jmp 0x30768
incl %r12d
movl 0x5c(%rsp), %ebx
jmp 0x30740
incl %r15d
jmp 0x30717
leaq 0xaa389(%rip), %rax     # 0xdaba8
movsd 0x38(%rsp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x3054e
cmpl 0x8(%rsp), %ebp
jg 0x3054e
cvtsi2sd %ebp, %xmm0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, 0x40(%rsp)
movl 0x20(%rsp), %r15d
cmpl 0xc(%rsp), %r15d
jg 0x308f4
cvtsi2sd %r15d, %xmm0
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
movsd %xmm1, 0x48(%rsp)
movl 0x24(%rsp), %r12d
cmpl %r13d, %r12d
jg 0x308ec
cvtsi2sd %r12d, %xmm0
movsd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm1, %xmm1
addsd 0x48(%rsp), %xmm1
addsd 0x40(%rsp), %xmm1
sqrtsd %xmm1, %xmm1
movapd %xmm1, %xmm0
xorpd 0x6277d(%rip), %xmm0    # 0x93030
mulsd %xmm1, %xmm0
divsd 0x60(%rsp), %xmm0
callq 0xe820
mulsd 0x28(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
movl %ebx, %r8d
callq 0x301e4
incl %r12d
jmp 0x3087f
incl %r15d
jmp 0x30856
incl %ebp
jmp 0x3082f
nop