// File: /workspace/github_cpp_makefile_star2_O1/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 0x33e30
movq %rsi, %rbx
movq %rdi, %r14
movsd %xmm0, (%rsp)
leaq 0x18(%rdi), %r15
movq %rsi, %rdi
callq 0x2cfc6
movq %r15, %rdi
movq %rax, %rsi
callq 0x6ea70
movq %rbx, %rdi
callq 0x2d262
movsd (%rax), %xmm0
movsd 0x50(%r14), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x33ccf
movsd %xmm0, 0x50(%r14)
movsd 0x8(%rax), %xmm0
ucomisd 0x58(%r14), %xmm0
movsd (%rsp), %xmm1
jbe 0x33ce7
movsd %xmm0, 0x58(%r14)
movl 0x8(%rbx), %ebp
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jbe 0x33d21
movq %rbx, %rdi
callq 0x2d4ca
movsd (%rsp), %xmm2
ucomisd %xmm2, %xmm0
jbe 0x33d21
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 0x33d65
cmpl $0x0, 0xb4(%rbx)
jne 0x33d5f
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
movl 0x28(%rdi), %ecx
movq %rbx, %rsi
callq *0x88(%rax)
testl %eax, %eax
je 0x33d65
incl 0xb4(%rbx)
movl 0x8(%rbx), %eax
cmpl %eax, %ebp
jge 0x33db7
testl %eax, %eax
jle 0x33def
cltd
idivl %ebp
incl %eax
movslq %eax, %r15
movq %r15, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movq (%rbx), %rdx
addq %r13, %rdx
movslq 0x10(%r14), %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x325ce
incl 0x10(%r14)
addq %r15, %rbp
movslq 0x8(%rbx), %rax
addq %r12, %r13
cmpq %rax, %rbp
jl 0x33d88
jmp 0x33def
testl %eax, %eax
jle 0x33def
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rbx), %rdx
addq %r15, %rdx
movslq 0x10(%r14), %rdi
shlq $0x4, %rdi
addq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x325ce
incl 0x10(%r14)
incq %r12
movslq 0x8(%rbx), %rax
addq $0x30, %r15
cmpq %rax, %r12
jl 0x33dc1
movq 0x98(%rbx), %r14
testq %r14, %r14
je 0x33e30
cmpl $0x1, 0xb4(%rbx)
jne 0x33e1f
movq (%r14), %rax
movq 0x8(%r14), %rdx
movl 0x28(%r14), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq *0x90(%rax)
testl %eax, %eax
je 0x33e30
decl 0xb4(%rbx)
jne 0x33e30
testb $0x2, 0x89(%rbx)
jne 0x33e3f
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 0x2ce2e
movl $0xc8, %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x134f0