// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDConfiguration.cpp
// Function: gaps::RGBDConfiguration::WriteCameraFile(char const*, int) const
int RGBDConfiguration::
WriteCameraFile(const char *filename, int write_every_kth_image) const
{
  // Open file
  FILE *fp = fopen(filename, "w");
  if (!fp) {
    RNFail("Unable to open camera file %s\n", filename);
    return 0;
  }

  // Write images
  for (int i = 0; i < NImages(); i++) {
    if ((write_every_kth_image > 1) && ((i % write_every_kth_image) != 0)) continue;
    RGBDImage *image = Image(i);
    R3Point viewpoint = image->WorldViewpoint();
    R3Vector towards = image->WorldTowards();
    R3Vector up = image->WorldUp();
    RNAngle xfov = image->XFov();
    RNAngle yfov = image->YFov();
    fprintf(fp, "%f %f %f   %f %f %f   %f %f %f  %f %f  1\n",
      viewpoint[0], viewpoint[1], viewpoint[2],
      towards[0], towards[1], towards[2],
      up[0], up[1], up[2],
      xfov, yfov);
  }
  
  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movl %edx, 0xec(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0x147c00(%rip), %rsi    # 0x1688aa
callq 0x12860
movq %rax, 0xe0(%rsp)
cmpq $0x0, 0xe0(%rsp)
jne 0x20ce8
movq 0xf0(%rsp), %rsi
leaq 0x14606c(%rip), %rdi    # 0x166d3d
movb $0x0, %al
callq 0xdf990
movl $0x0, 0x104(%rsp)
jmp 0x20f4b
movl $0x0, 0xdc(%rsp)
movq 0x70(%rsp), %rdi
movl 0xdc(%rsp), %eax
movl %eax, 0x6c(%rsp)
callq 0x19c40
movl %eax, %ecx
movl 0x6c(%rsp), %eax
cmpl %ecx, %eax
jge 0x20f33
cmpl $0x1, 0xec(%rsp)
jle 0x20d39
movl 0xdc(%rsp), %eax
cltd
idivl 0xec(%rsp)
cmpl $0x0, %edx
je 0x20d39
jmp 0x20f1d
movq 0x70(%rsp), %rdi
movl 0xdc(%rsp), %esi
callq 0x19c90
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x19db0
movq 0xd0(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x1a320
movq 0xd0(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x22a50
movq 0xd0(%rsp), %rdi
callq 0x229b0
movsd %xmm0, 0x80(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x22aa0
movsd %xmm0, 0x78(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0xb8(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0xb8(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
callq 0x227d0
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0xa0(%rsp), %rdi
movl $0x1, %esi
callq 0x227d0
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0xa0(%rsp), %rdi
movl $0x2, %esi
callq 0x227d0
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x227d0
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x227d0
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x227d0
movq 0x20(%rsp), %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x48(%rsp), %xmm4
movsd 0x50(%rsp), %xmm5
movsd 0x58(%rsp), %xmm6
movsd 0x60(%rsp), %xmm7
movsd (%rax), %xmm10
movsd 0x80(%rsp), %xmm9
movsd 0x78(%rsp), %xmm8
leaq 0x145e5a(%rip), %rsi    # 0x166d5c
movsd %xmm10, (%rsp)
movsd %xmm9, 0x8(%rsp)
movsd %xmm8, 0x10(%rsp)
movb $0x8, %al
callq 0x12a30
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x20cf3
movq 0xe0(%rsp), %rdi
callq 0x126c0
movl $0x1, 0x104(%rsp)
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
nopw (%rax,%rax)