// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5018, %rsp           # imm = 0x5018
movq %rdi, %r14
movq 0x8(%rdi), %rax
movq 0x48(%rdi), %rcx
movq 0x20(%rax), %rdx
leaq 0xf566d(%rip), %rsi     # 0x12bcd8
xorl %r12d, %r12d
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x27140
leaq 0x116a1f(%rip), %rsi    # 0x14d0a3
movq %rbx, %rdi
callq 0x27b20
testq %rax, %rax
je 0x36989
movq %rax, %r15
leaq 0x100b59(%rip), %rax    # 0x1371f8
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x1010(%rsp), %r12
xorl %ecx, %ecx
movq %rcx, %rbp
movq %r12, %rdi
movl $0x4000, %esi           # imm = 0x4000
movq %r15, %rdx
callq 0x27fe0
testq %rax, %rax
je 0x3697b
movq %r12, %rdi
leaq 0xf563a(%rip), %rsi     # 0x12bd13
callq 0x27f90
movq %rbp, %rcx
testq %rax, %rax
je 0x366b3
movq %rax, %rbx
cmpb $0x23, (%rax)
movq %rbp, %rcx
je 0x366b3
xorl %edi, %edi
leaq 0xf5619(%rip), %rsi     # 0x12bd13
callq 0x27f90
movq %rax, %r13
movq %rax, %rdi
callq 0x27c00
movsd %xmm0, (%rsp)
movq %rbx, %rdi
leaq 0xf55ff(%rip), %rsi     # 0x12bd18
callq 0x27db0
testl %eax, %eax
je 0x36819
movq %rbx, %rdi
leaq 0xf55f6(%rip), %rsi     # 0x12bd26
callq 0x27db0
testl %eax, %eax
je 0x36858
movl $0x0, %ecx
testq %rbp, %rbp
je 0x366b3
movq %rbx, %rdi
leaq 0xf55de(%rip), %rsi     # 0x12bd33
callq 0x27db0
testl %eax, %eax
je 0x36887
movq %rbx, %rdi
leaq 0xf55cf(%rip), %rsi     # 0x12bd3b
callq 0x27db0
testl %eax, %eax
je 0x36899
movq %rbx, %rdi
leaq 0xf55c0(%rip), %rsi     # 0x12bd43
callq 0x27db0
testl %eax, %eax
je 0x368ab
movq %rbx, %rdi
leaq 0xf55b2(%rip), %rsi     # 0x12bd4c
callq 0x27db0
testl %eax, %eax
je 0x368ba
movq %rbx, %rdi
leaq 0xf55a4(%rip), %rsi     # 0x12bd55
callq 0x27db0
testl %eax, %eax
je 0x368c9
movzbl (%rbx), %eax
cmpl $0x70, %eax
je 0x368ea
cmpl $0x6b, %eax
jne 0x36902
cmpb $0x31, 0x1(%rbx)
jne 0x367e3
cmpb $0x0, 0x2(%rbx)
je 0x3693f
cmpb $0x32, 0x1(%rbx)
jne 0x367f3
cmpb $0x0, 0x2(%rbx)
je 0x3695d
cmpb $0x33, 0x1(%rbx)
jne 0x36902
cmpb $0x0, 0x2(%rbx)
jne 0x36902
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397e2
jmp 0x36937
movq %r13, %rdi
callq 0x27f80
movl %eax, %ebx
testl %eax, %eax
movl $0x0, %eax
cmovlel %eax, %ebx
subl $0x1, %ebx
jb 0x36937
movl $0xc8, %edi
callq 0x27940
movq %rax, %r13
movq %rax, %rdi
callq 0x3955c
movq %r14, %rdi
movq %r13, %rsi
callq 0x36364
jmp 0x3682d
movq %r13, %rdi
callq 0x27f80
movq %rbp, %rcx
testl %eax, %eax
js 0x366b3
movq %rbp, %rcx
cmpl 0x34(%r14), %eax
jge 0x366b3
movq 0x28(%r14), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
jmp 0x366b3
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397be
jmp 0x36937
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397c4
jmp 0x36937
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397ca
jmp 0x36937
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397d0
jmp 0x36937
movq %r13, %rdi
leaq 0xf5492(%rip), %rsi     # 0x12bd65
callq 0x27db0
xorl %esi, %esi
testl %eax, %eax
setne %sil
movq %rbp, %rdi
callq 0x397b2
jmp 0x36937
cmpb $0x31, 0x1(%rbx)
jne 0x368f6
cmpb $0x0, 0x2(%rbx)
je 0x3694e
cmpb $0x32, 0x1(%rbx)
jne 0x36902
cmpb $0x0, 0x2(%rbx)
je 0x3696c
movq %rbx, %rdi
leaq 0xf5465(%rip), %rsi     # 0x12bd71
callq 0x27db0
movq %rbp, %rcx
testl %eax, %eax
jne 0x366b3
movsd (%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
divsd 0xf5381(%rip), %xmm0    # 0x12bcb0
movq %rbp, %rdi
callq 0x397f4
movq %rbp, %rcx
jmp 0x366b3
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397d6
jmp 0x36937
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397e8
jmp 0x36937
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397dc
jmp 0x36937
movq %rbp, %rdi
movsd (%rsp), %xmm0
callq 0x397ee
jmp 0x36937
movq %r15, %rdi
callq 0x27930
pushq $0x1
popq %r12
jmp 0x3699c
leaq 0xf535e(%rip), %rdi     # 0x12bcee
leaq 0x10(%rsp), %rsi
xorl %eax, %eax
callq 0xe434a
movl %r12d, %eax
addq $0x5018, %rsp           # imm = 0x5018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0xc8, %esi
movq %r13, %rdi
callq 0x27960
movq %rbx, %rdi
callq 0x28170
nop