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

  // Load images
  for (int i = 0; i < configuration->NImages(); i++) {
    RGBDImage *image = configuration->Image(i);
   
    // Check if should load image
    if ((load_every_kth_image > 1) && ((i % load_every_kth_image) != 0)) continue; 
    if (i < load_images_starting_at_index) continue;
    if (i > load_images_ending_at_index) continue;
    if (!load_images_bbox.IsEmpty() && !R3Contains(load_images_bbox, image->WorldViewpoint())) continue;

    // Read image
    if (!image->ReadChannels()) continue;

    // Load image
    if (!LoadSurfels(scene, image)) continue;

    // Release image
    if (!image->ReleaseChannels()) continue;
  }
  
  // Print statistics
  if (print_verbose) {
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Scans = %d\n", configuration->NImages());
    printf("  # Objects = %d\n", scene->NObjects());
    printf("  # Scans = %d\n", scene->NScans());
    printf("  # Images = %d\n", scene->NImages());
    printf("  # Nodes = %d\n", scene->Tree()->NNodes());
    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 $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x172a30
leaq 0x38(%rsp), %rdi
callq 0x1ec90
cmpl $0x0, 0x24e253(%rip)    # 0x26881c
je 0x1a5e8
leaq 0x1e2d81(%rip), %rdi    # 0x1fd353
movb $0x0, %al
callq 0x16090
movq 0x2449b0(%rip), %rax    # 0x25ef90
movq (%rax), %rdi
callq 0x168c0
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x48(%rsp), %rdi
callq 0x1ecb0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x1a706
movq 0x48(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x1ee30
movq %rax, 0x28(%rsp)
cmpl $0x1, 0x24513e(%rip)    # 0x25f768
jle 0x1a641
movl 0x34(%rsp), %eax
cltd
idivl 0x245131(%rip)          # 0x25f768
cmpl $0x0, %edx
je 0x1a641
jmp 0x1a6f6
movl 0x34(%rsp), %eax
cmpl 0x24e1f1(%rip), %eax    # 0x26883c
jge 0x1a652
jmp 0x1a6f6
movl 0x34(%rsp), %eax
cmpl 0x245108(%rip), %eax    # 0x25f764
jle 0x1a663
jmp 0x1a6f6
leaq 0x24e15e(%rip), %rdi    # 0x2687c8
callq 0x1ee60
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xb(%rsp)
jne 0x1a6a8
movq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x1ef20
leaq 0x24e136(%rip), %rdi    # 0x2687c8
leaq 0x10(%rsp), %rsi
callq 0xbd2d0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0x1a6b2
jmp 0x1a6b4
jmp 0x1a6f6
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0xf8(%rax)
cmpl $0x0, %eax
jne 0x1a6c9
jmp 0x1a6f6
movq 0x50(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x1ac10
cmpl $0x0, %eax
jne 0x1a6df
jmp 0x1a6f6
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x148(%rax)
cmpl $0x0, %eax
jne 0x1a6f4
jmp 0x1a6f6
jmp 0x1a6f6
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x1a5f0
cmpl $0x0, 0x24e10f(%rip)    # 0x26881c
je 0x1a83b
leaq 0x38(%rsp), %rdi
callq 0x172af0
leaq 0x1e2b37(%rip), %rdi    # 0x1fd25b
movb $0x1, %al
callq 0x16090
movq 0x48(%rsp), %rdi
callq 0x1ecb0
movl %eax, %esi
leaq 0x1e2bd0(%rip), %rdi    # 0x1fd30e
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1ed00
movl %eax, %esi
leaq 0x1e2b6a(%rip), %rdi    # 0x1fd2c2
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1ed80
movl %eax, %esi
leaq 0x1e2b9c(%rip), %rdi    # 0x1fd30e
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1eda0
movl %eax, %esi
leaq 0x1e2ae6(%rip), %rdi    # 0x1fd272
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edd0
movl %eax, %esi
leaq 0x1e2b70(%rip), %rdi    # 0x1fd31e
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edd0
movl %eax, %esi
leaq 0x1e2b4e(%rip), %rdi    # 0x1fd31e
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edf0
movq %rax, %rdi
callq 0x1ee00
movl %eax, %esi
leaq 0x1e2b34(%rip), %rdi    # 0x1fd32e
movb $0x0, %al
callq 0x16090
movq 0x50(%rsp), %rdi
callq 0x1edc0
movq %rax, %rdi
callq 0x1edf0
movq %rax, %rdi
callq 0x1ee20
movq %rax, %rsi
leaq 0x1e2b1a(%rip), %rdi    # 0x1fd33f
movb $0x0, %al
callq 0x16090
movq 0x24475d(%rip), %rax    # 0x25ef90
movq (%rax), %rdi
callq 0x168c0
movl $0x1, %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)