// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelUtils.cpp
// Function: gaps::CreateConnectedPointSet(gaps::R3SurfelPointSet*, gaps::R3SurfelPointSet*, double, int)
R3SurfelPointSet *
CreateConnectedPointSet(R3SurfelPointSet *pointset, R3SurfelPointSet *seedset,
  RNLength grid_spacing, int max_grid_resolution)
{
  // Just checking
  if (pointset->NPoints() == 0) return NULL;
  if (seedset->NPoints() == 0) return NULL;

  // Create pointset grid
  R3Grid *pointset_grid = CreateGrid(pointset, grid_spacing, max_grid_resolution);
  if (!pointset_grid) return NULL;
  if (pointset_grid->NEntries() == 0) { delete pointset_grid; return NULL; }

  // Create seedset grid
  R3Grid seedset_grid(*pointset_grid); seedset_grid.Clear(0);
  int step = seedset->NPoints() / seedset_grid.NEntries() + 1;
  for (int j = 0; j < seedset->NPoints(); j += step) {
    const R3SurfelPoint *point = seedset->Point(j);
    R3Point position = point->Position();
    seedset_grid.RasterizeWorldPoint(position, 1);
  }

  // Mask to part of grid connected to seeds
  MaskToSeededConnectedComponent(*pointset_grid, seedset_grid, 0.5);

  // Create connnected point set
  R3SurfelGridConstraint constraint(pointset_grid);
  R3SurfelPointSet *connected_pointset = CreatePointSet(pointset, &constraint);

  // Delete grids
  delete pointset_grid;

  // Return connected point set
  return connected_pointset;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
cmpl $0x0, 0x10(%rdi)
je 0x2646a
movq %rsi, %r15
cmpl $0x0, 0x10(%rsi)
je 0x2646a
movq %rdi, %r14
movl %edx, %esi
callq 0x25bef
testq %rax, %rax
je 0x2646a
movq %rax, %rbx
cmpl $0x0, 0x24c(%rax)
je 0x26455
movq %r14, 0x8(%rsp)
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
callq 0x7667a
xorpd %xmm0, %xmm0
movq %r12, %rdi
callq 0x79b14
movl 0x10(%r15), %eax
testl %eax, %eax
jle 0x263d9
cltd
leaq 0x68(%rsp), %r12
idivl 0x24c(%r12)
incl %eax
movslq %eax, %r14
movq %r14, %rbx
shlq $0x4, %rbx
movl $0x8, %r13d
xorl %ebp, %ebp
movq 0x8(%r15), %rax
movq -0x8(%rax,%r13), %rcx
movq (%rax,%r13), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
addsd 0x10(%rcx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rax), %xmm1
addsd 0x18(%rcx), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax), %xmm2
addsd 0x20(%rcx), %xmm2
leaq 0x18(%rsp), %rdi
callq 0x83dc2
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x76f0c
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movq %r12, %rdi
movsd 0xb6d89(%rip), %xmm3    # 0xdd148
xorl %esi, %esi
callq 0x7b91e
addq %r14, %rbp
movslq 0x10(%r15), %rax
addq %rbx, %r13
cmpq %rax, %rbp
jl 0x26346
leaq 0x68(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x264ac
leaq 0x10d816(%rip), %rax    # 0x133c08
movsd (%rax), %xmm0
leaq 0x30(%rsp), %rdi
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %rbx, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x3074a
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x21f14
movq %rax, %r14
movq %rbx, %rdi
callq 0x766d6
movl $0x250, %esi            # imm = 0x250
movq %rbx, %rdi
callq 0x134f0
leaq 0x30(%rsp), %rdi
callq 0x31dba
leaq 0x68(%rsp), %rdi
callq 0x766d6
jmp 0x2646d
movq %rbx, %rdi
callq 0x766d6
movl $0x250, %esi            # imm = 0x250
movq %rbx, %rdi
callq 0x134f0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x31dba
jmp 0x2649a
jmp 0x26497
jmp 0x26497
jmp 0x26497
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x766d6
movq %rbx, %rdi
callq 0x138b0