// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelPointSet.cpp
// Function: gaps::R3SurfelPointSet::InsertPoints(gaps::R3SurfelBlock*, gaps::R3Box const&)
void R3SurfelPointSet::
InsertPoints(R3SurfelBlock *block, const R3Box& constraint_box)
{
  // Check block
  if (block->NSurfels() == 0) return;

  // Check and update bounding box (conservatively)
  R3Box intersection_box = constraint_box;
  intersection_box.Intersect(block->BBox());
  if (intersection_box.IsEmpty()) return;
  bbox.Union(intersection_box);

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

  // Translate constraint to block coordinate system (and store in floats)
  const R3Point& origin = block->PositionOrigin();
  float xmin = constraint_box[0][0] - origin[0];
  float ymin = constraint_box[0][1] - origin[1];
  float zmin = constraint_box[0][2] - origin[2];
  float xmax = constraint_box[1][0] - origin[0];
  float ymax = constraint_box[1][1] - origin[1];
  float zmax = constraint_box[1][2] - origin[2];

  // Allocate space for points
  AllocatePoints(npoints + block->NSurfels());

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

  // Copy points
  for (int i = 0; i < block->NSurfels(); i++) {
    const R3Surfel *surfel = block->Surfel(i);
    if (surfel->X() < xmin) continue;
    if (surfel->Y() < ymin) continue;
    if (surfel->Z() < zmin) continue;
    if (surfel->X() > xmax) continue;
    if (surfel->Y() > ymax) continue;
    if (surfel->Z() > zmax) continue;
    points[npoints].Reset(block, surfel);
    npoints++;
  }

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

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movq %rdx, 0x170(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0x178(%rsp), %rdi
callq 0x1c0e0
cmpl $0x0, %eax
jne 0x57216
jmp 0x57826
movq 0x170(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0xc9de0
movq 0x178(%rsp), %rdi
callq 0x4a500
movq %rax, 0xe8(%rsp)
jmp 0x57242
movq 0xe8(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0xcbf10
jmp 0x57259
leaq 0x138(%rsp), %rdi
callq 0x44290
movl %eax, 0xe4(%rsp)
jmp 0x5726f
movl 0xe4(%rsp), %eax
cmpl $0x0, %eax
je 0x572b1
movl $0x1, 0x128(%rsp)
jmp 0x57819
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x1b990
jmp 0x5782e
movq 0xf0(%rsp), %rdi
addq $0x18, %rdi
leaq 0x138(%rsp), %rsi
callq 0xcbc30
jmp 0x572cc
movq 0xf0(%rsp), %rax
addq $0x50, %rax
movq %rax, 0xd0(%rsp)
movq 0x178(%rsp), %rdi
callq 0x4a780
movq %rax, 0xd8(%rsp)
jmp 0x572f7
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdi
callq 0x1bbc0
jmp 0x5730e
movq 0x178(%rsp), %rdi
callq 0x189c0
movq %rax, 0xc8(%rsp)
jmp 0x57325
movq 0xc8(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x170(%rsp), %rdi
xorl %esi, %esi
callq 0x1bb60
movq %rax, 0xc0(%rsp)
jmp 0x5734e
movq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0xb8(%rsp)
jmp 0x57368
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0xb0(%rsp)
jmp 0x57382
movsd 0xb0(%rsp), %xmm1
movsd 0xb8(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x11c(%rsp)
movq 0x170(%rsp), %rdi
xorl %esi, %esi
callq 0x1bb60
movq %rax, 0xa8(%rsp)
jmp 0x573be
movq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0xa0(%rsp)
jmp 0x573db
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x98(%rsp)
jmp 0x573f8
movsd 0x98(%rsp), %xmm1
movsd 0xa0(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x118(%rsp)
movq 0x170(%rsp), %rdi
xorl %esi, %esi
callq 0x1bb60
movq %rax, 0x90(%rsp)
jmp 0x57434
movq 0x90(%rsp), %rdi
movl $0x2, %esi
callq 0x1bba0
movsd %xmm0, 0x88(%rsp)
jmp 0x57451
movq 0x120(%rsp), %rdi
movl $0x2, %esi
callq 0x1bba0
movsd %xmm0, 0x80(%rsp)
jmp 0x5746e
movsd 0x80(%rsp), %xmm1
movsd 0x88(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x114(%rsp)
movq 0x170(%rsp), %rdi
movl $0x1, %esi
callq 0x1bb60
movq %rax, 0x78(%rsp)
jmp 0x574aa
movq 0x78(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0x70(%rsp)
jmp 0x574be
movq 0x120(%rsp), %rdi
xorl %esi, %esi
callq 0x1bba0
movsd %xmm0, 0x68(%rsp)
jmp 0x574d5
movsd 0x68(%rsp), %xmm1
movsd 0x70(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x110(%rsp)
movq 0x170(%rsp), %rdi
movl $0x1, %esi
callq 0x1bb60
movq %rax, 0x60(%rsp)
jmp 0x5750b
movq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x58(%rsp)
jmp 0x57522
movq 0x120(%rsp), %rdi
movl $0x1, %esi
callq 0x1bba0
movsd %xmm0, 0x50(%rsp)
jmp 0x5753c
movsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10c(%rsp)
movq 0x170(%rsp), %rdi
movl $0x1, %esi
callq 0x1bb60
movq %rax, 0x48(%rsp)
jmp 0x57572
movq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x1bba0
movsd %xmm0, 0x40(%rsp)
jmp 0x57589
movq 0x120(%rsp), %rdi
movl $0x2, %esi
callq 0x1bba0
movsd %xmm0, 0x38(%rsp)
jmp 0x575a3
movq 0xf0(%rsp), %rax
movsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x108(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x30(%rsp)
movq 0x178(%rsp), %rdi
callq 0x1c0e0
movl %eax, 0x34(%rsp)
jmp 0x575e2
movq 0xf0(%rsp), %rdi
movl 0x34(%rsp), %eax
movl 0x30(%rsp), %esi
addl %eax, %esi
movq (%rdi), %rax
movq 0x80(%rax), %rax
callq *%rax
jmp 0x57602
movq 0x178(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x5762c
movq 0x178(%rsp), %rsi
movq 0x98(%rsi), %rdi
callq 0x31140
jmp 0x5762a
jmp 0x5762c
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x178(%rsp), %rdi
callq 0x1c0e0
movl %eax, 0x2c(%rsp)
jmp 0x57655
movl 0x28(%rsp), %eax
movl 0x2c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x577e4
movq 0x178(%rsp), %rdi
movl 0x104(%rsp), %esi
callq 0x43660
movq %rax, 0x20(%rsp)
jmp 0x57680
movq 0x20(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x44190
movss %xmm0, 0x1c(%rsp)
jmp 0x576a2
movss 0x1c(%rsp), %xmm1
movss 0x11c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x576bb
jmp 0x577ce
movq 0xf8(%rsp), %rdi
callq 0x441a0
movss %xmm0, 0x18(%rsp)
jmp 0x576d0
movss 0x18(%rsp), %xmm1
movss 0x118(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x576e9
jmp 0x577ce
movq 0xf8(%rsp), %rdi
callq 0x441b0
movss %xmm0, 0x14(%rsp)
jmp 0x576fe
movss 0x14(%rsp), %xmm1
movss 0x114(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x57717
jmp 0x577ce
movq 0xf8(%rsp), %rdi
callq 0x44190
movss %xmm0, 0x10(%rsp)
jmp 0x5772c
movss 0x10(%rsp), %xmm0
ucomiss 0x110(%rsp), %xmm0
jbe 0x57741
jmp 0x577ce
movq 0xf8(%rsp), %rdi
callq 0x441a0
movss %xmm0, 0xc(%rsp)
jmp 0x57756
movss 0xc(%rsp), %xmm0
ucomiss 0x10c(%rsp), %xmm0
jbe 0x57768
jmp 0x577ce
movq 0xf8(%rsp), %rdi
callq 0x441b0
movss %xmm0, 0x8(%rsp)
jmp 0x5777d
movss 0x8(%rsp), %xmm0
ucomiss 0x108(%rsp), %xmm0
jbe 0x5778f
jmp 0x577ce
movq 0xf0(%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x10(%rax), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq 0x178(%rsp), %rsi
movq 0xf8(%rsp), %rdx
callq 0x558d0
jmp 0x577bd
movq 0xf0(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x57637
movq 0x178(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0x5780e
movq 0x178(%rsp), %rsi
movq 0x98(%rsi), %rdi
callq 0x311c0
jmp 0x5780c
jmp 0x5780e
movl $0x0, 0x128(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x1b990
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x130(%rsp), %rdi
callq 0x13970
nopl (%rax,%rax)