// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
leaq 0xaf17d(%rip), %rsi     # 0xcf284
movq %r15, %rdi
callq 0x135f0
testq %rax, %rax
je 0x202f8
movq %rax, %r14
leaq 0xa880f(%rip), %rdi     # 0xc8931
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x139e0
leaq 0xa880a(%rip), %r15     # 0xc8941
xorl %ebx, %ebx
movslq 0xac(%r12), %rax
cmpq %rax, %rbx
jge 0x20168
movq 0xa0(%r12), %rax
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x13780
incq %rbx
jmp 0x20139
movq %r12, (%rsp)
leaq 0xa87e2(%rip), %rdi     # 0xc8955
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x139e0
leaq 0xa87e4(%rip), %r12     # 0xc896c
leaq 0xa87da(%rip), %r13     # 0xc8969
pushq $0x2
popq %rbp
xorl %ebx, %ebx
movq (%rsp), %r15
movslq 0x2c(%r15), %rax
cmpq %rax, %rbx
jge 0x201d5
movq 0x20(%r15), %rax
movq (%rax,%rbx,8), %r15
testq %rbx, %rbx
je 0x201bf
movq %r13, %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x139e0
movq 0x60(%r15), %rdx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x13780
incq %rbx
jmp 0x20194
leaq 0xa8794(%rip), %rdi     # 0xc8970
pushq $0x2
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
movq %r14, %rcx
callq 0x139e0
leaq 0xa877f(%rip), %rdi     # 0xc8973
pushq $0x6
popq %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x139e0
leaq 0xa8781(%rip), %rbp     # 0xc898a
movslq 0x1c(%r15), %rax
cmpq %rax, %rbx
jge 0x202eb
movq 0x10(%r15), %rax
movq %rbx, 0x8(%rsp)
movq (%rax,%rbx,8), %r15
movq %r15, %rdi
callq 0x16d5a
movq %rax, %r13
testq %rax, %rax
jne 0x2023e
movq %r15, %rdi
callq 0x16d70
movq %rax, %r13
movq %r15, %rdi
callq 0x16a48
movq %rax, %r12
movq 0x88(%r15), %rbx
testq %rbx, %rbx
leaq 0xa82d2(%rip), %rax     # 0xc852c
cmoveq %rax, %rbx
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x16342
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movq %r14, %rdi
leaq 0xa86f3(%rip), %rsi     # 0xc897a
movq %rbx, %rdx
movb $0x3, %al
callq 0x13780
xorl %ebx, %ebx
movslq 0x10(%r12), %rax
cmpq %rax, %rbx
jge 0x202b9
movq 0x8(%r12), %rax
movsd (%rax,%rbx,8), %xmm0
movq %r14, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x13780
incq %rbx
jmp 0x20293
leaq 0xa86d2(%rip), %rdx     # 0xc8992
testq %r13, %r13
je 0x202c9
movq 0x60(%r13), %rdx
movq %r14, %rdi
leaq 0xb09c2(%rip), %rsi     # 0xd0c95
xorl %eax, %eax
callq 0x13780
movq 0x8(%rsp), %rbx
incq %rbx
movq (%rsp), %r15
jmp 0x20209
movq %r14, %rdi
callq 0x134e0
pushq $0x1
popq %rbx
jmp 0x2030b
leaq 0xa81d3(%rip), %rdi     # 0xc84d2
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0x9ce26
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq