// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: LoadImagesFromConfiguration(gaps::R3SurfelScene*, char const*)
static int
LoadImagesFromConfiguration(R3SurfelScene *scene, const char *configuration_filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Read configuration file
  RGBDConfiguration configuration;
  if (!configuration.ReadFile(configuration_filename)) return 0;

  // Create images
  for (int i = 0; i < configuration.NImages(); i++) {
    RGBDImage *rgbd_image = configuration.Image(i);

    // Get name
    char name[1025];
    if (rgbd_image->Name() && strcmp(rgbd_image->Name(), "-")) {
      strncpy(name, rgbd_image->Name(), 1024);
    }
    else if (rgbd_image->ColorFilename() && strcmp(rgbd_image->ColorFilename(), "-")) {
      const char *start = strrchr(rgbd_image->ColorFilename(), '/');
      if (start) strncpy(name, start+1, 1024);
      else strncpy(name, rgbd_image->ColorFilename(), 1024);
    }
    else if (rgbd_image->DepthFilename() && strcmp(rgbd_image->DepthFilename(), "-")) {
      const char *start = strrchr(rgbd_image->DepthFilename(), '/');
      if (start) strncpy(name, start+1, 1024);
      else strncpy(name, rgbd_image->DepthFilename(), 1024);
    }
    else sprintf(name, "Image_%d\n", i);

    // Get stuff from rgbd image
    R3Point viewpoint = rgbd_image->WorldViewpoint();
    R3Vector towards = rgbd_image->WorldTowards();
    R3Vector up = rgbd_image->WorldUp();
    int width = rgbd_image->NPixels(RN_X);
    int height = rgbd_image->NPixels(RN_Y);
    R3Matrix intrinsics = rgbd_image->Intrinsics();
    double xfocal = intrinsics[0][0];
    double yfocal = intrinsics[1][1];
    double xcenter = intrinsics[0][2];
    double ycenter = intrinsics[1][2];

    // Create sfl image
    R3SurfelImage *sfl_image = new R3SurfelImage();
    sfl_image->SetViewpoint(viewpoint);
    sfl_image->SetOrientation(towards, up);
    sfl_image->SetImageDimensions(width, height);
    sfl_image->SetImageCenter(R2Point(xcenter, ycenter));
    sfl_image->SetXFocal(xfocal);
    sfl_image->SetYFocal(yfocal);
    sfl_image->SetName(name);

    // Insert sfl image into scene
    scene->InsertImage(sfl_image);
  }
  
  // Print statistics
  if (print_verbose) {
    printf("Loaded images from %s ...\n", configuration_filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Images = %d\n", configuration.NImages());
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x6b8, %rsp            # imm = 0x6B8
movq %rdi, 0x6a8(%rsp)
movq %rsi, 0x6a0(%rsp)
leaq 0x690(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x16dd30
movq 0xd8(%rsp), %rdi
callq 0x263f0
leaq 0x5f8(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x2b200
movq 0xe0(%rsp), %rdi
movq 0x6a0(%rsp), %rsi
movl $0x1, %edx
callq 0x2bd40
movl %eax, 0xec(%rsp)
jmp 0x21361
movl 0xec(%rsp), %eax
cmpl $0x0, %eax
jne 0x213a1
movl $0x0, 0x6b4(%rsp)
movl $0x1, 0x5e8(%rsp)
jmp 0x21a2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f0(%rsp)
movl %eax, 0x5ec(%rsp)
jmp 0x21a4b
movl $0x0, 0x5e4(%rsp)
movl 0x5e4(%rsp), %eax
movl %eax, 0xd0(%rsp)
leaq 0x5f8(%rsp), %rdi
callq 0x27480
movl %eax, 0xd4(%rsp)
jmp 0x213d0
movl 0xd0(%rsp), %eax
movl 0xd4(%rsp), %ecx
cmpl %ecx, %eax
jge 0x21993
movl 0x5e4(%rsp), %esi
leaq 0x5f8(%rsp), %rdi
callq 0x274a0
movq %rax, 0xc8(%rsp)
jmp 0x21404
movq 0xc8(%rsp), %rax
movq %rax, 0x5d8(%rsp)
movq 0x5d8(%rsp), %rdi
callq 0x274d0
movq %rax, 0xc0(%rsp)
jmp 0x2142b
movq 0xc0(%rsp), %rax
cmpq $0x0, %rax
je 0x214af
movq 0x5d8(%rsp), %rdi
callq 0x274d0
movq %rax, 0xb8(%rsp)
jmp 0x21450
movq 0xb8(%rsp), %rdi
leaq 0x1d76b7(%rip), %rsi    # 0x1f8b16
callq 0x16a80
cmpl $0x0, %eax
je 0x214af
leaq 0x1d0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x5d8(%rsp), %rdi
callq 0x274d0
movq %rax, 0xb0(%rsp)
jmp 0x21490
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x16380
jmp 0x216ad
movq 0x5d8(%rsp), %rdi
callq 0x274f0
movq %rax, 0xa0(%rsp)
jmp 0x214c6
movq 0xa0(%rsp), %rax
cmpq $0x0, %rax
je 0x215ae
movq 0x5d8(%rsp), %rdi
callq 0x274f0
movq %rax, 0x98(%rsp)
jmp 0x214ef
movq 0x98(%rsp), %rdi
leaq 0x1d7618(%rip), %rsi    # 0x1f8b16
callq 0x16a80
cmpl $0x0, %eax
je 0x215ae
movq 0x5d8(%rsp), %rdi
callq 0x274f0
movq %rax, 0x90(%rsp)
jmp 0x21523
movq 0x90(%rsp), %rdi
movl $0x2f, %esi
callq 0x16810
movq %rax, 0x1c8(%rsp)
cmpq $0x0, 0x1c8(%rsp)
je 0x21568
leaq 0x1d0(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
addq $0x1, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x16380
jmp 0x215a9
leaq 0x1d0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x5d8(%rsp), %rdi
callq 0x274f0
movq %rax, 0x88(%rsp)
jmp 0x2158f
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x16380
jmp 0x216ab
movq 0x5d8(%rsp), %rdi
callq 0x27510
movq %rax, 0x78(%rsp)
jmp 0x215c2
movq 0x78(%rsp), %rax
cmpq $0x0, %rax
je 0x2168c
movq 0x5d8(%rsp), %rdi
callq 0x27510
movq %rax, 0x70(%rsp)
jmp 0x215e5
movq 0x70(%rsp), %rdi
leaq 0x1d7525(%rip), %rsi    # 0x1f8b16
callq 0x16a80
cmpl $0x0, %eax
je 0x2168c
movq 0x5d8(%rsp), %rdi
callq 0x27510
movq %rax, 0x68(%rsp)
jmp 0x21613
movq 0x68(%rsp), %rdi
movl $0x2f, %esi
callq 0x16810
movq %rax, 0x1c0(%rsp)
cmpq $0x0, 0x1c0(%rsp)
je 0x21655
leaq 0x1d0(%rsp), %rdi
movq 0x1c0(%rsp), %rsi
addq $0x1, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x16380
jmp 0x2168a
leaq 0x1d0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x5d8(%rsp), %rdi
callq 0x27510
movq %rax, 0x60(%rsp)
jmp 0x21676
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x16380
jmp 0x216a9
leaq 0x1d0(%rsp), %rdi
movl 0x5e4(%rsp), %edx
leaq 0x1d7476(%rip), %rsi    # 0x1f8b18
movb $0x0, %al
callq 0x16130
jmp 0x216ab
jmp 0x216ad
movq 0x5d8(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x27530
jmp 0x216c4
movq 0x5d8(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x27580
jmp 0x216db
movq 0x5d8(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x275d0
jmp 0x216f2
movq 0x5d8(%rsp), %rdi
xorl %esi, %esi
callq 0x27620
movl %eax, 0x54(%rsp)
jmp 0x21707
movl 0x54(%rsp), %eax
movl %eax, 0x174(%rsp)
movq 0x5d8(%rsp), %rdi
movl $0x1, %esi
callq 0x27620
movl %eax, 0x50(%rsp)
jmp 0x2172a
movl 0x50(%rsp), %eax
movl %eax, 0x170(%rsp)
movq 0x5d8(%rsp), %rdi
callq 0x27660
movq %rax, 0x48(%rsp)
jmp 0x21749
movq 0x48(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x15f700
jmp 0x2175d
leaq 0x128(%rsp), %rdi
xorl %esi, %esi
callq 0x27680
movq %rax, 0x40(%rsp)
jmp 0x21773
movq 0x40(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
movl $0x1, %esi
callq 0x27680
movq %rax, 0x38(%rsp)
jmp 0x2179e
movq 0x38(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x118(%rsp)
leaq 0x128(%rsp), %rdi
xorl %esi, %esi
callq 0x27680
movq %rax, 0x30(%rsp)
jmp 0x217c7
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x110(%rsp)
leaq 0x128(%rsp), %rdi
movl $0x1, %esi
callq 0x27680
movq %rax, 0x28(%rsp)
jmp 0x217f3
movq 0x28(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x108(%rsp)
movl $0x1d8, %edi            # imm = 0x1D8
callq 0x16740
movq %rax, 0x20(%rsp)
jmp 0x21817
movq 0x20(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x64380
jmp 0x21827
movq 0x20(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
movq (%rdi), %rax
movq 0x60(%rax), %rax
leaq 0x1a8(%rsp), %rsi
callq *%rax
jmp 0x2184f
movq 0x100(%rsp), %rdi
movq (%rdi), %rax
movq 0x68(%rax), %rax
leaq 0x190(%rsp), %rsi
leaq 0x178(%rsp), %rdx
callq *%rax
jmp 0x21872
movq 0x100(%rsp), %rdi
movl 0x174(%rsp), %esi
movl 0x170(%rsp), %edx
movq (%rdi), %rax
movq 0x70(%rax), %rax
callq *%rax
jmp 0x21893
movq 0x100(%rsp), %rax
movq %rax, 0x18(%rsp)
movsd 0x110(%rsp), %xmm0
movsd 0x108(%rsp), %xmm1
leaq 0xf0(%rsp), %rdi
callq 0x1630a0
jmp 0x218c1
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
movq 0x78(%rax), %rax
leaq 0xf0(%rsp), %rsi
callq *%rax
jmp 0x218d9
movq 0x100(%rsp), %rdi
movsd 0x120(%rsp), %xmm0
movq (%rdi), %rax
movq 0x88(%rax), %rax
callq *%rax
jmp 0x218f8
movq 0x100(%rsp), %rdi
movsd 0x118(%rsp), %xmm0
movq (%rdi), %rax
movq 0x90(%rax), %rax
callq *%rax
jmp 0x21917
movq 0x100(%rsp), %rdi
movq (%rdi), %rax
movq 0xc8(%rax), %rax
leaq 0x1d0(%rsp), %rsi
callq *%rax
jmp 0x21935
movq 0x6a8(%rsp), %rdi
movq 0x100(%rsp), %rsi
movq (%rdi), %rax
movq 0xa0(%rax), %rax
callq *%rax
jmp 0x21953
jmp 0x21955
movl 0x5e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5e4(%rsp)
jmp 0x213ac
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x5f0(%rsp)
movl %eax, 0x5ec(%rsp)
movl $0x1d8, %esi            # imm = 0x1D8
callq 0x16750
jmp 0x21a4b
cmpl $0x0, 0x242e26(%rip)    # 0x2647c0
je 0x21a19
movq 0x6a0(%rsp), %rsi
leaq 0x1d7177(%rip), %rdi    # 0x1f8b22
xorl %eax, %eax
callq 0x16090
jmp 0x219b4
leaq 0x690(%rsp), %rdi
callq 0x16ddf0
movsd %xmm0, 0x10(%rsp)
jmp 0x219c9
movsd 0x10(%rsp), %xmm0
leaq 0x1d6ba9(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
jmp 0x219df
leaq 0x5f8(%rsp), %rdi
callq 0x27480
movl %eax, 0xc(%rsp)
jmp 0x219f2
movl 0xc(%rsp), %esi
leaq 0x1d6caf(%rip), %rdi    # 0x1f86ac
xorl %eax, %eax
callq 0x16090
jmp 0x21a06
movq 0x239583(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
jmp 0x21a17
jmp 0x21a19
movl $0x1, 0x6b4(%rsp)
movl $0x1, 0x5e8(%rsp)
leaq 0x5f8(%rsp), %rdi
callq 0x2b2f0
movl 0x6b4(%rsp), %eax
addq $0x6b8, %rsp            # imm = 0x6B8
retq
leaq 0x5f8(%rsp), %rdi
callq 0x2b2f0
movq 0x5f0(%rsp), %rdi
callq 0x16ca0
nopw %cs:(%rax,%rax)