// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::R3SurfelBlock(gaps::R3SurfelPointSet const*)
R3SurfelBlock::
R3SurfelBlock(const R3SurfelPointSet *set)
  : surfels(NULL),
    nsurfels(set->NPoints()),
    position_origin(set->Centroid()),
    bbox(set->BBox()),
    timestamp_origin(0),
    timestamp_range(FLT_MAX,-FLT_MAX),
    min_identifier(UINT_MAX),
    max_identifier(0),
    resolution(0),
    flags(R3_SURFEL_BLOCK_BBOX_UPTODATE_FLAG),
    data(NULL),
    database(NULL),
    database_index(-1),
    file_surfels_offset(0),
    file_surfels_count(0),
    file_read_count(0),
    node(NULL),
    opengl_id(0)
{
  // Copy points
  if (nsurfels > 0) {
    // Set timestamp range and origin
    this->timestamp_range = set->TimestampRange();
    if (!this->timestamp_range.IsEmpty()) {
      this->timestamp_origin = this->timestamp_range.Mid();
    }

    // Create surfels
    surfels = new R3Surfel [ nsurfels ];
    for (int i = 0; i < set->NPoints(); i++) {
      const R3SurfelPoint *point = set->Point(i);
      R3Point position = point->Position() - position_origin.Vector();
      R3Vector normal = point->Normal();
      R3Vector tangent = point->Tangent();
      R3Surfel *surfel = &surfels[i];
      surfel->SetPosition(position[0], position[1], position[2]);
      surfel->SetNormal(normal[0], normal[1], normal[2]);
      surfel->SetTangent(tangent[0], tangent[1], tangent[2]);
      surfel->SetRadius(0, point->Radius(0));
      surfel->SetRadius(1, point->Radius(1));
      surfel->SetDepth(point->Depth());
      surfel->SetElevation(point->Elevation());
      surfel->SetColor(point->Color());
      surfel->SetTimestamp(point->Timestamp() - timestamp_origin);
      surfel->SetIdentifier(point->Identifier());
      surfel->SetAttribute(point->Attribute());
      surfel->SetFlags(point->Flags() & ~R3_SURFEL_MARKED_FLAG);
    }
  }
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
movq 0x220(%rsp), %rax
movq %rax, 0x178(%rsp)
movq $0x0, (%rax)
movq 0x218(%rsp), %rdi
callq 0x18700
movq 0x178(%rsp), %rdi
movl %eax, 0x8(%rdi)
addq $0x10, %rdi
movq 0x218(%rsp), %rsi
callq 0x560c0
movq 0x178(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x170(%rsp)
movq 0x218(%rsp), %rdi
callq 0x435d0
movq 0x170(%rsp), %rdi
movq %rax, %rsi
callq 0xc9de0
movq 0x178(%rsp), %rdi
movq $0x0, 0x60(%rdi)
addq $0x68, %rdi
movsd 0x15beec(%rip), %xmm0   # 0x1a4190
movsd 0x15bedc(%rip), %xmm1   # 0x1a4188
callq 0x144d90
jmp 0x482b3
movq 0x178(%rsp), %rdi
movl $0xffffffff, 0x78(%rdi) # imm = 0xFFFFFFFF
movl $0x0, 0x7c(%rdi)
movq $0x0, 0x80(%rdi)
addq $0x88, %rdi
movl $0x1, %esi
callq 0x1b970
jmp 0x482e7
movq 0x178(%rsp), %rax
movq $0x0, 0x90(%rax)
movq $0x0, 0x98(%rax)
movl $0xffffffff, 0xa0(%rax) # imm = 0xFFFFFFFF
movq $0x0, 0xa8(%rax)
movl $0x0, 0xb0(%rax)
movl $0x0, 0xb4(%rax)
movq $0x0, 0xb8(%rax)
movl $0x0, 0xc0(%rax)
cmpl $0x0, 0x8(%rax)
jle 0x48a57
movq 0x218(%rsp), %rdi
callq 0x4f840
movq %rax, 0x168(%rsp)
jmp 0x48364
movq 0x178(%rsp), %rax
movq 0x168(%rsp), %rcx
movq %rax, %rdi
addq $0x68, %rdi
movups (%rcx), %xmm0
movups %xmm0, 0x68(%rax)
callq 0x4f850
movl %eax, 0x164(%rsp)
jmp 0x48390
movl 0x164(%rsp), %eax
cmpl $0x0, %eax
jne 0x483e9
movq 0x178(%rsp), %rdi
addq $0x68, %rdi
callq 0x4f870
movsd %xmm0, 0x158(%rsp)
jmp 0x483b8
movq 0x178(%rsp), %rax
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0x60(%rax)
jmp 0x483e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x48a5f
movq 0x178(%rsp), %rax
movslq 0x8(%rax), %rax
movq %rax, 0x140(%rsp)
movl $0x30, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
movq %rdi, 0x148(%rsp)
callq 0x13030
movq %rax, 0x150(%rsp)
jmp 0x4842a
movq 0x140(%rsp), %rax
cmpq $0x0, %rax
je 0x4849a
movq 0x150(%rsp), %rax
movq 0x140(%rsp), %rcx
imulq $0x30, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x130(%rsp)
movq %rax, 0x138(%rsp)
movq 0x138(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0x47310
jmp 0x48479
movq 0x130(%rsp), %rcx
movq 0x128(%rsp), %rax
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, 0x138(%rsp)
jne 0x48462
movq 0x178(%rsp), %rax
movq 0x150(%rsp), %rcx
movq %rcx, (%rax)
movl $0x0, 0x208(%rsp)
movl 0x208(%rsp), %eax
movl %eax, 0x120(%rsp)
movq 0x218(%rsp), %rdi
callq 0x18700
movl %eax, 0x124(%rsp)
jmp 0x484dc
movl 0x120(%rsp), %eax
movl 0x124(%rsp), %ecx
cmpl %ecx, %eax
jge 0x48a55
movq 0x218(%rsp), %rdi
movl 0x208(%rsp), %esi
callq 0x18710
movq %rax, 0x118(%rsp)
jmp 0x48510
movq 0x118(%rsp), %rax
movq %rax, 0x200(%rsp)
movq 0x200(%rsp), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x18730
jmp 0x48537
movq 0x178(%rsp), %rsi
addq $0x10, %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x4f890
jmp 0x48552
leaq 0x1e8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
callq 0xf92b0
jmp 0x48571
movq 0x200(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x4f8d0
jmp 0x48588
movq 0x200(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x4f940
jmp 0x4859f
movq 0x178(%rsp), %rax
movq (%rax), %rax
movslq 0x208(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x180(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x1e8(%rsp), %rdi
xorl %esi, %esi
callq 0x1bde0
movq %rax, 0x110(%rsp)
jmp 0x485ee
movq 0x110(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xfc(%rsp)
leaq 0x1e8(%rsp), %rdi
movl $0x1, %esi
callq 0x1bde0
movq %rax, 0x100(%rsp)
jmp 0x48623
movq 0x100(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xec(%rsp)
leaq 0x1e8(%rsp), %rdi
movl $0x2, %esi
callq 0x1bde0
movq %rax, 0xf0(%rsp)
jmp 0x48658
movss 0xec(%rsp), %xmm1
movss 0xfc(%rsp), %xmm0
movq 0x108(%rsp), %rdi
movq 0xf0(%rsp), %rax
movsd (%rax), %xmm2
cvtsd2ss %xmm2, %xmm2
callq 0x44cd0
jmp 0x48689
movq 0x180(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0x1a0(%rsp), %rdi
xorl %esi, %esi
callq 0x31d80
movq %rax, 0xe0(%rsp)
jmp 0x486b2
movq 0xe0(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xcc(%rsp)
leaq 0x1a0(%rsp), %rdi
movl $0x1, %esi
callq 0x31d80
movq %rax, 0xd0(%rsp)
jmp 0x486e7
movq 0xd0(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xbc(%rsp)
leaq 0x1a0(%rsp), %rdi
movl $0x2, %esi
callq 0x31d80
movq %rax, 0xc0(%rsp)
jmp 0x4871c
movss 0xbc(%rsp), %xmm1
movss 0xcc(%rsp), %xmm0
movq 0xd8(%rsp), %rdi
movq 0xc0(%rsp), %rax
movsd (%rax), %xmm2
cvtsd2ss %xmm2, %xmm2
callq 0x47830
jmp 0x4874d
movq 0x180(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x188(%rsp), %rdi
xorl %esi, %esi
callq 0x31d80
movq %rax, 0xb0(%rsp)
jmp 0x48776
movq 0xb0(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x9c(%rsp)
leaq 0x188(%rsp), %rdi
movl $0x1, %esi
callq 0x31d80
movq %rax, 0xa0(%rsp)
jmp 0x487ab
movq 0xa0(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8c(%rsp)
leaq 0x188(%rsp), %rdi
movl $0x2, %esi
callq 0x31d80
movq %rax, 0x90(%rsp)
jmp 0x487e0
movss 0x8c(%rsp), %xmm1
movss 0x9c(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
movq 0x90(%rsp), %rax
movsd (%rax), %xmm2
cvtsd2ss %xmm2, %xmm2
callq 0x47900
jmp 0x48811
movq 0x180(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x200(%rsp), %rdi
xorl %esi, %esi
callq 0x4f9b0
movss %xmm0, 0x88(%rsp)
jmp 0x4883b
movss 0x88(%rsp), %xmm0
movq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x47a90
jmp 0x48855
movq 0x180(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x200(%rsp), %rdi
movl $0x1, %esi
callq 0x4f9b0
movss %xmm0, 0x7c(%rsp)
jmp 0x4887c
movss 0x7c(%rsp), %xmm0
movq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x47a90
jmp 0x48893
movq 0x180(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4f9e0
movsd %xmm0, 0x68(%rsp)
jmp 0x488b5
movq 0x60(%rsp), %rdi
movsd 0x68(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x47b10
jmp 0x488cb
movq 0x180(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fa00
movsd %xmm0, 0x58(%rsp)
jmp 0x488ed
movq 0x50(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x47b90
jmp 0x48903
movq 0x180(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fa20
movq %rax, 0x48(%rsp)
jmp 0x48924
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x44d10
jmp 0x48935
movq 0x180(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fa60
movsd %xmm0, 0x38(%rsp)
jmp 0x48957
movq 0x30(%rsp), %rdi
movsd 0x38(%rsp), %xmm0
movq 0x178(%rsp), %rax
movsd 0x60(%rax), %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x4fa40
jmp 0x4897e
movq 0x180(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fad0
movl %eax, 0x2c(%rsp)
jmp 0x4899e
movl 0x2c(%rsp), %esi
movq 0x20(%rsp), %rdi
callq 0x4fab0
jmp 0x489ae
movq 0x180(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fb10
movl %eax, 0x1c(%rsp)
jmp 0x489ce
movl 0x1c(%rsp), %esi
movq 0x10(%rsp), %rdi
callq 0x4faf0
jmp 0x489de
movq 0x180(%rsp), %rax
movq %rax, (%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fb50
movb %al, 0xf(%rsp)
jmp 0x489fd
movq (%rsp), %rdi
movb 0xf(%rsp), %al
movzbl %al, %esi
andl $0x7f, %esi
callq 0x4fb30
jmp 0x48a12
jmp 0x48a14
movl 0x208(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x208(%rsp)
jmp 0x484b8
movq 0x148(%rsp), %rsi
movq 0x150(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
callq 0x13a90
jmp 0x48a5f
jmp 0x48a57
addq $0x228, %rsp            # imm = 0x228
retq
movq 0x170(%rsp), %rdi
callq 0x1b990
movq 0x210(%rsp), %rdi
callq 0x13970
nopl (%rax)