// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::EnableViewingExtent() const
void R3SurfelViewer::
EnableViewingExtent(void) const
{
  // Check clip planes extent
  const R3Box& bbox = scene->BBox();  
  const R3Box& extent = ViewingExtent();
  if (extent.IsEmpty() || R3Contains(extent, bbox)) {
    DisableViewingExtent();
    return;
  }

  // Load lo clip planes
  for (int dim = RN_X; dim <= RN_Z; dim++) {
    if (extent[RN_LO][dim] > bbox[RN_LO][dim]) {
      GLdouble plane_equation[4] = { 0, 0, 0, 0 };
      plane_equation[dim] = 1.0;
      plane_equation[3] = -extent[RN_LO][dim];
      glClipPlane(GL_CLIP_PLANE0 + dim, plane_equation);
      glEnable(GL_CLIP_PLANE0 + dim);
    }
  }

  // Load hi clip planes
  for (int dim = RN_X; dim <= RN_Z; dim++) {
    if (extent[RN_HI][dim] < bbox[RN_HI][dim]) {
      GLdouble plane_equation[4] = { 0, 0, 0, 0 };
      plane_equation[dim] = -1.0;
      plane_equation[3] = extent[RN_HI][dim];
      glClipPlane(GL_CLIP_PLANE0 + 3 + dim, plane_equation);
      glEnable(GL_CLIP_PLANE0 + 3 + dim);
    }
  }
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%rax), %rdi
callq 0x3d7d0
movq 0x18(%rsp), %rdi
movq %rax, 0x88(%rsp)
callq 0x3d7f0
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rdi
callq 0x2f3f0
cmpl $0x0, %eax
jne 0x318db
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0xef350
cmpl $0x0, %eax
je 0x318ee
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x238(%rax)
jmp 0x31abb
movl $0x0, 0x7c(%rsp)
cmpl $0x2, 0x7c(%rsp)
jg 0x319dd
movq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x3d810
movq %rax, %rdi
movl 0x7c(%rsp), %esi
callq 0x2f630
movsd %xmm0, 0x10(%rsp)
movq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x3d810
movq %rax, %rdi
movl 0x7c(%rsp), %esi
callq 0x2f630
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x319cb
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x28510
movslq 0x7c(%rsp), %rax
movsd 0x20f6a6(%rip), %xmm0   # 0x241010
movsd %xmm0, 0x50(%rsp,%rax,8)
movq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x3d810
movq %rax, %rdi
movl 0x7c(%rsp), %esi
callq 0x2f630
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x68(%rsp)
movl 0x7c(%rsp), %edi
addl $0x3000, %edi           # imm = 0x3000
leaq 0x50(%rsp), %rsi
callq 0x283d0
movl 0x7c(%rsp), %edi
addl $0x3000, %edi           # imm = 0x3000
callq 0x28960
jmp 0x319cd
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x318f6
movl $0x0, 0x4c(%rsp)
cmpl $0x2, 0x4c(%rsp)
jg 0x31abb
movq 0x80(%rsp), %rdi
movl $0x1, %esi
callq 0x3d810
movq %rax, %rdi
movl 0x4c(%rsp), %esi
callq 0x2f630
movsd %xmm0, 0x8(%rsp)
movq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x3d810
movq %rax, %rdi
movl 0x4c(%rsp), %esi
callq 0x2f630
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x31aa9
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x28510
movslq 0x4c(%rsp), %rax
movsd 0x20f5ac(%rip), %xmm0   # 0x241008
movsd %xmm0, 0x20(%rsp,%rax,8)
movq 0x80(%rsp), %rdi
movl $0x1, %esi
callq 0x3d810
movq %rax, %rdi
movl 0x4c(%rsp), %esi
callq 0x2f630
movsd %xmm0, 0x38(%rsp)
movl 0x4c(%rsp), %edi
addl $0x3003, %edi           # imm = 0x3003
leaq 0x20(%rsp), %rsi
callq 0x283d0
movl 0x4c(%rsp), %edi
addl $0x3003, %edi           # imm = 0x3003
callq 0x28960
jmp 0x31aab
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x319e5
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)