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

  // Read file
  int id, npoints, primitive_type;
  double area, total_affinity, possible_affinity, timestamp;
  R3Point centroid, center;
  R3Plane plane;
  RNRgb color;
  R3Vector axes[3];
  double variances[3];
  R3Box extent;
  while (fscanf(fp, "%d%d%lf%lf%lf%d%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",
    &id, &npoints, &area,
    &total_affinity, &possible_affinity, &primitive_type,
    &centroid[0], &centroid[1], &centroid[2],
    &plane[0], &plane[1], &plane[2], &plane[3], 
    &color[0], &color[1], &color[2],
    &timestamp,
    &center[0], &center[1], &center[2],
    &axes[0][0], &axes[0][1], &axes[0][2],
    &axes[1][0], &axes[1][1], &axes[1][2],
    &axes[2][0], &axes[2][1], &axes[2][2],
    &variances[0], &variances[1], &variances[2],
    &extent[0][0], &extent[0][1], &extent[0][2],
    &extent[1][0], &extent[1][1], &extent[1][2]) == (unsigned int) 38) {

    // Determine radii
    RNLength radius0 = 0.5 * (extent[1][0] - extent[0][0]);
    if (RNIsZero(radius0)) continue;
    RNLength radius1 = 0.5 * (extent[1][1] - extent[0][1]);
    if (RNIsZero(radius1)) continue;
    RNLength radius2 = 0.5 * (extent[1][2] - extent[0][2]);

    // Determine center of extent
    center += (radius0 + extent[0][0]) * axes[0];
    center += (radius1 + extent[0][1]) * axes[1];

    // Create rectangle
    R3Rectangle *rectangle = new R3Rectangle(center, axes[0], axes[1], radius0, radius1);

    // Create RGBD surface
    double texel_spacing = 0.01;
    RGBDSurface *rgbd_surface = new RGBDSurface(NULL, rectangle, texel_spacing);
    rgbd_surface->thickness = radius2;

    // Insert RGBD surface
    InsertSurface(rgbd_surface);
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x508, %rsp            # imm = 0x508
movq %rdi, 0x4f8(%rsp)
movq %rsi, 0x4f0(%rsp)
movq 0x4f8(%rsp), %rax
movq %rax, 0x330(%rsp)
movq 0x4f0(%rsp), %rdi
leaq 0x14e493(%rip), %rsi    # 0x16cba3
callq 0x12860
movq %rax, 0x4e8(%rsp)
cmpq $0x0, 0x4e8(%rsp)
jne 0x1e74e
movq 0x4f0(%rsp), %rsi
leaq 0x148369(%rip), %rdi    # 0x166aa0
movb $0x0, %al
callq 0xdf990
movl $0x0, 0x504(%rsp)
jmp 0x1f2f9
leaq 0x4a0(%rsp), %rdi
callq 0x8a990
leaq 0x488(%rsp), %rdi
callq 0x8a990
leaq 0x468(%rsp), %rdi
callq 0x87fd0
leaq 0x450(%rsp), %rdi
callq 0xdb180
leaq 0x400(%rsp), %rax
movq %rax, %rcx
addq $0x48, %rcx
movq %rcx, 0x320(%rsp)
movq %rax, 0x328(%rsp)
movq 0x328(%rsp), %rdi
movq %rdi, 0x318(%rsp)
callq 0x8baf0
movq 0x318(%rsp), %rax
movq 0x320(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0x328(%rsp)
jne 0x1e7a1
leaq 0x3a8(%rsp), %rdi
callq 0x75300
movq 0x4e8(%rsp), %rax
movq %rax, 0x308(%rsp)
leaq 0x4a0(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x310(%rsp)
jmp 0x1e80d
leaq 0x4a0(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x300(%rsp)
jmp 0x1e829
leaq 0x4a0(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x2f8(%rsp)
jmp 0x1e845
leaq 0x468(%rsp), %rdi
xorl %esi, %esi
callq 0x22760
movq %rax, 0x2f0(%rsp)
jmp 0x1e85e
leaq 0x468(%rsp), %rdi
movl $0x1, %esi
callq 0x22760
movq %rax, 0x2e8(%rsp)
jmp 0x1e87a
leaq 0x468(%rsp), %rdi
movl $0x2, %esi
callq 0x22760
movq %rax, 0x2e0(%rsp)
jmp 0x1e896
leaq 0x468(%rsp), %rdi
movl $0x3, %esi
callq 0x22760
movq %rax, 0x2d8(%rsp)
jmp 0x1e8b2
leaq 0x450(%rsp), %rdi
xorl %esi, %esi
callq 0x227b0
movq %rax, 0x2d0(%rsp)
jmp 0x1e8cb
leaq 0x450(%rsp), %rdi
movl $0x1, %esi
callq 0x227b0
movq %rax, 0x2c8(%rsp)
jmp 0x1e8e7
leaq 0x450(%rsp), %rdi
movl $0x2, %esi
callq 0x227b0
movq %rax, 0x2c0(%rsp)
jmp 0x1e903
leaq 0x488(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x2b8(%rsp)
jmp 0x1e91c
leaq 0x488(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x2b0(%rsp)
jmp 0x1e938
leaq 0x488(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x2a8(%rsp)
jmp 0x1e954
leaq 0x400(%rsp), %rdi
xorl %esi, %esi
callq 0x227d0
movq %rax, 0x2a0(%rsp)
jmp 0x1e96d
leaq 0x400(%rsp), %rdi
movl $0x1, %esi
callq 0x227d0
movq %rax, 0x298(%rsp)
jmp 0x1e989
leaq 0x400(%rsp), %rdi
movl $0x2, %esi
callq 0x227d0
movq %rax, 0x290(%rsp)
jmp 0x1e9a5
leaq 0x418(%rsp), %rdi
xorl %esi, %esi
callq 0x227d0
movq %rax, 0x288(%rsp)
jmp 0x1e9be
leaq 0x418(%rsp), %rdi
movl $0x1, %esi
callq 0x227d0
movq %rax, 0x280(%rsp)
jmp 0x1e9da
leaq 0x418(%rsp), %rdi
movl $0x2, %esi
callq 0x227d0
movq %rax, 0x278(%rsp)
jmp 0x1e9f6
leaq 0x430(%rsp), %rdi
xorl %esi, %esi
callq 0x227d0
movq %rax, 0x270(%rsp)
jmp 0x1ea0f
leaq 0x430(%rsp), %rdi
movl $0x1, %esi
callq 0x227d0
movq %rax, 0x268(%rsp)
jmp 0x1ea2b
leaq 0x430(%rsp), %rdi
movl $0x2, %esi
callq 0x227d0
movq %rax, 0x260(%rsp)
jmp 0x1ea47
leaq 0x3e0(%rsp), %rax
movq %rax, 0x240(%rsp)
leaq 0x3e8(%rsp), %rax
movq %rax, 0x248(%rsp)
leaq 0x3f0(%rsp), %rax
movq %rax, 0x250(%rsp)
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x258(%rsp)
jmp 0x1ea90
movq 0x258(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x238(%rsp)
jmp 0x1eaa9
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x230(%rsp)
jmp 0x1eac2
movq 0x230(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x228(%rsp)
jmp 0x1eade
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x220(%rsp)
jmp 0x1eaf7
movq 0x220(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x218(%rsp)
jmp 0x1eb13
leaq 0x3a8(%rsp), %rdi
movl $0x1, %esi
callq 0x19bc0
movq %rax, 0x210(%rsp)
jmp 0x1eb2f
movq 0x210(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x208(%rsp)
jmp 0x1eb48
leaq 0x3a8(%rsp), %rdi
movl $0x1, %esi
callq 0x19bc0
movq %rax, 0x200(%rsp)
jmp 0x1eb64
movq 0x200(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x1f8(%rsp)
jmp 0x1eb80
leaq 0x3a8(%rsp), %rdi
movl $0x1, %esi
callq 0x19bc0
movq %rax, 0x1f0(%rsp)
jmp 0x1eb9c
movq 0x1f0(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x1e8(%rsp)
jmp 0x1ebb8
movq 0x308(%rsp), %rdi
movq 0x300(%rsp), %rdx
movq 0x2f8(%rsp), %rsi
movq 0x2f0(%rsp), %r8
movq 0x2e8(%rsp), %r9
movq 0x2e0(%rsp), %r10
movq 0x2d8(%rsp), %r11
movq 0x2d0(%rsp), %rbx
movq 0x2c8(%rsp), %r14
movq 0x2c0(%rsp), %r15
movq 0x2b8(%rsp), %r12
movq 0x2b0(%rsp), %r13
movq 0x2a8(%rsp), %rbp
movq 0x1e8(%rsp), %rcx
movq %rsp, %rax
movq %rax, 0x1d8(%rsp)
movq %rcx, 0x108(%rax)
movq 0x1f8(%rsp), %rcx
movq %rcx, 0x100(%rax)
movq 0x208(%rsp), %rcx
movq %rcx, 0xf8(%rax)
movq 0x218(%rsp), %rcx
movq %rcx, 0xf0(%rax)
movq 0x228(%rsp), %rcx
movq %rcx, 0xe8(%rax)
movq 0x238(%rsp), %rcx
movq %rcx, 0xe0(%rax)
movq 0x250(%rsp), %rcx
movq %rcx, 0xd8(%rax)
movq 0x248(%rsp), %rcx
movq %rcx, 0xd0(%rax)
movq 0x240(%rsp), %rcx
movq %rcx, 0xc8(%rax)
movq 0x260(%rsp), %rcx
movq %rcx, 0xc0(%rax)
movq 0x268(%rsp), %rcx
movq %rcx, 0xb8(%rax)
movq 0x270(%rsp), %rcx
movq %rcx, 0xb0(%rax)
movq 0x278(%rsp), %rcx
movq %rcx, 0xa8(%rax)
movq 0x280(%rsp), %rcx
movq %rcx, 0xa0(%rax)
movq 0x288(%rsp), %rcx
movq %rcx, 0x98(%rax)
movq 0x290(%rsp), %rcx
movq %rcx, 0x90(%rax)
movq 0x298(%rsp), %rcx
movq %rcx, 0x88(%rax)
movq 0x2a0(%rsp), %rcx
movq %rcx, 0x80(%rax)
movq 0x310(%rsp), %rcx
movq %rbp, 0x78(%rax)
movq %r13, 0x70(%rax)
movq %r12, 0x68(%rax)
leaq 0x4b8(%rsp), %r12
movq %r12, 0x60(%rax)
movq %r15, 0x58(%rax)
movq %r14, 0x50(%rax)
movq %rbx, 0x48(%rax)
movq %r11, 0x40(%rax)
movq %r10, 0x38(%rax)
movq %r9, 0x30(%rax)
movq %r8, 0x28(%rax)
movq %rsi, 0x20(%rax)
movq %rdx, 0x18(%rax)
movq %rcx, 0x10(%rax)
leaq 0x4dc(%rsp), %rcx
movq %rcx, 0x8(%rax)
leaq 0x4c0(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x147d26(%rip), %rsi    # 0x166ac5
xorl %eax, %eax
leaq 0x4e4(%rsp), %rdx
leaq 0x4e0(%rsp), %rcx
leaq 0x4d0(%rsp), %r8
leaq 0x4c8(%rsp), %r9
callq 0x12cb0
movl %eax, 0x1e4(%rsp)
jmp 0x1edcf
movl 0x1e4(%rsp), %eax
cmpl $0x26, %eax
jne 0x1f2c1
leaq 0x3a8(%rsp), %rdi
movl $0x1, %esi
callq 0x19bc0
movq %rax, 0x1d0(%rsp)
jmp 0x1edfb
movq 0x1d0(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x1c8(%rsp)
jmp 0x1ee14
movq 0x1c8(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x1b8(%rsp)
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x1c0(%rsp)
jmp 0x1ee42
movq 0x1c0(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x1b0(%rsp)
jmp 0x1ee5b
movsd 0x1b8(%rsp), %xmm0
movq 0x1b0(%rsp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd 0x1471ac(%rip), %xmm1   # 0x166028
mulsd %xmm1, %xmm0
movsd %xmm0, 0x390(%rsp)
movsd 0x390(%rsp), %xmm0
leaq 0x193027(%rip), %rax    # 0x1b1ec0
movsd (%rax), %xmm1
callq 0x1a370
movl %eax, 0x1ac(%rsp)
jmp 0x1eeab
movl 0x1ac(%rsp), %eax
cmpl $0x0, %eax
je 0x1eed5
jmp 0x1e7e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a0(%rsp)
movl %eax, 0x39c(%rsp)
jmp 0x1f2ea
leaq 0x3a8(%rsp), %rdi
movl $0x1, %esi
callq 0x19bc0
movq %rax, 0x1a0(%rsp)
jmp 0x1eef1
movq 0x1a0(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x198(%rsp)
jmp 0x1ef0d
movq 0x198(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x188(%rsp)
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x190(%rsp)
jmp 0x1ef3b
movq 0x190(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x180(%rsp)
jmp 0x1ef57
movsd 0x188(%rsp), %xmm0
movq 0x180(%rsp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd 0x1470b0(%rip), %xmm1   # 0x166028
mulsd %xmm1, %xmm0
movsd %xmm0, 0x388(%rsp)
movsd 0x388(%rsp), %xmm0
leaq 0x192f2b(%rip), %rax    # 0x1b1ec0
movsd (%rax), %xmm1
callq 0x1a370
movl %eax, 0x17c(%rsp)
jmp 0x1efa7
movl 0x17c(%rsp), %eax
cmpl $0x0, %eax
je 0x1efb8
jmp 0x1e7e4
leaq 0x3a8(%rsp), %rdi
movl $0x1, %esi
callq 0x19bc0
movq %rax, 0x170(%rsp)
jmp 0x1efd4
movq 0x170(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x168(%rsp)
jmp 0x1eff0
movq 0x168(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x158(%rsp)
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x160(%rsp)
jmp 0x1f01e
movq 0x160(%rsp), %rdi
movl $0x2, %esi
callq 0x19c00
movq %rax, 0x150(%rsp)
jmp 0x1f03a
movsd 0x158(%rsp), %xmm0
movq 0x150(%rsp), %rax
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd 0x146fcd(%rip), %xmm1   # 0x166028
mulsd %xmm1, %xmm0
movsd %xmm0, 0x380(%rsp)
movsd 0x390(%rsp), %xmm0
movsd %xmm0, 0x140(%rsp)
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x148(%rsp)
jmp 0x1f093
movq 0x148(%rsp), %rdi
xorl %esi, %esi
callq 0x19c00
movq %rax, 0x138(%rsp)
jmp 0x1f0ac
movsd 0x140(%rsp), %xmm0
movq 0x138(%rsp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
leaq 0x368(%rsp), %rdi
leaq 0x400(%rsp), %rsi
callq 0x227f0
jmp 0x1f0dc
leaq 0x488(%rsp), %rdi
leaq 0x368(%rsp), %rsi
callq 0x8b0e0
jmp 0x1f0f3
movsd 0x388(%rsp), %xmm0
movsd %xmm0, 0x128(%rsp)
leaq 0x3a8(%rsp), %rdi
xorl %esi, %esi
callq 0x19bc0
movq %rax, 0x130(%rsp)
jmp 0x1f11e
movq 0x130(%rsp), %rdi
movl $0x1, %esi
callq 0x19c00
movq %rax, 0x120(%rsp)
jmp 0x1f13a
movsd 0x128(%rsp), %xmm0
movq 0x120(%rsp), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
leaq 0x418(%rsp), %rsi
leaq 0x350(%rsp), %rdi
callq 0x227f0
jmp 0x1f16a
leaq 0x488(%rsp), %rdi
leaq 0x350(%rsp), %rsi
callq 0x8b0e0
jmp 0x1f181
movl $0x78, %edi
callq 0x126d0
movq %rax, 0x118(%rsp)
jmp 0x1f195
movq 0x118(%rsp), %rdi
leaq 0x418(%rsp), %rcx
movsd 0x390(%rsp), %xmm0
movsd 0x388(%rsp), %xmm1
leaq 0x488(%rsp), %rsi
leaq 0x400(%rsp), %rdx
callq 0x711f0
jmp 0x1f1ce
movq 0x118(%rsp), %rax
movq %rax, 0x348(%rsp)
movabsq $0x3f847ae147ae147b, %rax # imm = 0x3F847AE147AE147B
movq %rax, 0x340(%rsp)
movl $0xa0, %edi
callq 0x126d0
movq %rax, 0x110(%rsp)
jmp 0x1f204
movq 0x110(%rsp), %rdi
movq 0x348(%rsp), %rdx
movsd 0x340(%rsp), %xmm0
xorl %eax, %eax
movl %eax, %esi
callq 0x23ce0
jmp 0x1f228
movq 0x330(%rsp), %rdi
movq 0x110(%rsp), %rax
movq %rax, 0x338(%rsp)
movsd 0x380(%rsp), %xmm0
movq 0x338(%rsp), %rax
movsd %xmm0, 0x98(%rax)
movq 0x338(%rsp), %rsi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
jmp 0x1f26c
jmp 0x1e7e4
movq 0x118(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a0(%rsp)
movl %eax, 0x39c(%rsp)
movl $0x78, %esi
callq 0x126e0
jmp 0x1f2ea
movq 0x110(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a0(%rsp)
movl %eax, 0x39c(%rsp)
movl $0xa0, %esi
callq 0x126e0
jmp 0x1f2ea
movq 0x4e8(%rsp), %rdi
callq 0x126c0
jmp 0x1f2d0
movl $0x1, 0x504(%rsp)
leaq 0x3a8(%rsp), %rdi
callq 0x19b90
jmp 0x1f2f9
leaq 0x3a8(%rsp), %rdi
callq 0x19b90
jmp 0x1f312
movl 0x504(%rsp), %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3a0(%rsp), %rdi
callq 0x12c20
nop