// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Utils/R3Segmentation.cpp
// Function: gaps::R3Segmentation::CreateClusters(int)
int R3Segmentation::
CreateClusters(int primitive_type)
{
  // Print debug message
  RNTime step_time;
  step_time.Read();
  if (print_progress) {
    printf("      SA %.3f %d\n", step_time.Elapsed(), points.NEntries());
    step_time.Read();
  }

  // Create clusters
  if (initialize_hierarchically) {
    if (!CreateSingletonClusters(primitive_type)) return 0;
    if (!MergeClusters()) return 0;
  }
  else {
    if (!CreateRegionGrowingClusters(primitive_type)) return 0;
  }

  // Check clusters
  if (clusters.IsEmpty()) return 0;

  // Print debug message
  if (print_progress) {
    printf("      SB %.3f %d %d %g\n", step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
    step_time.Read();
  }

  // Iteratively update clusters
  for (int i = 0; i < max_refinement_iterations; i++) {
    // Reassign points to clusters
    if (!ReassignClusters()) return 0;

    // Print debug message
    if (print_progress) {
      printf("      SC %d : %.3f %d %d %g\n", i, step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
      step_time.Read();
    }

    // Create clusters
    if (!allow_outlier_points) {
      if (!CreateRegionGrowingClusters(primitive_type)) return 0;
    }

    // Print debug message
    if (print_progress) {
      printf("      SD %d : %.3f %d %d %g\n", i, step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
      step_time.Read();
    }

    // Merge clusters
    if (!MergeClusters()) return 0;

    // Print debug message
    if (print_progress) {
      printf("      SE %d : %.3f %d %d %g\n", i, step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
      step_time.Read();
    }

    // Refine boundaries
    if (!RefineBoundaries()) return 0;

    // Print debug message
    if (print_progress) {
      printf("      SF %d : %.3f %d %d %g\n", i, step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
      step_time.Read();
    }
    
    // Delete clusters
    if (!DeleteClusters()) return 0;

    // Print debug message
    if (print_progress) {
      printf("      SG %d : %.3f %d %d %g\n", i, step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
      step_time.Read();
    }
  }

  // Split clusters
  // if (!SplitClusters()) return 0;

  // Print debug message
  if (print_progress) {
    printf("      SH %.3f %d %d %g\n", step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
    step_time.Read();
  }

  // Refine boundaries
  if (!RefineBoundaries()) return 0;

  // Print debug message
  if (print_progress) {
    printf("      SI %.3f %d %d %g\n", step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
    step_time.Read();
  }

  // Delete clusters
  if (!DeleteClusters()) return 0;

  // Print debug message
  if (print_progress) {
    printf("      SJ %.3f %d %d %g\n", step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
    step_time.Read();
  }

  // Sort clusters
  clusters.Sort(CompareClusters);

  // Merge small clusters
  if (!MergeSmallClusters()) return 0;

  // Print debug message
  if (print_progress) {
    printf("      SK %.3f %d %d %g\n", step_time.Elapsed(), clusters.NEntries(), NUnclusteredPoints(), Affinity());
    step_time.Read();
  }
  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xc2f90
movq %r14, %rdi
xorl %esi, %esi
callq 0x15a10
cmpl $0x0, 0xdc(%rbx)
je 0x2da71
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xc2ff2
movl 0xc(%rbx), %esi
leaq 0xdc89d(%rip), %rdi     # 0x10a2fd
movb $0x1, %al
callq 0x15080
movq %r14, %rdi
xorl %esi, %esi
callq 0x15a10
cmpl $0x0, 0xd0(%rbx)
je 0x2da8e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2caa2
movq %rbx, %rdi
callq 0x2d118
jmp 0x2da98
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2cb90
cmpl $0x0, 0x24(%rbx)
je 0x2dae5
leaq 0x18(%rbx), %r14
cmpl $0x0, 0xdc(%rbx)
je 0x2db2f
leaq 0x8(%rsp), %rdi
callq 0xc2ff2
movl 0x24(%rbx), %esi
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2daec
movq (%rbx), %rcx
xorl %edi, %edi
xorl %edx, %edx
movq (%rcx,%rdi,8), %r8
cmpq $0x1, 0xc0(%r8)
adcl $0x0, %edx
incq %rdi
cmpq %rdi, %rax
jne 0x2dacc
jmp 0x2daee
xorl %ebp, %ebp
jmp 0x2e043
xorl %edx, %edx
testl %esi, %esi
jle 0x2db11
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rcx
cmpq %rcx, %rsi
jne 0x2dafb
jmp 0x2db15
xorpd %xmm1, %xmm1
leaq 0xdc7f3(%rip), %rdi     # 0x10a30f
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a10
cmpl $0x0, 0xb8(%rbx)
jle 0x2de0f
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
leaq 0xdc7dc(%rip), %r13     # 0x10a327
movq %rbx, %rdi
callq 0x2cd72
cmpl $0x0, 0xdc(%rbx)
je 0x2dbd0
movq %r12, %rdi
callq 0xc2ff2
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2db8d
movq (%rbx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq (%rdx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x2db74
jmp 0x2db8f
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
testl %edx, %edx
jle 0x2dbb5
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rsi
cmpq %rsi, %rdx
jne 0x2db9f
jmp 0x2dbb9
xorpd %xmm1, %xmm1
movq %r13, %rdi
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a10
cmpl $0x0, 0xd4(%rbx)
jne 0x2dbe3
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2cb90
cmpl $0x0, 0xdc(%rbx)
je 0x2dc64
movq %r12, %rdi
callq 0xc2ff2
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2dc1d
movq (%rbx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq (%rdx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x2dc04
jmp 0x2dc1f
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
testl %edx, %edx
jle 0x2dc45
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rsi
cmpq %rsi, %rdx
jne 0x2dc2f
jmp 0x2dc49
xorpd %xmm1, %xmm1
leaq 0xdc6f4(%rip), %rdi     # 0x10a344
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a10
movq %rbx, %rdi
callq 0x2d118
cmpl $0x0, 0xdc(%rbx)
je 0x2dced
movq %r12, %rdi
callq 0xc2ff2
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2dca6
movq (%rbx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq (%rdx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x2dc8d
jmp 0x2dca8
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
testl %edx, %edx
jle 0x2dcce
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rsi
cmpq %rsi, %rdx
jne 0x2dcb8
jmp 0x2dcd2
xorpd %xmm1, %xmm1
leaq 0xdc688(%rip), %rdi     # 0x10a361
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a10
movq %rbx, %rdi
callq 0x2d8ea
cmpl $0x0, 0xdc(%rbx)
je 0x2dd76
movq %r12, %rdi
callq 0xc2ff2
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2dd2f
movq (%rbx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq (%rdx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x2dd16
jmp 0x2dd31
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
testl %edx, %edx
jle 0x2dd57
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rsi
cmpq %rsi, %rdx
jne 0x2dd41
jmp 0x2dd5b
xorpd %xmm1, %xmm1
leaq 0xdc61c(%rip), %rdi     # 0x10a37e
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a10
movq %rbx, %rdi
callq 0x2cf68
cmpl $0x0, 0xdc(%rbx)
je 0x2ddff
movq %r12, %rdi
callq 0xc2ff2
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2ddb8
movq (%rbx), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
movq (%rdx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %ecx
incq %rsi
cmpq %rsi, %rax
jne 0x2dd9f
jmp 0x2ddba
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
testl %edx, %edx
jle 0x2dde0
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rsi
cmpq %rsi, %rdx
jne 0x2ddca
jmp 0x2dde4
xorpd %xmm1, %xmm1
leaq 0xdc5b0(%rip), %rdi     # 0x10a39b
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a10
incl %r15d
cmpl 0xb8(%rbx), %r15d
jl 0x2db4b
cmpl $0x0, 0xdc(%rbx)
je 0x2de91
leaq 0x8(%rsp), %rdi
callq 0xc2ff2
movl 0x24(%rbx), %esi
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2de4e
movq (%rbx), %rcx
xorl %edi, %edi
xorl %edx, %edx
movq (%rcx,%rdi,8), %r8
cmpq $0x1, 0xc0(%r8)
adcl $0x0, %edx
incq %rdi
cmpq %rdi, %rax
jne 0x2de35
jmp 0x2de50
xorl %edx, %edx
testl %esi, %esi
jle 0x2de73
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rcx
cmpq %rcx, %rsi
jne 0x2de5d
jmp 0x2de77
xorpd %xmm1, %xmm1
leaq 0xdc53a(%rip), %rdi     # 0x10a3b8
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a10
movq %rbx, %rdi
callq 0x2d8ea
cmpl $0x0, 0xdc(%rbx)
je 0x2df1b
leaq 0x8(%rsp), %rdi
callq 0xc2ff2
movl 0x24(%rbx), %esi
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2ded8
movq (%rbx), %rcx
xorl %edi, %edi
xorl %edx, %edx
movq (%rcx,%rdi,8), %r8
cmpq $0x1, 0xc0(%r8)
adcl $0x0, %edx
incq %rdi
cmpq %rdi, %rax
jne 0x2debf
jmp 0x2deda
xorl %edx, %edx
testl %esi, %esi
jle 0x2defd
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rcx
cmpq %rcx, %rsi
jne 0x2dee7
jmp 0x2df01
xorpd %xmm1, %xmm1
leaq 0xdc4c8(%rip), %rdi     # 0x10a3d0
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a10
movq %rbx, %rdi
callq 0x2cf68
cmpl $0x0, 0xdc(%rbx)
je 0x2dfa5
leaq 0x8(%rsp), %rdi
callq 0xc2ff2
movl 0x24(%rbx), %esi
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2df62
movq (%rbx), %rcx
xorl %edi, %edi
xorl %edx, %edx
movq (%rcx,%rdi,8), %r8
cmpq $0x1, 0xc0(%r8)
adcl $0x0, %edx
incq %rdi
cmpq %rdi, %rax
jne 0x2df49
jmp 0x2df64
xorl %edx, %edx
testl %esi, %esi
jle 0x2df87
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rcx
cmpq %rcx, %rsi
jne 0x2df71
jmp 0x2df8b
xorpd %xmm1, %xmm1
leaq 0xdc456(%rip), %rdi     # 0x10a3e8
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a10
leaq -0x1072(%rip), %rsi     # 0x2cf3a
movq %r14, %rdi
callq 0xc38c2
movq %rbx, %rdi
callq 0x2d784
movl $0x1, %ebp
cmpl $0x0, 0xdc(%rbx)
je 0x2e043
leaq 0x8(%rsp), %rdi
callq 0xc2ff2
movl 0x24(%rbx), %esi
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e000
movq (%rbx), %rcx
xorl %edi, %edi
xorl %edx, %edx
movq (%rcx,%rdi,8), %r8
cmpq $0x1, 0xc0(%r8)
adcl $0x0, %edx
incq %rdi
cmpq %rdi, %rax
jne 0x2dfe7
jmp 0x2e002
xorl %edx, %edx
testl %esi, %esi
jle 0x2e025
movq (%r14), %rax
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
addsd 0x128(%rdi), %xmm1
incq %rcx
cmpq %rcx, %rsi
jne 0x2e00f
jmp 0x2e029
xorpd %xmm1, %xmm1
leaq 0xdc3d0(%rip), %rdi     # 0x10a400
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a10
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq