// File: /workspace/github_cpp_makefile_star2_O2/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 0x96d51(%rip), %rsi     # 0xae713
movq %rbx, %rdi
callq 0x11700
testq %rax, %rax
je 0x17cf8
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x45d4a
leaq 0x128(%rsp), %r12
movq %r12, %rdi
callq 0x45d4a
leaq 0xa0(%rsp), %rdi
callq 0x4491a
leaq 0x70(%rsp), %rdi
callq 0x6bf12
xorl %ebx, %ebx
leaq (%rsp,%rbx), %rdi
addq $0xc0, %rdi
callq 0x4650a
addq $0x18, %rbx
cmpq $0x48, %rbx
jne 0x17a0c
leaq 0x18(%rsp), %rdi
callq 0x3e166
leaq 0xd8(%rsp), %rbx
leaq 0xc0(%rsp), %r15
movq %r14, %rdi
leaq 0x91013(%rip), %rsi     # 0xa8a5d
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 0x11af0
addq $0x110, %rsp            # imm = 0x110
cmpl $0x26, %eax
jne 0x17ce1
movsd 0x20(%rsp), %xmm0
movsd 0x38(%rsp), %xmm3
subsd %xmm0, %xmm3
mulsd 0x9045c(%rip), %xmm3    # 0xa8018
leaq 0xe0135(%rip), %rax     # 0xf7cf8
movsd (%rax), %xmm1
movapd %xmm1, %xmm2
xorpd 0x9047d(%rip), %xmm2    # 0xa8050
movsd %xmm3, 0x8(%rsp)
ucomisd %xmm2, %xmm3
jb 0x17beb
ucomisd 0x8(%rsp), %xmm1
jae 0x17a40
movsd 0x40(%rsp), %xmm3
subsd 0x28(%rsp), %xmm3
mulsd 0x90419(%rip), %xmm3    # 0xa8018
ucomisd %xmm2, %xmm3
jb 0x17c0f
ucomisd %xmm3, %xmm1
jae 0x17a40
movsd %xmm3, 0x10(%rsp)
movsd 0x48(%rsp), %xmm1
subsd 0x30(%rsp), %xmm1
mulsd 0x903ef(%rip), %xmm1    # 0xa8018
movsd %xmm1, 0x58(%rsp)
addsd 0x8(%rsp), %xmm0
leaq 0x160(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x46c02
movq %r12, %rdi
movq %r13, %rsi
callq 0x4609c
movsd 0x28(%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x46c02
movq %r12, %rdi
movq %r13, %rsi
callq 0x4609c
pushq $0x78
popq %rdi
callq 0x115c0
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x3bfd2
movl $0xa0, %edi
callq 0x115c0
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movsd 0x907f6(%rip), %xmm0    # 0xa84b0
callq 0x19b1e
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x98(%r13)
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq %r13, %rsi
callq *0x20(%rax)
jmp 0x17a40
movq %r14, %rdi
callq 0x115b0
leaq 0x18(%rsp), %rdi
callq 0x3ee72
pushq $0x1
popq %rbp
jmp 0x17d0b
leaq 0x90d39(%rip), %rdi     # 0xa8a38
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6e732
movl %ebp, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %rbp, %rdi
jmp 0x17d35
movq %rax, %rbx
movl $0xa0, %esi
movq %r13, %rdi
callq 0x115d0
jmp 0x17d47
jmp 0x17d44
jmp 0x17d44
jmp 0x17d44
jmp 0x17d44
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3ee72
movq %rbx, %rdi
callq 0x11a80
nop