// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
xorl %r13d, %r13d
movq %r13, (%rdi)
movl 0xc(%rsi), %eax
movl %eax, 0x8(%rdi)
leaq 0x10(%rdi), %r12
leaq 0x508ebd(%rip), %rsi    # 0x535670
movq %r12, %rdi
callq 0x83dd2
leaq 0x28(%rbx), %rdi
movsd 0xb09a1(%rip), %xmm0    # 0xdd168
movsd 0xb09a1(%rip), %xmm3    # 0xdd170
movq %rdi, (%rsp)
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm3, %xmm4
movaps %xmm3, %xmm5
callq 0x6d3f4
movq %r13, 0x60(%rbx)
leaq 0x68(%rbx), %rdi
movsd 0xb0974(%rip), %xmm0    # 0xdd168
movsd 0xb0974(%rip), %xmm1    # 0xdd170
callq 0xab9aa
xorps %xmm0, %xmm0
movups %xmm0, 0x90(%rbx)
movups %xmm0, 0x80(%rbx)
movl $0xffffffff, 0xa0(%rbx) # imm = 0xFFFFFFFF
movups %xmm0, 0xa8(%rbx)
movq %rbx, 0x8(%rsp)
movups %xmm0, 0xb4(%rbx)
cmpl $0x0, 0xc(%r15)
je 0x2c9c9
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x52cfc
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x8412a
cmpl $0x0, 0xc(%r15)
movq (%rsp), %rbx
jle 0x2c87f
xorl %r12d, %r12d
movq (%r15), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
callq 0x6dd46
incq %r12
movslq 0xc(%r15), %rax
cmpq %rax, %r12
jl 0x2c864
movq 0x8(%rsp), %rbx
movslq 0x8(%rbx), %rbp
movl $0x30, %ecx
movq %rbp, %rax
mulq %rcx
movq $-0x1, %r14
cmovnoq %rax, %r14
movq %r14, %rdi
callq 0x13030
movq %rax, %r13
testl %ebp, %ebp
je 0x2c9c6
shlq $0x4, %rbp
leaq (%rbp,%rbp,2), %rbp
xorl %r12d, %r12d
leaq (%r12,%r13), %rdi
callq 0x2b118
addq $0x30, %r12
cmpq %r12, %rbp
jne 0x2c8bd
cmpl $0x0, 0x8(%rbx)
movq %r13, (%rbx)
jle 0x2c9c9
movl $0x2e, %ebp
xorl %r12d, %r12d
leaq 0x10(%rsp), %r13
leaq 0x30(%rsp), %rbx
movq 0x8(%rsp), %r14
movq (%r15), %rax
movq (%rax,%r12,8), %rsi
movq %r13, %rdi
callq 0x83dd2
movq 0x8(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd 0x18(%rax), %xmm1
movsd 0x20(%rax), %xmm2
movq %rbx, %rdi
callq 0x84856
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8472a
movq %r13, %rbx
xorps %xmm0, %xmm0
cvtsd2ss 0x20(%rsp), %xmm0
cvtpd2ps 0x10(%rsp), %xmm1
movq (%r14), %r13
movlpd %xmm1, -0x2e(%r13,%rbp)
movss %xmm0, -0x26(%r13,%rbp)
movq (%rsp), %rdi
callq 0x6d9a8
xorps %xmm1, %xmm1
cvtsi2sdl 0xc(%r15), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0xb1456(%rip), %xmm0    # 0xdddc8
addsd 0xb07be(%rip), %xmm0    # 0xdd138
cvtsd2ss %xmm0, %xmm0
movss 0xb1452(%rip), %xmm1    # 0xdddd8
minss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movw %ax, -0x12(%r13,%rbp)
movw %ax, -0x10(%r13,%rbp)
movw $0x8080, -0x2(%r13,%rbp) # imm = 0x8080
movb $-0x80, (%r13,%rbp)
incq %r12
movslq 0x8(%r14), %rax
addq $0x30, %rbp
cmpq %rax, %r12
movq %rbx, %r13
leaq 0x30(%rsp), %rbx
jl 0x2c8f3
jmp 0x2c9c9
movq %r13, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c9f2
jmp 0x2c9f2
jmp 0x2c9f2
jmp 0x2c9f2
movq %r14, %rsi
movq %rax, %r14
movq %r13, %rdi
callq 0x139b0
jmp 0x2c9f5
jmp 0x2c9f2
movq %rax, %r14
movq (%rsp), %rdi
callq 0x6e174
movq %r14, %rdi
callq 0x138b0