// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::NodeVisibility(gaps::R3SurfelNode*) const
int R3SurfelViewer::
NodeVisibility(R3SurfelNode *node) const
{
  // Check node
  if (!node) return 0;

  // Check node complexity
  if (subsampling_factor > 1) {
    if (node->Complexity() < subsampling_factor) return 0;
  }

  // Check if drawing human labeled objects
  if (!human_labeled_object_visibility) {
    R3SurfelObject *object = node->Object(TRUE, TRUE);
    while (object) {
      if (object->HumanLabel()) return 0;
      object = object->Parent();
    }
  }

  // Check if label is visible
  R3SurfelObject *object = node->Object(TRUE, TRUE);
  while (object && object->Parent() && (object->Parent() != scene->RootObject())) object = object->Parent();
  if (object) {
    if (!AttributeVisibility(object->Flags())) return 0;
    R3SurfelLabel *label = object->CurrentLabel();
    if ((label) && !LabelVisibility(label)) return 0;
  }

  // Check elevation range
  if (!elevation_range.IsEmpty()) {
    RNInterval node_range = node->ElevationRange();
    if (!elevation_range.Contains(node_range)) return 0;
  }

  // Check viewing extent
  if (!viewing_extent.IsEmpty()) {
    if (!R3Intersects(viewing_extent, node->BBox())) return 0;
  }
  
#if (R3_SURFEL_VIEWER_DRAW_METHOD != R3_SURFEL_VIEWER_DRAW_WITH_VBO)
  // Check viewing frustum
  if (node->Complexity() > 1000) {
    if (!viewing_frustum.IsEmpty()) {
      if (!R3Intersects(viewing_frustum, node->BBox())) return 0;
    }
  }
#endif
  
  // Passed all tests
  return 1;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x50(%rsp)
jne 0x3039d
movl $0x0, 0x64(%rsp)
jmp 0x305de
movq 0x18(%rsp), %rax
cmpl $0x1, 0x48c(%rax)
jle 0x303da
movq 0x50(%rsp), %rdi
callq 0x58960
movq 0x18(%rsp), %rax
movaps %xmm0, %xmm1
cvtsi2sdl 0x48c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x303d8
movl $0x0, 0x64(%rsp)
jmp 0x305de
jmp 0x303da
movq 0x18(%rsp), %rax
cmpl $0x0, 0x304(%rax)
jne 0x30436
movq 0x50(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x58f70
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x30434
movq 0x48(%rsp), %rdi
callq 0x66220
cmpq $0x0, %rax
je 0x30423
movl $0x0, 0x64(%rsp)
jmp 0x305de
movq 0x48(%rsp), %rdi
callq 0x3d2e0
movq %rax, 0x48(%rsp)
jmp 0x303fe
jmp 0x30436
movq 0x50(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x58f70
movq %rax, 0x40(%rsp)
xorl %eax, %eax
cmpq $0x0, 0x40(%rsp)
movb %al, 0x17(%rsp)
je 0x304a5
movq 0x40(%rsp), %rdi
callq 0x3d2e0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0x17(%rsp)
je 0x304a5
movq 0x40(%rsp), %rdi
callq 0x3d2e0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rsp)
movq 0x8(%rax), %rdi
callq 0x3d2f0
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
setne %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x304af
jmp 0x304c0
movq 0x40(%rsp), %rdi
callq 0x3d2e0
movq %rax, 0x40(%rsp)
jmp 0x3044c
cmpq $0x0, 0x40(%rsp)
je 0x30532
movq 0x40(%rsp), %rdi
callq 0x3d310
movq 0x18(%rsp), %rdi
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rsi
callq 0x305f0
cmpl $0x0, %eax
jne 0x304f8
movl $0x0, 0x64(%rsp)
jmp 0x305de
movq 0x40(%rsp), %rdi
callq 0x662c0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x30530
movq 0x18(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3d330
cmpl $0x0, %eax
jne 0x30530
movl $0x0, 0x64(%rsp)
jmp 0x305de
jmp 0x30532
movq 0x18(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x3d380
cmpl $0x0, %eax
jne 0x30586
movq 0x50(%rsp), %rdi
callq 0x58b40
movq %rax, %rsi
leaq 0x20(%rsp), %rdi
callq 0x1a6080
movq 0x18(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
leaq 0x20(%rsp), %rsi
callq 0x3d3a0
cmpl $0x0, %eax
jne 0x30584
movl $0x0, 0x64(%rsp)
jmp 0x305de
jmp 0x30586
movq 0x18(%rsp), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x2f3f0
cmpl $0x0, %eax
jne 0x305d6
movq 0x18(%rsp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, (%rsp)
movq 0x50(%rsp), %rdi
callq 0x58ae0
movq (%rsp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xeb080
cmpl $0x0, %eax
jne 0x305d4
movl $0x0, 0x64(%rsp)
jmp 0x305de
jmp 0x305d6
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw (%rax,%rax)