// File: /workspace/github_cpp_makefile_star2_O1/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 $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movq %rdi, 0x50(%rsp)
leaq 0xab2dd(%rip), %rsi     # 0xc3a33
movq %rbx, %rdi
callq 0x11710
testq %rax, %rax
je 0x18a90
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x4be44
leaq 0x128(%rsp), %r12
movq %r12, %rdi
callq 0x4be44
leaq 0xa0(%rsp), %rdi
callq 0x4a934
leaq 0x70(%rsp), %rdi
callq 0x76068
xorl %ebx, %ebx
leaq (%rsp,%rbx), %rdi
addq $0xc0, %rdi
callq 0x4c8dc
addq $0x18, %rbx
cmpq $0x48, %rbx
jne 0x187a0
leaq 0x18(%rsp), %rdi
callq 0x43634
leaq 0xd8(%rsp), %rbx
leaq 0xc0(%rsp), %r15
movq %r14, %rdi
leaq 0xa52ff(%rip), %rsi     # 0xbdadd
leaq 0x6c(%rsp), %rdx
leaq 0x68(%rsp), %rcx
leaq 0x158(%rsp), %r8
leaq 0x150(%rsp), %r9
xorl %eax, %eax
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x150(%rsp), %r10
pushq %r10
leaq 0x150(%rsp), %r10
pushq %r10
leaq 0x150(%rsp), %r10
pushq %r10
leaq 0x148(%rsp), %r10
pushq %r10
leaq 0x148(%rsp), %r10
pushq %r10
leaq 0x148(%rsp), %r10
pushq %r10
leaq 0x148(%rsp), %r10
pushq %r10
leaq 0x148(%rsp), %r10
pushq %r10
pushq %rbx
leaq 0x148(%rsp), %r10
pushq %r10
leaq 0x148(%rsp), %r10
pushq %r10
pushq %r15
leaq 0x1c8(%rsp), %r10
pushq %r10
leaq 0x1c8(%rsp), %r10
pushq %r10
pushq %r12
leaq 0x1e8(%rsp), %r10
pushq %r10
leaq 0x130(%rsp), %r10
pushq %r10
leaq 0x130(%rsp), %r10
pushq %r10
leaq 0x130(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x180(%rsp), %r10
pushq %r10
leaq 0x164(%rsp), %r10
pushq %r10
leaq 0x250(%rsp), %r10
pushq %r10
callq 0x11ae0
addq $0x110, %rsp            # imm = 0x110
cmpl $0x26, %eax
jne 0x18a77
movsd 0x20(%rsp), %xmm0
movsd 0x38(%rsp), %xmm3
subsd %xmm0, %xmm3
mulsd 0xa46d0(%rip), %xmm3    # 0xbd020
leaq 0xee391(%rip), %rax     # 0x106ce8
movsd (%rax), %xmm1
movapd %xmm1, %xmm2
xorpd 0xa46e9(%rip), %xmm2    # 0xbd050
movsd %xmm3, 0x8(%rsp)
ucomisd %xmm2, %xmm3
jb 0x1897f
ucomisd 0x8(%rsp), %xmm1
jae 0x187d4
movsd 0x40(%rsp), %xmm3
subsd 0x28(%rsp), %xmm3
mulsd 0xa468d(%rip), %xmm3    # 0xbd020
ucomisd %xmm2, %xmm3
jb 0x189a3
ucomisd %xmm3, %xmm1
jae 0x187d4
movsd %xmm3, 0x10(%rsp)
movsd 0x48(%rsp), %xmm1
subsd 0x30(%rsp), %xmm1
mulsd 0xa4663(%rip), %xmm1    # 0xbd020
movsd %xmm1, 0x58(%rsp)
addsd 0x8(%rsp), %xmm0
leaq 0x160(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x4d2ae
movq %r12, %rdi
movq %r13, %rsi
callq 0x4c22e
movsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4d2ae
movq %r12, %rdi
movq %r13, %rsi
callq 0x4c22e
movl $0x78, %edi
callq 0x115b0
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x413ec
movl $0xa0, %edi
callq 0x115b0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movsd 0xa4a60(%rip), %xmm0    # 0xbd4b0
callq 0x1ac82
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x98(%r13)
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq %r13, %rsi
callq *0x20(%rax)
jmp 0x187d4
movq %r14, %rdi
callq 0x115a0
leaq 0x18(%rsp), %rdi
callq 0x444d0
movl $0x1, %ebp
jmp 0x18aa3
leaq 0xa5021(%rip), %rdi     # 0xbdab8
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x79092
movl %ebp, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x78, %esi
movq %rbp, %rdi
jmp 0x18acf
movq %rax, %rbx
movl $0xa0, %esi
movq %r13, %rdi
callq 0x115c0
jmp 0x18ae1
jmp 0x18ade
jmp 0x18ade
jmp 0x18ade
jmp 0x18ade
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x444d0
movq %rbx, %rdi
callq 0x11a70
nop