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

  // Read file
  R3Point center;
  R3Vector axis[2];
  double radius[3];
  while (fscanf(fp, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
    &center[0], &center[1], &center[2],
    &axis[0][0], &axis[0][1], &axis[0][2],
    &axis[1][0], &axis[1][1], &axis[1][2],
    &radius[0], &radius[1], &radius[2]) == (unsigned int) 12) {
    // Make sure axes are orthogonal
    axis[0].Normalize();
    R3Vector axis2 = axis[0] % axis[1];
    axis[1] = axis2 % axis[0];
    axis[1].Normalize();
    
    // Create rectangle
    R3Rectangle *rectangle = new R3Rectangle(center,
      axis[0], axis[1], radius[0], radius[1]);

    // Create RGBD surface
    RGBDSurface *rgbd_surface = new RGBDSurface(NULL, rectangle);
    rgbd_surface->thickness = radius[2];

    // Insert RGBD surface
    InsertSurface(rgbd_surface);
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, 0x190(%rsp)
movq %rsi, 0x188(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x188(%rsp), %rdi
leaq 0x14d844(%rip), %rsi    # 0x16cba3
callq 0x12860
movq %rax, 0x180(%rsp)
cmpq $0x0, 0x180(%rsp)
jne 0x1f39d
movq 0x188(%rsp), %rsi
leaq 0x1477af(%rip), %rdi    # 0x166b35
movb $0x0, %al
callq 0xdf990
movl $0x0, 0x19c(%rsp)
jmp 0x1f6f0
leaq 0x168(%rsp), %rdi
callq 0x8a990
leaq 0x130(%rsp), %rax
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x8baf0
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0xb0(%rsp)
jne 0x1f3c9
jmp 0x1f401
movq 0x180(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x168(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x80(%rsp)
leaq 0x168(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x88(%rsp)
leaq 0x168(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x90(%rsp)
leaq 0x130(%rsp), %rdi
xorl %esi, %esi
callq 0x227d0
movq %rax, 0x98(%rsp)
leaq 0x130(%rsp), %rdi
movl $0x1, %esi
callq 0x227d0
movq %rax, %r13
leaq 0x130(%rsp), %rdi
movl $0x2, %esi
callq 0x227d0
movq %rax, %r12
leaq 0x130(%rsp), %rdi
addq $0x18, %rdi
xorl %esi, %esi
callq 0x227d0
movq %rax, %r15
leaq 0x130(%rsp), %rdi
addq $0x18, %rdi
movl $0x1, %esi
callq 0x227d0
movq %rax, %r14
leaq 0x130(%rsp), %rdi
addq $0x18, %rdi
movl $0x2, %esi
callq 0x227d0
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rdx
movq 0x88(%rsp), %rcx
movq 0x90(%rsp), %r8
movq 0x98(%rsp), %r9
movq %rax, %rbx
leaq 0x110(%rsp), %r11
leaq 0x110(%rsp), %r10
addq $0x8, %r10
leaq 0x110(%rsp), %rax
addq $0x10, %rax
leaq 0x1475e2(%rip), %rsi    # 0x166b10
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movb $0x0, %al
callq 0x12cb0
cmpl $0xc, %eax
jne 0x1f6d8
leaq 0x130(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x8c260
movq 0x60(%rsp), %rsi
leaq 0x148(%rsp), %rdx
movq %rdx, 0x68(%rsp)
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8c940
movq 0x50(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0xe0(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x8c940
movq 0x58(%rsp), %rsi
movq 0x68(%rsp), %rdi
callq 0x8c7c0
movq 0x68(%rsp), %rdi
callq 0x8c260
movl $0x78, %edi
callq 0x126d0
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x70(%rsp)
movsd 0x110(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
leaq 0x168(%rsp), %rsi
callq 0x711f0
jmp 0x1f610
movq 0x70(%rsp), %rax
movq %rax, 0xd8(%rsp)
movl $0xa0, %edi
callq 0x126d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movq 0xd8(%rsp), %rdx
xorl %eax, %eax
movl %eax, %esi
movsd 0x146f0a(%rip), %xmm0   # 0x166550
callq 0x23ce0
jmp 0x1f64d
movq 0xb8(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, 0xc0(%rsp)
movsd 0x120(%rsp), %xmm0
movq 0xc0(%rsp), %rax
movsd %xmm0, 0x98(%rax)
movq 0xc0(%rsp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
jmp 0x1f401
movq 0x70(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
movl $0x78, %esi
callq 0x126e0
jmp 0x1f708
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
movl $0xa0, %esi
callq 0x126e0
jmp 0x1f708
movq 0x180(%rsp), %rdi
callq 0x126c0
movl $0x1, 0x19c(%rsp)
movl 0x19c(%rsp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xd0(%rsp), %rdi
callq 0x12c20
nopw %cs:(%rax,%rax)