// File: /workspace/github_cpp_makefile_star2_O1/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 0xc45b4
movq %r14, %rdi
xorl %esi, %esi
callq 0x15a20
cmpl $0x0, 0xdc(%rbx)
je 0x2deff
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xc4616
movl 0xc(%rbx), %esi
leaq 0xde40f(%rip), %rdi     # 0x10c2fd
movb $0x1, %al
callq 0x15080
movq %r14, %rdi
xorl %esi, %esi
callq 0x15a20
cmpl $0x0, 0xd0(%rbx)
je 0x2df1c
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2cf26
movq %rbx, %rdi
callq 0x2d514
jmp 0x2df26
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2d01a
cmpl $0x0, 0x24(%rbx)
je 0x2df70
leaq 0x18(%rbx), %r14
cmpl $0x0, 0xdc(%rbx)
je 0x2dfc3
leaq 0x8(%rsp), %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2df77
movq (%rbx), %rcx
xorl %esi, %esi
xorl %edx, %edx
movq (%rcx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %edx
incq %rsi
cmpq %rsi, %rax
jne 0x2df57
jmp 0x2df79
xorl %ebp, %ebp
jmp 0x2e50d
xorl %edx, %edx
movl 0x24(%rbx), %esi
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2dfa5
movq (%r14), %rcx
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2df8e
jmp 0x2dfa9
xorpd %xmm1, %xmm1
leaq 0xde35f(%rip), %rdi     # 0x10c30f
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a20
cmpl $0x0, 0xb8(%rbx)
jle 0x2e2c1
xorl %r15d, %r15d
leaq 0x8(%rsp), %r12
leaq 0xde348(%rip), %r13     # 0x10c327
movq %rbx, %rdi
callq 0x2d1ba
cmpl $0x0, 0xdc(%rbx)
je 0x2e06a
movq %r12, %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e021
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 0x2e008
jmp 0x2e023
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e04f
movq (%r14), %rsi
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e038
jmp 0x2e053
xorpd %xmm1, %xmm1
movq %r13, %rdi
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a20
cmpl $0x0, 0xd4(%rbx)
jne 0x2e07d
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2d01a
cmpl $0x0, 0xdc(%rbx)
je 0x2e104
movq %r12, %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e0b7
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 0x2e09e
jmp 0x2e0b9
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e0e5
movq (%r14), %rsi
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e0ce
jmp 0x2e0e9
xorpd %xmm1, %xmm1
leaq 0xde254(%rip), %rdi     # 0x10c344
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a20
movq %rbx, %rdi
callq 0x2d514
cmpl $0x0, 0xdc(%rbx)
je 0x2e193
movq %r12, %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e146
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 0x2e12d
jmp 0x2e148
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e174
movq (%r14), %rsi
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e15d
jmp 0x2e178
xorpd %xmm1, %xmm1
leaq 0xde1e2(%rip), %rdi     # 0x10c361
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a20
movq %rbx, %rdi
callq 0x2dd64
cmpl $0x0, 0xdc(%rbx)
je 0x2e222
movq %r12, %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e1d5
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 0x2e1bc
jmp 0x2e1d7
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e203
movq (%r14), %rsi
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e1ec
jmp 0x2e207
xorpd %xmm1, %xmm1
leaq 0xde170(%rip), %rdi     # 0x10c37e
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a20
movq %rbx, %rdi
callq 0x2d370
cmpl $0x0, 0xdc(%rbx)
je 0x2e2b1
movq %r12, %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e264
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 0x2e24b
jmp 0x2e266
xorl %ecx, %ecx
movl 0x24(%rbx), %edx
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e292
movq (%r14), %rsi
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e27b
jmp 0x2e296
xorpd %xmm1, %xmm1
leaq 0xde0fe(%rip), %rdi     # 0x10c39b
movl %r15d, %esi
movb $0x2, %al
callq 0x15080
movq %r12, %rdi
xorl %esi, %esi
callq 0x15a20
incl %r15d
cmpl 0xb8(%rbx), %r15d
jl 0x2dfdf
cmpl $0x0, 0xdc(%rbx)
je 0x2e349
leaq 0x8(%rsp), %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e2fd
movq (%rbx), %rcx
xorl %esi, %esi
xorl %edx, %edx
movq (%rcx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %edx
incq %rsi
cmpq %rsi, %rax
jne 0x2e2e4
jmp 0x2e2ff
xorl %edx, %edx
movl 0x24(%rbx), %esi
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e32b
movq (%r14), %rcx
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e314
jmp 0x2e32f
xorpd %xmm1, %xmm1
leaq 0xde082(%rip), %rdi     # 0x10c3b8
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a20
movq %rbx, %rdi
callq 0x2dd64
cmpl $0x0, 0xdc(%rbx)
je 0x2e3d9
leaq 0x8(%rsp), %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e38d
movq (%rbx), %rcx
xorl %esi, %esi
xorl %edx, %edx
movq (%rcx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %edx
incq %rsi
cmpq %rsi, %rax
jne 0x2e374
jmp 0x2e38f
xorl %edx, %edx
movl 0x24(%rbx), %esi
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e3bb
movq (%r14), %rcx
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e3a4
jmp 0x2e3bf
xorpd %xmm1, %xmm1
leaq 0xde00a(%rip), %rdi     # 0x10c3d0
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a20
movq %rbx, %rdi
callq 0x2d370
cmpl $0x0, 0xdc(%rbx)
je 0x2e469
leaq 0x8(%rsp), %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e41d
movq (%rbx), %rcx
xorl %esi, %esi
xorl %edx, %edx
movq (%rcx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %edx
incq %rsi
cmpq %rsi, %rax
jne 0x2e404
jmp 0x2e41f
xorl %edx, %edx
movl 0x24(%rbx), %esi
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e44b
movq (%r14), %rcx
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e434
jmp 0x2e44f
xorpd %xmm1, %xmm1
leaq 0xddf92(%rip), %rdi     # 0x10c3e8
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a20
leaq -0x112f(%rip), %rsi     # 0x2d341
movq %r14, %rdi
callq 0xc4ec4
movq %rbx, %rdi
callq 0x2dbfa
movl $0x1, %ebp
cmpl $0x0, 0xdc(%rbx)
je 0x2e50d
leaq 0x8(%rsp), %rdi
callq 0xc4616
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x2e4c1
movq (%rbx), %rcx
xorl %esi, %esi
xorl %edx, %edx
movq (%rcx,%rsi,8), %rdi
cmpq $0x1, 0xc0(%rdi)
adcl $0x0, %edx
incq %rsi
cmpq %rsi, %rax
jne 0x2e4a8
jmp 0x2e4c3
xorl %edx, %edx
movl 0x24(%rbx), %esi
movslq 0x24(%rbx), %rax
testq %rax, %rax
jle 0x2e4ef
movq (%r14), %rcx
xorpd %xmm1, %xmm1
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
addsd 0x128(%r8), %xmm1
incq %rdi
cmpq %rdi, %rax
jne 0x2e4d8
jmp 0x2e4f3
xorpd %xmm1, %xmm1
leaq 0xddf06(%rip), %rdi     # 0x10c400
movb $0x2, %al
callq 0x15080
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x15a20
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq