// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: CreatePlanarObjects(gaps::R3SurfelScene*, char const*, char const*, char const*, int, double, double, double, double, double, int, double, double, double)
static int
CreatePlanarObjects(R3SurfelScene *scene, 
  const char *parent_object_name, const char *parent_node_name, const char *source_node_name, 
  int max_neighbors, RNLength max_neighbor_distance, 
  RNLength max_offplane_distance, RNAngle max_normal_angle,
  RNArea min_area, RNScalar min_density, int min_points,
  RNLength grid_spacing, RNScalar accuracy_factor, RNLength chunk_size)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();
  if (print_verbose) {
    printf("Creating planar objects ...\n");
    fflush(stdout);
  }

  // Find parent object
  R3SurfelObject *parent_object = scene->FindObjectByName(parent_object_name);
  if (!parent_object) {
    RNFail("Unable to find object with name %s\n", parent_object_name);
    return 0;
  }

  // Find parent node
  R3SurfelNode *parent_node = scene->Tree()->FindNodeByName(parent_node_name);
  if (!parent_node) {
    RNFail("Unable to find node with name %s\n", parent_node_name);
    return 0;
  }

  // Find source node
  R3SurfelNode *source_node = scene->Tree()->FindNodeByName(source_node_name);
  if (!source_node) {
    RNFail("Unable to find node with name %s\n", source_node_name);
    return 0;
  }

  // Create planar objects 
  RNArray<R3SurfelObject *> *objects = CreatePlanarObjects(scene, 
    source_node, NULL, parent_object, parent_node,
    max_neighbors, max_neighbor_distance, 
    max_offplane_distance, max_normal_angle,
    min_area, min_density, min_points, 
    grid_spacing, accuracy_factor, chunk_size);
  if (!objects) {
    RNFail("No planar objects created\n");
    return 0;
  }

  // Print statistics
  if (print_verbose) {
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Objects = %d\n", objects->NEntries());
    fflush(stdout);
  }

  // Delete array of objects
  delete objects;

  // Return success
  return 1;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movl %r8d, 0x8c(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x78(%rsp)
movsd %xmm2, 0x70(%rsp)
movsd %xmm3, 0x68(%rsp)
movsd %xmm4, 0x60(%rsp)
movl %r9d, 0x5c(%rsp)
movsd %xmm5, 0x50(%rsp)
movsd %xmm6, 0x48(%rsp)
movsd %xmm7, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x16dd30
leaq 0x30(%rsp), %rdi
callq 0x263f0
cmpl $0x0, 0x23fbee(%rip)    # 0x2647c0
je 0x24bf1
leaq 0x1d423e(%rip), %rdi    # 0x1f8e19
movb $0x0, %al
callq 0x16090
movq 0x2363a7(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x70d50
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x24c39
movq 0xa0(%rsp), %rsi
leaq 0x1d41b7(%rip), %rdi    # 0x1f8dd9
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0xb4(%rsp)
jmp 0x24ddf
movq 0xa8(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
movq 0x98(%rsp), %rsi
callq 0x60280
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x24c89
movq 0x98(%rsp), %rsi
leaq 0x1d3f27(%rip), %rdi    # 0x1f8b99
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0xb4(%rsp)
jmp 0x24ddf
movq 0xa8(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
movq 0x90(%rsp), %rsi
callq 0x60280
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x24cd9
movq 0x90(%rsp), %rsi
leaq 0x1d3ed7(%rip), %rdi    # 0x1f8b99
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0xb4(%rsp)
jmp 0x24ddf
movq 0xa8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %r8
movl 0x8c(%rsp), %r9d
movsd 0x80(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
movsd 0x70(%rsp), %xmm2
movsd 0x68(%rsp), %xmm3
movsd 0x60(%rsp), %xmm4
movl 0x5c(%rsp), %eax
movsd 0x50(%rsp), %xmm5
movsd 0x48(%rsp), %xmm6
movsd 0x40(%rsp), %xmm7
xorl %edx, %edx
movl %eax, (%rsp)
callq 0x92a50
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x24d61
leaq 0x1d40e9(%rip), %rdi    # 0x1f8e36
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0xb4(%rsp)
jmp 0x24ddf
cmpl $0x0, 0x23fa58(%rip)    # 0x2647c0
je 0x24dab
leaq 0x30(%rsp), %rdi
callq 0x16ddf0
leaq 0x1d3804(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
movq 0x10(%rsp), %rdi
callq 0x26490
movl %eax, %esi
leaq 0x1d38bb(%rip), %rdi    # 0x1f8650
movb $0x0, %al
callq 0x16090
movq 0x2361ed(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x24dd4
movq 0x8(%rsp), %rdi
callq 0x2b190
movq 0x8(%rsp), %rdi
movl $0x10, %esi
callq 0x16750
movl $0x1, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
nop