// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::R3SurfelBlock(gaps::R3SurfelPointSet const*, gaps::R3Point const&, double)
R3SurfelBlock::
R3SurfelBlock(const R3SurfelPointSet *set,
  const R3Point& position_origin, RNScalar timestamp_origin)
  : surfels(NULL),
    nsurfels(set->NPoints()),
    position_origin(position_origin),
    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 surfels
  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();
    }

    // Copy 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 $0x238, %rsp            # imm = 0x238
movq %rdi, 0x230(%rsp)
movq %rsi, 0x228(%rsp)
movq %rdx, 0x220(%rsp)
movsd %xmm0, 0x218(%rsp)
movq 0x230(%rsp), %rax
movq %rax, 0x178(%rsp)
movq $0x0, (%rax)
movq 0x228(%rsp), %rdi
callq 0x18700
movq 0x178(%rsp), %rdi
movl %eax, 0x8(%rdi)
addq $0x10, %rdi
movq 0x220(%rsp), %rsi
callq 0xf8390
movq 0x178(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x170(%rsp)
movq 0x228(%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 0x15b65b(%rip), %xmm0   # 0x1a4190
movsd 0x15b64b(%rip), %xmm1   # 0x1a4188
callq 0x144d90
jmp 0x48b44
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 0x48b78
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 0x492e0
movq 0x228(%rsp), %rdi
callq 0x4f840
movq %rax, 0x168(%rsp)
jmp 0x48bf5
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 0x48c21
movl 0x164(%rsp), %eax
cmpl $0x0, %eax
jne 0x48c7a
movq 0x178(%rsp), %rdi
addq $0x68, %rdi
callq 0x4f870
movsd %xmm0, 0x158(%rsp)
jmp 0x48c49
movq 0x178(%rsp), %rax
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0x60(%rax)
jmp 0x48c7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x210(%rsp)
movl %eax, 0x20c(%rsp)
jmp 0x492e8
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 0x48cbb
movq 0x140(%rsp), %rax
cmpq $0x0, %rax
je 0x48d2b
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 0x48d0a
movq 0x130(%rsp), %rcx
movq 0x128(%rsp), %rax
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, 0x138(%rsp)
jne 0x48cf3
movq 0x178(%rsp), %rax
movq 0x150(%rsp), %rcx
movq %rcx, (%rax)
movl $0x0, 0x208(%rsp)
movl 0x208(%rsp), %eax
movl %eax, 0x120(%rsp)
movq 0x228(%rsp), %rdi
callq 0x18700
movl %eax, 0x124(%rsp)
jmp 0x48d6d
movl 0x120(%rsp), %eax
movl 0x124(%rsp), %ecx
cmpl %ecx, %eax
jge 0x492de
movq 0x228(%rsp), %rdi
movl 0x208(%rsp), %esi
callq 0x18710
movq %rax, 0x118(%rsp)
jmp 0x48da1
movq 0x118(%rsp), %rax
movq %rax, 0x200(%rsp)
movq 0x200(%rsp), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x18730
jmp 0x48dc8
movq 0x220(%rsp), %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x4f890
jmp 0x48ddf
leaq 0x1e8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
callq 0xf92b0
jmp 0x48dfe
movq 0x200(%rsp), %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x4f8d0
jmp 0x48e15
movq 0x200(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x4f940
jmp 0x48e2c
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 0x48e7b
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 0x48eb0
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 0x48ee5
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 0x48f16
movq 0x180(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0x1a0(%rsp), %rdi
xorl %esi, %esi
callq 0x31d80
movq %rax, 0xe0(%rsp)
jmp 0x48f3f
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 0x48f74
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 0x48fa9
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 0x48fda
movq 0x180(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x188(%rsp), %rdi
xorl %esi, %esi
callq 0x31d80
movq %rax, 0xb0(%rsp)
jmp 0x49003
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 0x49038
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 0x4906d
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 0x4909e
movq 0x180(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x200(%rsp), %rdi
xorl %esi, %esi
callq 0x4f9b0
movss %xmm0, 0x88(%rsp)
jmp 0x490c8
movss 0x88(%rsp), %xmm0
movq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x47a90
jmp 0x490e2
movq 0x180(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x200(%rsp), %rdi
movl $0x1, %esi
callq 0x4f9b0
movss %xmm0, 0x7c(%rsp)
jmp 0x49109
movss 0x7c(%rsp), %xmm0
movq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x47a90
jmp 0x49120
movq 0x180(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4f9e0
movsd %xmm0, 0x68(%rsp)
jmp 0x49142
movq 0x60(%rsp), %rdi
movsd 0x68(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x47b10
jmp 0x49158
movq 0x180(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fa00
movsd %xmm0, 0x58(%rsp)
jmp 0x4917a
movq 0x50(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x47b90
jmp 0x49190
movq 0x180(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fa20
movq %rax, 0x48(%rsp)
jmp 0x491b1
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x44d10
jmp 0x491c2
movq 0x180(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fa60
movsd %xmm0, 0x38(%rsp)
jmp 0x491e4
movq 0x30(%rsp), %rdi
movsd 0x38(%rsp), %xmm0
movsd 0x218(%rsp), %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x4fa40
jmp 0x49207
movq 0x180(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fad0
movl %eax, 0x2c(%rsp)
jmp 0x49227
movl 0x2c(%rsp), %esi
movq 0x20(%rsp), %rdi
callq 0x4fab0
jmp 0x49237
movq 0x180(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fb10
movl %eax, 0x1c(%rsp)
jmp 0x49257
movl 0x1c(%rsp), %esi
movq 0x10(%rsp), %rdi
callq 0x4faf0
jmp 0x49267
movq 0x180(%rsp), %rax
movq %rax, (%rsp)
movq 0x200(%rsp), %rdi
callq 0x4fb50
movb %al, 0xf(%rsp)
jmp 0x49286
movq (%rsp), %rdi
movb 0xf(%rsp), %al
movzbl %al, %esi
andl $0x7f, %esi
callq 0x4fb30
jmp 0x4929b
jmp 0x4929d
movl 0x208(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x208(%rsp)
jmp 0x48d49
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 0x492e8
jmp 0x492e0
addq $0x238, %rsp            # imm = 0x238
retq
movq 0x170(%rsp), %rdi
callq 0x1b990
movq 0x210(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)