// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::RasterizeGridPlane(gaps::R3Plane const&, double, int)
void R3Grid::
RasterizeGridPlane(const R3Plane& plane, RNScalar value, int operation)
{
  // Load info to pass to MarchingCubes
  R3Point corner_points[8];
  RNScalar corner_levels[8];
  R3Point triangle_points[3 * 8];
  R3Box grid_box = GridBox();
  for (int octant = 0; octant < 8; octant++) {
    corner_points[octant] = grid_box.Corner(octant);
    corner_levels[octant] = R3SignedDistance(plane, corner_points[octant]);
  }

  // Determine triangles 
  int npoints = MarchingCubes(corner_points, corner_levels, 0, triangle_points);

  // Rasterize triangles into temporary grid
  R3Grid tmp(grid_resolution[0], grid_resolution[1], grid_resolution[2]);
  for (int i = 0; i < npoints; i += 3) {
    tmp.RasterizeGridTriangle(triangle_points[i], triangle_points[i+1], triangle_points[i+2], 1);
  }
  
  // Add value to this grid where temporary grid is nonzero (avoids double counting at triangle boundaries)
  for (int iz = 0; iz < grid_resolution[2]; iz++) {
    for (int iy = 0; iy < grid_resolution[1]; iy++) {
      for (int ix = 0; ix < grid_resolution[0]; ix++) {
        if (tmp.GridValue(ix, iy, iz) > 0) {
          RasterizeGridValue(ix, iy, iz, value, operation);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x608, %rsp            # imm = 0x608
movl %edx, %ebx
movsd %xmm0, (%rsp)
movq %rsi, %r15
movq %rdi, %r14
xorl %r12d, %r12d
leaq (%rsp,%r12), %rdi
addq $0xb0, %rdi
callq 0x3c530
addq $0x18, %r12
cmpq $0xc0, %r12
jne 0x34ff9
xorl %r12d, %r12d
leaq (%rsp,%r12), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
callq 0x3c530
addq $0x18, %r12
cmpq $0x240, %r12            # imm = 0x240
jne 0x35019
movl 0x238(%r14), %eax
decl %eax
cvtsi2sd %eax, %xmm3
movl 0x23c(%r14), %eax
decl %eax
cvtsi2sd %eax, %xmm4
movl 0x240(%r14), %eax
decl %eax
cvtsi2sd %eax, %xmm5
leaq 0x38(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
callq 0x27374
leaq 0xb0(%rsp), %r13
xorl %ebp, %ebp
leaq 0x170(%rsp), %r12
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
movl %ebp, %edx
callq 0x27552
movq %r13, %rdi
movq %r12, %rsi
callq 0x3c89a
movq %r15, %rdi
movq %r13, %rsi
callq 0x49617
movsd %xmm0, 0x70(%rsp,%rbp,8)
incq %rbp
addq $0x18, %r13
cmpq $0x8, %rbp
jne 0x35085
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x3c0(%rsp), %rdx
xorpd %xmm0, %xmm0
callq 0x352d3
movl %eax, %ebp
movl 0x238(%r14), %esi
movl 0x23c(%r14), %edx
movl 0x240(%r14), %ecx
leaq 0x170(%rsp), %rdi
callq 0x2e450
testl %ebp, %ebp
jle 0x351cf
xorl %r12d, %r12d
leaq 0x400(%rsp), %r13
leaq 0x8(%rsp), %r15
movupd -0x40(%r13), %xmm0
movapd 0x6ceeb(%rip), %xmm1    # 0xa2010
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x28(%rsp)
movsd -0x30(%r13), %xmm0
movsd 0x6ceef(%rip), %xmm2    # 0xa2030
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movsd -0x18(%r13), %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movupd -0x28(%r13), %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movupd -0x10(%r13), %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x8(%rsp)
movsd (%r13), %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x10(%rsp)
leaq 0x170(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r15, %rcx
movsd 0x6ce82(%rip), %xmm0    # 0xa2038
xorl %r8d, %r8d
callq 0x34a44
addq $0x48, %r13
addl $0x3, %r12d
cmpl %r12d, %ebp
jg 0x35117
movl 0x240(%r14), %ecx
testl %ecx, %ecx
jle 0x3527b
movl 0x23c(%r14), %eax
xorl %ebp, %ebp
testl %eax, %eax
jle 0x35271
movl 0x238(%r14), %ecx
xorl %r15d, %r15d
testl %ecx, %ecx
jle 0x35262
xorl %r12d, %r12d
movq 0x3a0(%rsp), %rax
movl 0x3b8(%rsp), %edx
imull %ebp, %edx
movl 0x3b4(%rsp), %esi
imull %r15d, %esi
addl %edx, %esi
addl %r12d, %esi
movslq %esi, %rdx
movsd (%rax,%rdx,8), %xmm0
ucomisd 0x6cfb6(%rip), %xmm0    # 0xa21e8
jbe 0x35253
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
movsd (%rsp), %xmm0
movl %ebx, %r8d
callq 0x34032
movl 0x238(%r14), %ecx
incl %r12d
cmpl %ecx, %r12d
jl 0x35200
movl 0x23c(%r14), %eax
incl %r15d
cmpl %eax, %r15d
jl 0x351f9
movl 0x240(%r14), %ecx
incl %ebp
cmpl %ecx, %ebp
jl 0x351e7
leaq 0x170(%rsp), %rdi
callq 0x2ee9e
leaq 0x38(%rsp), %rdi
callq 0x280f4
addq $0x608, %rsp            # imm = 0x608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x352ac
jmp 0x352ac
jmp 0x352b1
jmp 0x352ac
movq %rax, %rbx
jmp 0x352c1
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x2ee9e
leaq 0x38(%rsp), %rdi
callq 0x280f4
movq %rbx, %rdi
callq 0xe7e0