// File: /workspace/github_cpp_makefile_star2_O2/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 $0x298, %rsp            # imm = 0x298
cmpl $0x0, 0x10(%rdi)
je 0x24a4e
movq %rsi, %r15
cmpl $0x0, 0x10(%rsi)
je 0x24a4e
movq %rdi, %r14
movl %edx, %esi
callq 0x242e5
testq %rax, %rax
je 0x24a4e
movq %rax, %rbx
cmpl $0x0, 0x24c(%rax)
je 0x24a39
movq %r14, (%rsp)
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, 0x8(%rsp)
movq %rbx, %rsi
callq 0x6c1d2
xorps %xmm0, %xmm0
movq %r12, %rdi
callq 0x6eeec
movl 0x10(%r15), %ecx
movl %ecx, %eax
cltd
leaq 0x48(%rsp), %rsi
idivl 0x24c(%rsi)
incl %eax
movslq %eax, %rbx
movq %rbx, %rbp
shlq $0x4, %rbp
xorl %r14d, %r14d
leaq 0x10(%rsp), %r13
xorl %r12d, %r12d
movslq %ecx, %rax
cmpq %rax, %r12
jge 0x249c4
movq 0x8(%r15), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0x16310
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
movsd 0xa3797(%rip), %xmm0    # 0xc8148
xorl %edx, %edx
callq 0x285cc
addq %rbx, %r12
movl 0x10(%r15), %ecx
addq %rbp, %r14
jmp 0x2498a
leaq 0x48(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x24a90
leaq 0x10024b(%rip), %rax    # 0x124c28
movsd (%rax), %xmm0
leaq 0x10(%rsp), %rdi
pushq $0x4
popq %rdx
pushq $0x1
popq %r8
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2d9f6
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x20c50
movq %rax, %r14
movq %rbx, %rdi
callq 0x6c22a
movl $0x250, %esi            # imm = 0x250
movq %rbx, %rdi
callq 0x13500
leaq 0x10(%rsp), %rdi
callq 0x2ec74
leaq 0x48(%rsp), %rdi
callq 0x6c22a
jmp 0x24a51
movq %rbx, %rdi
callq 0x6c22a
movl $0x250, %esi            # imm = 0x250
movq %rbx, %rdi
callq 0x13500
xorl %r14d, %r14d
movq %r14, %rax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2ec74
jmp 0x24a7e
jmp 0x24a7b
jmp 0x24a7b
jmp 0x24a7b
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x6c22a
movq %rbx, %rdi
callq 0x138f0