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

  // Write clusters to file
  for (int i = 0; i < clusters.NEntries(); i++) {
    R3SegmentationCluster *cluster = clusters.Kth(i);
    R3Point center;
    RNScalar variances[3];
    R3Triad axes = cluster->PrincipleAxes(&center, variances);
    R3Box extent = cluster->AxisExtents();
    fprintf(fp, "%d %d %g %g %g %d  %g %g %g   %g %g %g %g   %g %g %g  %g  %g %g %g   %g %g %g  %g %g %g  %g %g %g   %g %g %g   %g %g %g  %g %g %g\n",
            i+1, cluster->points.NEntries(), cluster->area,
            cluster->total_affinity, cluster->possible_affinity, cluster->primitive.primitive_type,
            cluster->primitive.centroid.X(), cluster->primitive.centroid.Y(), cluster->primitive.centroid.Z(),
            cluster->primitive.plane.A(), cluster->primitive.plane.B(), cluster->primitive.plane.C(), cluster->primitive.plane.D(),
            cluster->color.R(), cluster->color.G(), cluster->color.B(),
            cluster->timestamp,
            center.X(), center.Y(), center.Z(),
            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]);
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xca9b0(%rip), %rsi     # 0xf6634
movq %r15, %rdi
callq 0x15760
testq %rax, %rax
je 0x2becb
movq %rax, %r14
xorl %r15d, %r15d
leaq 0x130(%rsp), %r12
leaq 0x190(%rsp), %r13
movslq 0x24(%rbx), %rax
cmpq %rax, %r15
jge 0x2bebe
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %rbp
movq %r12, %rdi
callq 0x9038e
leaq 0x148(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
leaq 0x110(%rsp), %rcx
callq 0x28b02
movq %r13, %rdi
movq %rbp, %rsi
callq 0x28cac
incq %r15
movsd 0xe8(%rbp), %xmm0
movsd %xmm0, 0x108(%rsp)
movsd 0x128(%rbp), %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x120(%rbp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movl 0x14(%rbp), %ecx
movl 0x40(%rbp), %r8d
movsd 0x80(%rbp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0x88(%rbp), %xmm0
movsd %xmm0, 0xe8(%rsp)
movsd 0x90(%rbp), %xmm0
movsd %xmm0, 0xe0(%rsp)
movsd 0xc8(%rbp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0xd0(%rbp), %xmm7
movups 0xd8(%rbp), %xmm8
movups 0xf0(%rbp), %xmm9
movups 0x100(%rbp), %xmm10
movups 0x130(%rsp), %xmm11
movsd 0x140(%rsp), %xmm12
movups 0x148(%rsp), %xmm13
movups 0x158(%rsp), %xmm14
movups 0x168(%rsp), %xmm15
movups 0x178(%rsp), %xmm6
movsd 0x188(%rsp), %xmm5
movaps 0x110(%rsp), %xmm4
movsd 0x120(%rsp), %xmm3
movups 0x198(%rsp), %xmm2
movups 0x1a8(%rsp), %xmm1
movups 0x1b8(%rsp), %xmm0
movups %xmm0, 0xc8(%rsp)
movups %xmm1, 0xb8(%rsp)
movups %xmm2, 0xa8(%rsp)
movsd %xmm3, 0xa0(%rsp)
movups %xmm4, 0x90(%rsp)
movsd %xmm5, 0x88(%rsp)
movups %xmm6, 0x78(%rsp)
movups %xmm15, 0x68(%rsp)
movups %xmm14, 0x58(%rsp)
movups %xmm13, 0x48(%rsp)
movsd %xmm12, 0x40(%rsp)
movups %xmm11, 0x30(%rsp)
movups %xmm10, 0x20(%rsp)
movups %xmm9, 0x10(%rsp)
movups %xmm8, (%rsp)
movq %r14, %rdi
leaq 0xc3530(%rip), %rsi     # 0xef398
movl %r15d, %edx
movsd 0x108(%rsp), %xmm0
movsd 0x100(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm2
movsd 0xf0(%rsp), %xmm3
movsd 0xe8(%rsp), %xmm4
movsd 0xe0(%rsp), %xmm5
movsd 0xd8(%rsp), %xmm6
movb $0x8, %al
callq 0x15910
movq %r13, %rdi
callq 0x7cbba
jmp 0x2bcab
movq %r14, %rdi
callq 0x15610
pushq $0x1
popq %rbx
jmp 0x2bede
leaq 0xc2b7f(%rip), %rdi     # 0xeea51
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xb4552
movl %ebx, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq