// File: /workspace/github_cpp_makefile_star2_O1/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 0xc3b63(%rip), %rsi     # 0xe52f8
movq %r15, %rdi
callq 0x135d0
testq %rax, %rax
je 0x219af
movq %rax, %r14
leaq 0xbd181(%rip), %rdi     # 0xde931
movl $0xf, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x139a0
cmpl $0x0, 0xac(%rbp)
jle 0x217ff
leaq 0xbd16f(%rip), %r15     # 0xde941
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 0x217d4
leaq 0xbd14f(%rip), %rdi     # 0xde955
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x139a0
cmpl $0x0, 0x2c(%rbp)
jle 0x2186d
leaq 0xbd147(%rip), %r15     # 0xde96c
leaq 0xbd13d(%rip), %r12     # 0xde969
xorl %ebx, %ebx
movq 0x20(%rbp), %rax
movq (%rax,%rbx,8), %r13
testq %rbx, %rbx
je 0x21850
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 0x2182e
leaq 0xbd0fc(%rip), %rdi     # 0xde970
movl $0x1, %r15d
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x139a0
leaq 0xbd0e0(%rip), %rdi     # 0xde973
movl $0x6, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x139a0
cmpl $0x2, 0x1c(%rbp)
jl 0x219a0
leaq 0xbd0d4(%rip), %r13     # 0xde98a
movq %rbp, (%rsp)
movq 0x10(%rbp), %rax
movq (%rax,%r15,8), %rbp
movq %rbp, %rdi
callq 0x17824
testq %rax, %rax
jne 0x218d7
movq %rbp, %rdi
callq 0x17876
movq %rax, 0x8(%rsp)
movq %rbp, %rdi
callq 0x17376
movq %rax, %r12
movq 0x88(%rbp), %rbx
testq %rbx, %rbx
leaq 0xbcc34(%rip), %rax     # 0xde52c
cmoveq %rax, %rbx
movq %rbp, %rdi
callq 0x170be
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 0xbd04c(%rip), %rsi     # 0xde97a
movq %rbx, %rdx
movb $0x3, %al
callq 0x13740
cmpl $0x0, 0x10(%r12)
jle 0x21966
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 0x21942
leaq 0xbd025(%rip), %rdx     # 0xde992
movq 0x8(%rsp), %rax
testq %rax, %rax
movq (%rsp), %rbp
je 0x2197f
movq 0x60(%rax), %rdx
movq %r14, %rdi
leaq 0xc53ac(%rip), %rsi     # 0xe6d35
xorl %eax, %eax
callq 0x13740
incq %r15
movslq 0x1c(%rbp), %rax
cmpq %rax, %r15
jl 0x218ba
movq %r14, %rdi
callq 0x134d0
movl $0x1, %ebx
jmp 0x219c2
leaq 0xbcb1c(%rip), %rdi     # 0xde4d2
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0xaddb2
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop