// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::R3SurfelBlock(gaps::RNArray<gaps::R3Point*> const&)
R3SurfelBlock::
R3SurfelBlock(const RNArray<R3Point *>& points)
  : surfels(NULL),
    nsurfels(points.NEntries()),
    position_origin(R3zero_point),
    bbox(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
    timestamp_origin(0),
    timestamp_range(FLT_MAX,-FLT_MAX),
    resolution(0),
    flags(0),
    data(NULL),
    database(NULL),
    database_index(-1),
    file_surfels_offset(0),
    file_surfels_count(0),
    file_read_count(0),
    node(NULL),
    opengl_id(0)
{
  // Check points
  if (points.IsEmpty()) return;
  
  // Compute position_origin
  position_origin = R3Centroid(points);

  // Compute bounding box
  for (int i = 0; i < points.NEntries(); i++) {
    bbox.Union(*(points[i]));
  }

  // Copy surfels
  surfels = new R3Surfel [ nsurfels ];
  for (int i = 0; i < nsurfels; i++) {
    R3Point point = *(points[i]);
    point -= position_origin.Vector();
    R3Surfel& surfel = this->surfels[i];
    surfel.SetPosition(point.X(), point.Y(), point.Z());
    surfel.SetRadius(bbox.DiagonalLength() / points.NEntries());
    surfel.SetColor(128, 128, 128);
  }
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq $0x0, (%rax)
movq 0x128(%rsp), %rdi
callq 0x16d50
movq 0xa8(%rsp), %rdi
movl %eax, 0x8(%rdi)
addq $0x10, %rdi
leaq 0x5b43af(%rip), %rsi    # 0x5fe0b0
callq 0xf8390
movq 0xa8(%rsp), %rdi
addq $0x28, %rdi
movq %rdi, 0xa0(%rsp)
movsd 0x15a46e(%rip), %xmm2   # 0x1a4190
movsd %xmm2, 0xb0(%rsp)
movsd 0x15a455(%rip), %xmm5   # 0x1a4188
movsd %xmm5, 0xb8(%rsp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
movaps %xmm5, %xmm3
movaps %xmm5, %xmm4
callq 0xc9ee0
movq 0xa8(%rsp), %rdi
movsd 0xb0(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
movq $0x0, 0x60(%rdi)
addq $0x68, %rdi
callq 0x144d90
jmp 0x49d7a
movq 0xa8(%rsp), %rdi
movq $0x0, 0x80(%rdi)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1b970
jmp 0x49d9f
movq 0xa8(%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)
movq 0x128(%rsp), %rdi
callq 0x31da0
movl %eax, 0x9c(%rsp)
jmp 0x49e11
movl 0x9c(%rsp), %eax
cmpl $0x0, %eax
je 0x49e3b
jmp 0x4a195
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x4a19d
movq 0x128(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq 0x100(%rsp), %rdi
callq 0x949b0
jmp 0x49e56
movq 0xa8(%rsp), %rdi
addq $0x10, %rdi
leaq 0x100(%rsp), %rsi
callq 0xf89e0
jmp 0x49e71
movl $0x0, 0xfc(%rsp)
movl 0xfc(%rsp), %eax
movl %eax, 0x94(%rsp)
movq 0x128(%rsp), %rdi
callq 0x16d50
movl %eax, 0x98(%rsp)
jmp 0x49ea0
movl 0x94(%rsp), %eax
movl 0x98(%rsp), %ecx
cmpl %ecx, %eax
jge 0x49f13
movq 0xa8(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x80(%rsp)
movq 0x128(%rsp), %rdi
movl 0xfc(%rsp), %esi
callq 0x4fb90
movq %rax, 0x88(%rsp)
jmp 0x49ee4
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdi
callq 0xcb9d0
jmp 0x49efb
jmp 0x49efd
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x49e7c
movq 0xa8(%rsp), %rax
movslq 0x8(%rax), %rax
movq %rax, 0x68(%rsp)
movl $0x30, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
movq %rdi, 0x70(%rsp)
callq 0x13030
movq %rax, 0x78(%rsp)
jmp 0x49f4b
movq 0x68(%rsp), %rax
cmpq $0x0, %rax
je 0x49f9d
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
imulq $0x30, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x58(%rsp)
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x47310
jmp 0x49f85
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %rax
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, 0x60(%rsp)
jne 0x49f74
movq 0xa8(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rcx, (%rax)
movl $0x0, 0xf8(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xf8(%rsp), %eax
cmpl 0x8(%rcx), %eax
jge 0x4a195
movq 0x128(%rsp), %rdi
movl 0xf8(%rsp), %esi
callq 0x4fb90
movq %rax, 0x48(%rsp)
jmp 0x49feb
movq 0x48(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0xf8390
jmp 0x49fff
movq 0xa8(%rsp), %rsi
addq $0x10, %rsi
leaq 0xc8(%rsp), %rdi
callq 0x4f890
jmp 0x4a01a
leaq 0xe0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0xf9090
jmp 0x4a031
movq 0xa8(%rsp), %rax
movq (%rax), %rax
movslq 0xf8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x187b0
movsd %xmm0, 0x40(%rsp)
jmp 0x4a079
movsd 0x40(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x187c0
movsd %xmm0, 0x30(%rsp)
jmp 0x4a09e
movsd 0x30(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x187a0
movsd %xmm0, 0x20(%rsp)
jmp 0x4a0c3
movss 0x1c(%rsp), %xmm1
movss 0x2c(%rsp), %xmm0
movq 0x38(%rsp), %rdi
movsd 0x20(%rsp), %xmm2
cvtsd2ss %xmm2, %xmm2
callq 0x44cd0
jmp 0x4a0e5
movq 0xa8(%rsp), %rdi
movq 0xc0(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x28, %rdi
callq 0xcb280
movsd %xmm0, 0x10(%rsp)
jmp 0x4a10b
movq 0x128(%rsp), %rdi
callq 0x16d50
movl %eax, 0x4(%rsp)
jmp 0x4a11e
movq 0x8(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
movl 0x4(%rsp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x479d0
jmp 0x4a140
movq 0xc0(%rsp), %rdi
movl $0x80, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x47a50
jmp 0x4a158
jmp 0x4a15a
movl 0xf8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x49fb8
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
callq 0x13a90
jmp 0x4a19d
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xa0(%rsp), %rdi
callq 0x1b990
movq 0x120(%rsp), %rdi
callq 0x13970
nopw (%rax,%rax)