// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointSet.cpp
// Function: gaps::R3SurfelPointSet::InsertPoints(gaps::R3SurfelBlock*, double)
void R3SurfelPointSet::
InsertPoints(R3SurfelBlock *block, RNScalar max_resolution)
{
  // Check block
  if (block->NSurfels() == 0) return;

  // Update bounding box
  bbox.Union(block->BBox());

  // Update timestamp range
  timestamp_range.Union(block->TimestampRange());

  // Compute number of surfels to insert
  int block_nsurfels = block->NSurfels();
  if (max_resolution > 0) {
    RNScalar block_resolution = block->Resolution();
    if (block_resolution > max_resolution) {
      RNScalar sampling_factor = max_resolution / block_resolution;
      block_nsurfels = block->NSurfels() * sampling_factor;
      if (block_nsurfels == 0) block_nsurfels = 1;
    }
  }
  
  // Allocate space for points
  AllocatePoints(npoints + block_nsurfels);

  // Read block
  if (block->database) block->database->ReadBlock(block);

  // Copy surfels
  if (block_nsurfels < block->NSurfels()) {
    // Subsample surfels
    int step = block->NSurfels() / block_nsurfels + 1;
    for (int i = 0; i < block->NSurfels(); i+= step) {
      const R3Surfel *surfel = block->Surfel(i);
      points[npoints].Reset(block, surfel);
      npoints++;
    }
  }
  else {
    // Copy all surfels
    for (int i = 0; i < block->NSurfels(); i++) {
      const R3Surfel *surfel = block->Surfel((int) i);
      points[npoints].Reset(block, surfel);
      npoints++;
    }
  }

  // Release block
  if (block->database) block->database->ReleaseBlock(block);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x0, 0x8(%rsi)
je 0x33b31
movq %rsi, %rbx
movq %rdi, %r14
movsd %xmm0, (%rsp)
leaq 0x18(%rdi), %r15
movq %rsi, %rdi
callq 0x2cb9e
movq %r15, %rdi
movq %rax, %rsi
callq 0x6de0c
movq %rbx, %rdi
callq 0x2ce62
movsd (%rax), %xmm0
movsd 0x50(%r14), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x339a7
movsd %xmm0, 0x50(%r14)
movsd 0x8(%rax), %xmm0
ucomisd 0x58(%r14), %xmm0
movsd (%rsp), %xmm1
jbe 0x339bf
movsd %xmm0, 0x58(%r14)
movl 0x8(%rbx), %ebp
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jbe 0x339f9
movq %rbx, %rdi
callq 0x2d0ea
movsd (%rsp), %xmm2
ucomisd %xmm2, %xmm0
jbe 0x339f9
xorps %xmm1, %xmm1
cvtsi2sdl 0x8(%rbx), %xmm1
divsd %xmm0, %xmm2
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ebp
cmpl $0x1, %ebp
adcl $0x0, %ebp
movl 0x10(%r14), %esi
addl %ebp, %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x80(%rax)
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x33a46
movl 0xb4(%rbx), %eax
testl %eax, %eax
jne 0x33a3e
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
movl 0x28(%rdi), %ecx
movq %rbx, %rsi
callq *0x88(%rax)
testl %eax, %eax
je 0x33a46
movl 0xb4(%rbx), %eax
incl %eax
movl %eax, 0xb4(%rbx)
movl 0x8(%rbx), %eax
cmpl %eax, %ebp
jge 0x33aa5
testl %eax, %eax
jle 0x33ae6
cltd
idivl %ebp
incl %eax
movslq %eax, %r15
movl 0x10(%r14), %eax
movq %r15, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movq (%rbx), %rdx
addq %r13, %rdx
movslq %eax, %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x3221e
movl 0x10(%r14), %eax
incl %eax
movl %eax, 0x10(%r14)
addq %r15, %rbp
movslq 0x8(%rbx), %rcx
addq %r12, %r13
cmpq %rcx, %rbp
jl 0x33a71
jmp 0x33ae6
testl %eax, %eax
jle 0x33ae6
movl 0x10(%r14), %eax
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rbx), %rdx
addq %r15, %rdx
movslq %eax, %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x3221e
movl 0x10(%r14), %eax
incl %eax
movl %eax, 0x10(%r14)
incq %r12
movslq 0x8(%rbx), %rcx
addq $0x30, %r15
cmpq %rcx, %r12
jl 0x33ab3
movq 0x98(%rbx), %r14
testq %r14, %r14
je 0x33b31
movl 0xb4(%rbx), %eax
cmpl $0x1, %eax
jne 0x33b1e
movq (%r14), %rax
movq 0x8(%r14), %rdx
movl 0x28(%r14), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq *0x90(%rax)
testl %eax, %eax
je 0x33b31
movl 0xb4(%rbx), %eax
decl %eax
movl %eax, 0xb4(%rbx)
jne 0x33b31
testb $0x2, 0x89(%rbx)
jne 0x33b40
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbx, %rdi
callq 0x2ca06
movl $0xc8, %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x134f0
nop