// File: tomfunkhouser[P]gaps/apps/conf2sfl/conf2sfl.cpp
// Function: CreateMultiresolutionHierarchy(gaps::R3SurfelScene*)
static int
CreateMultiresolutionHierarchy(R3SurfelScene *scene)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();
  if (print_verbose) {
    printf("Creating hierarchy ...\n");
    fflush(stdout);
  }

  // Get surfel tree
  R3SurfelTree *tree = scene->Tree();
  if (!tree) {
    RNFail("Surfel scene has no tree\n");
    return 0;
  }    

  // Split nodes
  int max_parts_per_node = 8;
  int max_blocks_per_node = 32;
  RNScalar max_node_complexity = 1024;
  RNScalar max_block_complexity = 1024;
  RNLength max_leaf_extent = 1.0;
  RNLength max_block_extent = 1.0;
  int max_levels = 64;
  tree->SplitNodes(max_parts_per_node, max_blocks_per_node, 
    max_node_complexity, max_block_complexity, 
    max_leaf_extent, max_block_extent, max_levels);

  // Create multiresolution blocks
  RNScalar multiresolution_factor = 0.25;
  tree->CreateMultiresolutionBlocks(multiresolution_factor, max_block_complexity);

  // Print statistics
  if (print_verbose) {
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Nodes = %d\n", scene->Tree()->NNodes());
    printf("  # Blocks = %d\n", scene->Tree()->Database()->NBlocks());
    printf("  # Surfels = %lld\n", scene->Tree()->Database()->NSurfels());
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x172a30
leaq 0x48(%rsp), %rdi
callq 0x1ec90
cmpl $0x0, 0x24dfa8(%rip)    # 0x26881c
je 0x1a893
leaq 0x1e2d1b(%rip), %rdi    # 0x1fd598
movb $0x0, %al
callq 0x16090
movq 0x244705(%rip), %rax    # 0x25ef90
movq (%rax), %rdi
callq 0x168c0
movq 0x58(%rsp), %rdi
callq 0x1edc0
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x1a8c5
leaq 0x1e2cff(%rip), %rdi    # 0x1fd5b0
movb $0x0, %al
callq 0x1779b0
movl $0x0, 0x64(%rsp)
jmp 0x1aa1c
movl $0x8, 0x3c(%rsp)
movl $0x20, 0x38(%rsp)
movsd 0x1e274b(%rip), %xmm0   # 0x1fd028
movsd %xmm0, 0x30(%rsp)
movsd 0x1e273d(%rip), %xmm0   # 0x1fd028
movsd %xmm0, 0x28(%rsp)
movsd 0x1e2727(%rip), %xmm0   # 0x1fd020
movsd %xmm0, 0x20(%rsp)
movsd 0x1e2719(%rip), %xmm0   # 0x1fd020
movsd %xmm0, 0x18(%rsp)
movl $0x40, 0x14(%rsp)
movq 0x40(%rsp), %rdi
movl 0x3c(%rsp), %esi
movl 0x38(%rsp), %edx
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movl 0x14(%rsp), %ecx
movq (%rdi), %rax
callq *0x20(%rax)
movsd 0x1e26cc(%rip), %xmm0   # 0x1fd018
movsd %xmm0, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movq (%rdi), %rax
callq *0x68(%rax)
cmpl $0x0, 0x24deac(%rip)    # 0x26881c
je 0x1aa14
leaq 0x48(%rsp), %rdi
callq 0x172af0
leaq 0x1e28d4(%rip), %rdi    # 0x1fd25b
movb $0x1, %al
callq 0x16090
movq 0x58(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edd0
movl %eax, %esi
leaq 0x1e2975(%rip), %rdi    # 0x1fd31e
movb $0x0, %al
callq 0x16090
movq 0x58(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edf0
movq %rax, %rdi
callq 0x1ee00
movl %eax, %esi
leaq 0x1e295b(%rip), %rdi    # 0x1fd32e
movb $0x0, %al
callq 0x16090
movq 0x58(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edf0
movq %rax, %rdi
callq 0x1ee20
movq %rax, %rsi
leaq 0x1e2941(%rip), %rdi    # 0x1fd33f
movb $0x0, %al
callq 0x16090
movq 0x244584(%rip), %rax    # 0x25ef90
movq (%rax), %rdi
callq 0x168c0
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)