// File: /workspace/github_cpp_makefile_star2_O2/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 $0x5d8, %rsp            # imm = 0x5D8
movl %edx, %ebx
movsd %xmm0, (%rsp)
movq %rsi, %r15
movq %rdi, %r14
xorl %r12d, %r12d
leaq (%rsp,%r12), %rdi
addq $0x80, %rdi
callq 0x37b4a
addq $0x18, %r12
cmpq $0xc0, %r12
jne 0x3103b
xorl %r12d, %r12d
leaq (%rsp,%r12), %rdi
addq $0x390, %rdi            # imm = 0x390
callq 0x37b4a
addq $0x18, %r12
cmpq $0x240, %r12            # imm = 0x240
jne 0x3105b
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3668a
leaq 0x80(%rsp), %r13
xorl %ebp, %ebp
leaq 0x140(%rsp), %r12
cmpq $0x8, %rbp
je 0x310d1
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x24db6
movq %r13, %rdi
movq %r12, %rsi
callq 0x37e36
movq %r15, %rdi
movq %r13, %rsi
callq 0x43420
movsd %xmm0, 0x40(%rsp,%rbp,8)
incq %rbp
addq $0x18, %r13
jmp 0x31097
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x390(%rsp), %r15
xorpd %xmm0, %xmm0
movq %r15, %rdx
callq 0x31225
movl %eax, %ebp
movl 0x238(%r14), %esi
movl 0x23c(%r14), %edx
movl 0x240(%r14), %ecx
leaq 0x140(%rsp), %rdi
callq 0x2b2ec
movslq %ebp, %r13
xorl %ebp, %ebp
leaq 0x140(%rsp), %r12
cmpq %r13, %rbp
jge 0x31150
leaq 0x18(%r15), %rdx
leaq 0x30(%r15), %rcx
movq %r12, %rdi
movq %r15, %rsi
movsd 0x61eca(%rip), %xmm0    # 0x93008
xorl %r8d, %r8d
callq 0x10d1e
addq $0x3, %rbp
addq $0x48, %r15
jmp 0x31123
xorl %ebp, %ebp
cmpl 0x240(%r14), %ebp
jge 0x311cd
xorl %r15d, %r15d
cmpl 0x23c(%r14), %r15d
jge 0x311c9
xorl %r12d, %r12d
cmpl 0x238(%r14), %r12d
jge 0x311c4
movq 0x370(%rsp), %rax
movl 0x388(%rsp), %ecx
imull %ebp, %ecx
movl 0x384(%rsp), %edx
imull %r15d, %edx
addl %ecx, %edx
addl %r12d, %edx
movslq %edx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd 0x62043(%rip), %xmm0    # 0x931e8
jbe 0x311bf
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %ebp, %ecx
movsd (%rsp), %xmm0
movl %ebx, %r8d
callq 0x301e4
incl %r12d
jmp 0x3116a
incl %r15d
jmp 0x3115e
incl %ebp
jmp 0x31152
leaq 0x140(%rsp), %rdi
callq 0x2bc02
leaq 0x8(%rsp), %rdi
callq 0x25832
addq $0x5d8, %rsp            # imm = 0x5D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x311fe
jmp 0x311fe
jmp 0x31203
jmp 0x311fe
movq %rax, %rbx
jmp 0x31213
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x2bc02
leaq 0x8(%rsp), %rdi
callq 0x25832
movq %rbx, %rdi
callq 0xe810