// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVRun.cpp
// Function: gaps::GSVRun::ReadCameraInfoFile()
int GSVRun::
ReadCameraInfoFile(void)
{
  // Create filename
  char filename[4096];
  sprintf(filename, "%s/%s/camera_info.txt", scene->RawDataDirectoryName(), Name());

  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open camera info file: %s\n", filename);
    return 0;
  }

  // Read camera information
  GSVCamera *camera = NULL;
  const int buffer_size = 16*1024;
  char buffer[buffer_size];
  while (fgets(buffer, buffer_size, fp)) {
    // Parse line
    char *keyword = strtok(buffer, ": \t\n");
    if (!keyword) continue;
    if (keyword[0] == '#') continue;
    char *string = strtok(NULL, ": \t\n");
    RNScalar value = atof(string);

    // First line should have number
    if (!strcmp(keyword, "camera_number")) {
      int ncameras = atoi(string);
      for (int i = 0; i < ncameras; i++) {
        GSVCamera *camera = new GSVCamera();
        InsertCamera(camera);
      }
    }
    else if (!strcmp(keyword, "camera_index")) {
      int index = atoi(string);
      if ((index >= 0) && (index < NCameras())) {
        camera = Camera(index);
      }
    }
    else if (camera) {
      if (!strcmp(keyword, "focal_x")) camera->SetXFocal(value);
      else if (!strcmp(keyword, "focal_y")) camera->SetYFocal(value);
      else if (!strcmp(keyword, "center_x")) camera->SetXCenter(value);
      else if (!strcmp(keyword, "center_y")) camera->SetYCenter(value);
      else if (!strcmp(keyword, "distortion_type")) camera->SetDistortionType((!strcmp(string, "PERSPECTIVE")) ? 0 : 1);
      else if (!strcmp(keyword, "k1")) camera->SetK1(value);
      else if (!strcmp(keyword, "k2")) camera->SetK2(value);
      else if (!strcmp(keyword, "k3")) camera->SetK3(value);
      else if (!strcmp(keyword, "p1")) camera->SetP1(value);
      else if (!strcmp(keyword, "p2")) camera->SetP2(value);
      else if (!strcmp(keyword, "fov_max")) camera->SetMaxFov(RN_PI*value/180.0);
    }
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
subq $0x50a8, %rsp           # imm = 0x50A8
movq %rdi, 0x5098(%rsp)
movq 0x5098(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x4090(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x8(%rax), %rdi
callq 0x47cf0
movq 0x20(%rsp), %rdi
movq %rax, 0x30(%rsp)
callq 0x44310
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
leaq 0x220d53(%rip), %rsi    # 0x266dc8
movb $0x0, %al
callq 0x2a280
leaq 0x4090(%rsp), %rdi
leaq 0x23d368(%rip), %rsi    # 0x2833f3
callq 0x2a520
movq %rax, 0x4088(%rsp)
cmpq $0x0, 0x4088(%rsp)
jne 0x460c9
leaq 0x4090(%rsp), %rsi
leaq 0x220d2c(%rip), %rdi    # 0x266dde
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x50a4(%rsp)
jmp 0x464d1
movq $0x0, 0x4080(%rsp)
movl $0x4000, 0x407c(%rsp) # imm = 0x4000
leaq 0x70(%rsp), %rdi
movq 0x4088(%rsp), %rdx
movl $0x4000, %esi           # imm = 0x4000
callq 0x29bd0
cmpq $0x0, %rax
je 0x464b9
leaq 0x70(%rsp), %rdi
leaq 0x220cf6(%rip), %rsi    # 0x266e03
callq 0x29520
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x68(%rsp)
jne 0x46121
jmp 0x460e0
movq 0x68(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x46130
jmp 0x460e0
xorl %eax, %eax
movl %eax, %edi
leaq 0x220cc8(%rip), %rsi    # 0x266e03
callq 0x29520
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
callq 0x29ef0
movsd %xmm0, 0x58(%rsp)
movq 0x68(%rsp), %rdi
leaq 0x220ca7(%rip), %rsi    # 0x266e08
callq 0x29f00
cmpl $0x0, %eax
jne 0x461f8
movq 0x60(%rsp), %rdi
callq 0x29610
movl %eax, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x461f3
movl $0xc8, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x4c610
jmp 0x461ab
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rsi
callq 0x45990
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x46185
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl $0xc8, %esi
callq 0x291f0
jmp 0x464e0
jmp 0x464b4
movq 0x68(%rsp), %rdi
leaq 0x220c12(%rip), %rsi    # 0x266e16
callq 0x29f00
cmpl $0x0, %eax
jne 0x4625a
movq 0x60(%rsp), %rdi
callq 0x29610
movl %eax, 0x38(%rsp)
cmpl $0x0, 0x38(%rsp)
jl 0x46255
movq 0x20(%rsp), %rdi
movl 0x38(%rsp), %eax
movl %eax, 0x14(%rsp)
callq 0x44320
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x46255
movq 0x20(%rsp), %rdi
movl 0x38(%rsp), %esi
callq 0x447e0
movq %rax, 0x4080(%rsp)
jmp 0x464b2
cmpq $0x0, 0x4080(%rsp)
je 0x464b0
movq 0x68(%rsp), %rdi
leaq 0x220bae(%rip), %rsi    # 0x266e23
callq 0x29f00
cmpl $0x0, %eax
jne 0x46297
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cb10
jmp 0x464ae
movq 0x68(%rsp), %rdi
leaq 0x220b88(%rip), %rsi    # 0x266e2b
callq 0x29f00
cmpl $0x0, %eax
jne 0x462c5
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cb30
jmp 0x464ac
movq 0x68(%rsp), %rdi
leaq 0x220b62(%rip), %rsi    # 0x266e33
callq 0x29f00
cmpl $0x0, %eax
jne 0x462f3
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cb50
jmp 0x464aa
movq 0x68(%rsp), %rdi
leaq 0x220b3d(%rip), %rsi    # 0x266e3c
callq 0x29f00
cmpl $0x0, %eax
jne 0x46321
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cb70
jmp 0x464a8
movq 0x68(%rsp), %rdi
leaq 0x220b18(%rip), %rsi    # 0x266e45
callq 0x29f00
cmpl $0x0, %eax
jne 0x4637a
movq 0x4080(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x220b05(%rip), %rsi    # 0x266e55
callq 0x29f00
movq 0x8(%rsp), %rdi
cmpl $0x0, %eax
setne %cl
xorb $-0x1, %cl
movl $0x1, %esi
xorl %eax, %eax
testb $0x1, %cl
cmovnel %eax, %esi
callq 0x4cab0
jmp 0x464a6
movq 0x68(%rsp), %rdi
leaq 0x220adb(%rip), %rsi    # 0x266e61
callq 0x29f00
cmpl $0x0, %eax
jne 0x463a8
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cb90
jmp 0x464a4
movq 0x68(%rsp), %rdi
leaq 0x220ab0(%rip), %rsi    # 0x266e64
callq 0x29f00
cmpl $0x0, %eax
jne 0x463d6
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cbb0
jmp 0x464a2
movq 0x68(%rsp), %rdi
leaq 0x220a85(%rip), %rsi    # 0x266e67
callq 0x29f00
cmpl $0x0, %eax
jne 0x46404
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cbd0
jmp 0x464a0
movq 0x68(%rsp), %rdi
leaq 0x220a5a(%rip), %rsi    # 0x266e6a
callq 0x29f00
cmpl $0x0, %eax
jne 0x4642f
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cbf0
jmp 0x4649e
movq 0x68(%rsp), %rdi
leaq 0x220a32(%rip), %rsi    # 0x266e6d
callq 0x29f00
cmpl $0x0, %eax
jne 0x4645a
movq 0x4080(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4cc10
jmp 0x4649c
movq 0x68(%rsp), %rdi
leaq 0x220a0a(%rip), %rsi    # 0x266e70
callq 0x29f00
cmpl $0x0, %eax
jne 0x4649a
movq 0x4080(%rsp), %rdi
leaq 0x227af9(%rip), %rax    # 0x26df78
movsd (%rax), %xmm0
mulsd 0x58(%rsp), %xmm0
movsd 0x220917(%rip), %xmm1   # 0x266da8
divsd %xmm1, %xmm0
callq 0x4cc30
jmp 0x4649c
jmp 0x4649e
jmp 0x464a0
jmp 0x464a2
jmp 0x464a4
jmp 0x464a6
jmp 0x464a8
jmp 0x464aa
jmp 0x464ac
jmp 0x464ae
jmp 0x464b0
jmp 0x464b2
jmp 0x464b4
jmp 0x460e0
movq 0x4088(%rsp), %rdi
callq 0x297e0
movl $0x1, 0x50a4(%rsp)
movl 0x50a4(%rsp), %eax
addq $0x50a8, %rsp           # imm = 0x50A8
retq
movq 0x40(%rsp), %rdi
callq 0x29c10
nopw (%rax,%rax)