// File: ddunbar[P]PDSample/./quasisampler_prototype.h
// Function: Quasisampler::buildAdaptiveSubdivision(unsigned int)
void buildAdaptiveSubdivision( unsigned minSubdivisionLevel = 6 )
  {
    root = new TileNode(width,height);
    
    // Since we are approximating the MAX within each tile by the values at
    // a few key points, we must provide a sufficiently dense initial
    // tiling. This would not be necessary with a more thorough scan of each
    // tile.
    subdivideAll(minSubdivisionLevel);

    TileLeafIterator it(root);
    TileNode *tmp;

    // Recursively subdivide all triangles until each triangle's
    // required level is reached.
    unsigned level;
    do {
      level = it->getLevel();
      
      if ( it->isSamplingType() ) // Sampling tiles are infinitesimal
      {
        if ( level < getReqSubdivisionLevel(getImportanceAt_bounded(it->getP1())) )
        {
          tmp = *it;
          tmp->refine();
        }
      }
      else
      {
        if ( 
          ( level < getReqSubdivisionLevel(getImportanceAt_bounded(it->getP1())) ) ||
          ( level < getReqSubdivisionLevel(getImportanceAt_bounded(it->getP2())) ) ||
          ( level < getReqSubdivisionLevel(getImportanceAt_bounded(it->getP3())) ) ||
          ( level < getReqSubdivisionLevel(getImportanceAt_bounded(it->getCenter())) )
          )
        {
          tmp = *it;
          tmp->refine();
        }
      }
    } while ( it.next() );
  }

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movl %esi, 0xac(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x78, %edi
callq 0x21a0
movq %rax, %rdi
movq 0x20(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x28(%rsp)
movsd 0x10(%rax), %xmm0
movsd 0x18(%rax), %xmm1
callq 0x8e00
jmp 0x88de
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rdi)
movl 0xac(%rsp), %esi
callq 0x8fd0
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x90(%rsp), %rdi
callq 0x9060
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x90a0
movl %eax, 0x84(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x90b0
testb $0x1, %al
jne 0x8948
jmp 0x89ec
movl 0x84(%rsp), %eax
movl %eax, 0x1c(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x9240
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x70(%rsp)
movsd %xmm1, 0x78(%rsp)
movsd 0x70(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
callq 0x9190
movl %eax, %edi
callq 0x90f0
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jae 0x89e7
leaq 0x90(%rsp), %rdi
callq 0x9260
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
callq 0x9270
jmp 0x89e7
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
movl $0x78, %esi
callq 0x21b0
jmp 0x8b83
jmp 0x8b64
movl 0x84(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x9240
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x60(%rsp)
movsd %xmm1, 0x68(%rsp)
movsd 0x60(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
callq 0x9190
movl %eax, %edi
callq 0x90f0
movl %eax, %ecx
movl 0x18(%rsp), %eax
cmpl %ecx, %eax
jb 0x8b40
movl 0x84(%rsp), %eax
movl %eax, 0x14(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x9f10
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x58(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
callq 0x9190
movl %eax, %edi
callq 0x90f0
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jb 0x8b40
movl 0x84(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x9f30
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x48(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x9190
movl %eax, %edi
callq 0x90f0
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jb 0x8b40
movl 0x84(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x9090
movq %rax, %rdi
callq 0x9f50
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x38(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x9190
movl %eax, %edi
callq 0x90f0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jae 0x8b62
leaq 0x90(%rsp), %rdi
callq 0x9260
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
callq 0x9270
jmp 0x8b64
jmp 0x8b66
leaq 0x90(%rsp), %rdi
callq 0x9fd0
testb $0x1, %al
jne 0x890e
addq $0xb8, %rsp
retq
movq 0xa0(%rsp), %rdi
callq 0x22f0