// File: tomfunkhouser[P]gaps/apps/sflprocess/sflprocess.cpp
// Function: CreateClusterObjects(gaps::R3SurfelScene*, char const*, char const*, char const*, int, double, double, double, int, double)
static int
CreateClusterObjects(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,
  int min_points_per_object, RNLength chunk_size)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();
  if (print_verbose) {
    printf("Creating cluster 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 cluster objects 
  RNArray<R3SurfelObject *> *objects = CreateClusterObjects(scene, 
    source_node, NULL, parent_object, parent_node,                                                   
    max_neighbors, max_neighbor_distance, 
    max_offplane_distance, max_normal_angle, 
    min_points_per_object, chunk_size);
  if (!objects) {
    RNFail("No cluster 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 $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movl %r8d, 0x6c(%rsp)
movsd %xmm0, 0x60(%rsp)
movsd %xmm1, 0x58(%rsp)
movsd %xmm2, 0x50(%rsp)
movl %r9d, 0x4c(%rsp)
movsd %xmm3, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x16dd30
leaq 0x30(%rsp), %rdi
callq 0x263f0
cmpl $0x0, 0x23fe62(%rip)    # 0x2647c0
je 0x2497d
leaq 0x1d4454(%rip), %rdi    # 0x1f8dbb
movb $0x0, %al
callq 0x16090
movq 0x23661b(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x70d50
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x249c5
movq 0x80(%rsp), %rsi
leaq 0x1d442b(%rip), %rdi    # 0x1f8dd9
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x24b41
movq 0x88(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x60280
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x24a0f
movq 0x78(%rsp), %rsi
leaq 0x1d41a1(%rip), %rdi    # 0x1f8b99
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x24b41
movq 0x88(%rsp), %rdi
callq 0x26780
movq %rax, %rdi
movq 0x70(%rsp), %rsi
callq 0x60280
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x24a59
movq 0x70(%rsp), %rsi
leaq 0x1d4157(%rip), %rdi    # 0x1f8b99
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x24b41
movq 0x88(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %r8
movl 0x6c(%rsp), %r9d
movsd 0x60(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
movl 0x4c(%rsp), %eax
movsd 0x40(%rsp), %xmm3
xorl %edx, %edx
movl %eax, (%rsp)
callq 0x94fe0
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x24ac3
leaq 0x1d434e(%rip), %rdi    # 0x1f8dfd
movb $0x0, %al
callq 0x172cb0
movl $0x0, 0x94(%rsp)
jmp 0x24b41
cmpl $0x0, 0x23fcf6(%rip)    # 0x2647c0
je 0x24b0d
leaq 0x30(%rsp), %rdi
callq 0x16ddf0
leaq 0x1d3aa2(%rip), %rdi    # 0x1f857f
movb $0x1, %al
callq 0x16090
movq 0x10(%rsp), %rdi
callq 0x26490
movl %eax, %esi
leaq 0x1d3b59(%rip), %rdi    # 0x1f8650
movb $0x0, %al
callq 0x16090
movq 0x23648b(%rip), %rax    # 0x25af90
movq (%rax), %rdi
callq 0x168c0
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x24b36
movq 0x8(%rsp), %rdi
callq 0x2b190
movq 0x8(%rsp), %rdi
movl $0x10, %esi
callq 0x16750
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq