// File: /workspace/github_cpp_makefile_star2_O1/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 0x26797
movq %rsi, %r15
cmpl $0x0, 0x10(%rsi)
je 0x26797
movq %rdi, %r14
movl %edx, %esi
callq 0x25edc
testq %rax, %rax
je 0x26797
movq %rax, %rbx
cmpl $0x0, 0x24c(%rax)
je 0x26782
movq %r14, 0x8(%rsp)
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
callq 0x77420
xorpd %xmm0, %xmm0
movq %r12, %rdi
callq 0x7a79e
movl 0x10(%r15), %eax
testl %eax, %eax
jle 0x26706
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 0x84d7e
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x77cba
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movq %r12, %rdi
movsd 0xb7a64(%rip), %xmm3    # 0xde150
xorl %esi, %esi
callq 0x7c592
addq %r14, %rbp
movslq 0x10(%r15), %rax
addq %rbx, %r13
cmpq %rax, %rbp
jl 0x26673
leaq 0x68(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x267d9
leaq 0x10e4e9(%rip), %rax    # 0x134c08
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 0x30b3e
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x22118
movq %rax, %r14
movq %rbx, %rdi
callq 0x7747c
movl $0x250, %esi            # imm = 0x250
movq %rbx, %rdi
callq 0x134f0
leaq 0x30(%rsp), %rdi
callq 0x321ae
leaq 0x68(%rsp), %rdi
callq 0x7747c
jmp 0x2679a
movq %rbx, %rdi
callq 0x7747c
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 0x321ae
jmp 0x267c7
jmp 0x267c4
jmp 0x267c4
jmp 0x267c4
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x7747c
movq %rbx, %rdi
callq 0x138b0