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

  // Write header
  fprintf(fp, "@relation UGOR\n");

  // Write features
  for (int i = 0; i < NFeatures(); i++) {
    R3SurfelFeature *feature = Feature(i);
    fprintf(fp, "@attribute %s real\n", feature->Name());
  }

  // Write labels
  fprintf(fp, "@attribute Label { ");
  for (int i = 0; i < NLabels(); i++) {
    R3SurfelLabel *label = Label(i);
    if (i != 0) fprintf(fp, ", ");
    fprintf(fp, "%s ", label->Name());
  }
  fprintf(fp, "}\n");

  // Write data
  fprintf(fp, "@data\n");
  for (int i = 1; i < NObjects(); i++) {
    R3SurfelObject *object = Object(i);
    R3SurfelLabel *label = object->GroundTruthLabel();
    if (!label) label = object->HumanLabel();
    const R3SurfelFeatureVector& vector = object->FeatureVector();
    const char *name = (object->Name()) ? object->Name() : "None";
    const R3Point& centroid = object->Centroid();
    fprintf(fp, "%% %s %g %g %g\n", name, centroid.X(), centroid.Y(), centroid.Z());
    for (int j = 0; j < vector.NValues(); j++) 
      fprintf(fp, "%12.6f ", vector.Value(j));
    fprintf(fp, "%s\n", (label) ? label->Name() : "Unknown");;
  }

  // Close file
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbp
leaq 0xc2d3f(%rip), %rsi     # 0xe42e4
movq %r15, %rdi
callq 0x135d0
testq %rax, %rax
je 0x217bf
movq %rax, %r14
leaq 0xbc371(%rip), %rdi     # 0xdd931
movl $0xf, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x139a0
cmpl $0x0, 0xac(%rbp)
jle 0x2160f
leaq 0xbc35f(%rip), %r15     # 0xdd941
xorl %ebx, %ebx
movq 0xa0(%rbp), %rax
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x13740
incq %rbx
movslq 0xac(%rbp), %rax
cmpq %rax, %rbx
jl 0x215e4
leaq 0xbc33f(%rip), %rdi     # 0xdd955
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x139a0
cmpl $0x0, 0x2c(%rbp)
jle 0x2167d
leaq 0xbc337(%rip), %r15     # 0xdd96c
leaq 0xbc32d(%rip), %r12     # 0xdd969
xorl %ebx, %ebx
movq 0x20(%rbp), %rax
movq (%rax,%rbx,8), %r13
testq %rbx, %rbx
je 0x21660
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x139a0
movq 0x60(%r13), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x13740
incq %rbx
movslq 0x2c(%rbp), %rax
cmpq %rax, %rbx
jl 0x2163e
leaq 0xbc2ec(%rip), %rdi     # 0xdd970
movl $0x1, %r15d
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x139a0
leaq 0xbc2d0(%rip), %rdi     # 0xdd973
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x139a0
cmpl $0x2, 0x1c(%rbp)
jl 0x217b0
leaq 0xbc2c4(%rip), %r13     # 0xdd98a
movq %rbp, (%rsp)
movq 0x10(%rbp), %rax
movq (%rax,%r15,8), %rbp
movq %rbp, %rdi
callq 0x17788
testq %rax, %rax
jne 0x216e7
movq %rbp, %rdi
callq 0x177d6
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
callq 0x17342
movq %rax, %r12
movq 0x88(%rbp), %rbx
testq %rbx, %rbx
leaq 0xbbe24(%rip), %rax     # 0xdd52c
cmoveq %rax, %rbx
movq %rbp, %rdi
callq 0x17078
movq (%rax), %rcx
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq *0x68(%rcx)
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movq %r14, %rdi
leaq 0xbc23c(%rip), %rsi     # 0xdd97a
movq %rbx, %rdx
movb $0x3, %al
callq 0x13740
cmpl $0x0, 0x10(%r12)
jle 0x21776
xorl %ebx, %ebx
movq 0x8(%r12), %rax
movsd (%rax,%rbx,8), %xmm0
movq %r14, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x13740
incq %rbx
movslq 0x10(%r12), %rax
cmpq %rax, %rbx
jl 0x21752
leaq 0xbc215(%rip), %rdx     # 0xdd992
movq 0x8(%rsp), %rax
testq %rax, %rax
movq (%rsp), %rbp
je 0x2178f
movq 0x60(%rax), %rdx
movq %r14, %rdi
leaq 0xc457c(%rip), %rsi     # 0xe5d15
xorl %eax, %eax
callq 0x13740
incq %r15
movslq 0x1c(%rbp), %rax
cmpq %rax, %r15
jl 0x216ca
movq %r14, %rdi
callq 0x134d0
movl $0x1, %ebx
jmp 0x217d2
leaq 0xbbd0c(%rip), %rdi     # 0xdd4d2
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xac81a
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop