// File: /workspace/github_cpp_makefile_star2_O2/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 0x305e7
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x18(%rdi), %r15
movq %rsi, %rdi
movsd %xmm0, (%rsp)
callq 0x2a720
movq %r15, %rdi
movq %rax, %rsi
callq 0x646fe
leaq 0x50(%r14), %r15
movq %rbx, %rdi
callq 0x2a8a8
movq %r15, %rdi
movq %rax, %rsi
callq 0x177ca
movl 0x8(%rbx), %ebp
xorpd %xmm0, %xmm0
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3051c
movq %rbx, %rdi
callq 0x2aa12
movsd (%rsp), %xmm2
ucomisd %xmm2, %xmm0
jbe 0x3051c
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 0x30542
movq %rbx, %rsi
callq 0x20a64
movl 0x8(%rbx), %ecx
cmpl %ecx, %ebp
jge 0x3058d
movl %ecx, %eax
cltd
idivl %ebp
incl %eax
movslq %eax, %r15
imulq $0x30, %r15, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq %ecx, %rax
cmpq %rax, %rbp
jge 0x305c5
movq (%rbx), %rdx
addq %r13, %rdx
movslq 0x10(%r14), %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x2f200
incl 0x10(%r14)
addq %r15, %rbp
movl 0x8(%rbx), %ecx
addq %r12, %r13
jmp 0x3055c
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq %ecx, %rax
cmpq %rax, %r12
jge 0x305c5
movq (%rbx), %rdx
addq %r15, %rdx
movslq 0x10(%r14), %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x2f200
incl 0x10(%r14)
incq %r12
movl 0x8(%rbx), %ecx
addq $0x30, %r15
jmp 0x30593
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x305e7
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20aa0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq