// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rdi, %r14
andq $0x0, (%rdi)
movq %rsi, %rbx
movl 0xc(%rsi), %eax
movl %eax, 0x8(%rdi)
addq $0x10, %rdi
leaq 0x4fc31b(%rip), %rsi    # 0x526690
movq %rdi, 0x18(%rsp)
callq 0x781cc
leaq 0x28(%r14), %rdi
movsd 0x9dddd(%rip), %xmm0    # 0xc8168
movsd 0x9dddd(%rip), %xmm3    # 0xc8170
movq %rdi, 0x8(%rsp)
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm3, %xmm4
movaps %xmm3, %xmm5
callq 0x63d86
andq $0x0, 0x60(%r14)
leaq 0x68(%r14), %rdi
movsd 0x9ddae(%rip), %xmm0    # 0xc8168
movsd 0x9ddae(%rip), %xmm1    # 0xc8170
callq 0x9c1e0
xorps %xmm0, %xmm0
movups %xmm0, 0x90(%r14)
movups %xmm0, 0x80(%r14)
orl $-0x1, 0xa0(%r14)
movups %xmm0, 0xa8(%r14)
movups %xmm0, 0xb4(%r14)
movq %rbx, 0x10(%rsp)
cmpl $0x0, 0xc(%rbx)
je 0x2a568
leaq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r15
movq %r15, %rsi
xorl %edx, %edx
callq 0x4be67
leaq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x784a6
xorl %ebx, %ebx
movslq 0xc(%r15), %rax
cmpq %rax, %rbx
jge 0x2a445
movq (%r15), %rax
movq (%rax,%rbx,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x6464c
incq %rbx
jmp 0x2a426
movslq 0x8(%r14), %r13
pushq $0x30
popq %rcx
movq %r13, %rax
mulq %rcx
pushq $-0x1
popq %r15
cmovnoq %rax, %r15
movq %r15, %rdi
callq 0x13030
movq %rax, %rbp
testl %r13d, %r13d
je 0x2a483
imulq $0x30, %r13, %rbx
xorl %r12d, %r12d
leaq (%r12,%rbp), %rdi
callq 0x29118
addq $0x30, %r12
cmpq %r12, %rbx
jne 0x2a471
movq %rbp, (%r14)
pushq $0x2e
popq %r12
xorl %ebx, %ebx
leaq 0x20(%rsp), %r13
leaq 0x40(%rsp), %rbp
movslq 0x8(%r14), %rax
cmpq %rax, %rbx
jge 0x2a568
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rsi
movq %r13, %rdi
callq 0x781cc
movq %r14, %r15
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
callq 0x2d0b2
movq %r13, %rdi
movq %rbp, %rsi
callq 0x78854
movq %rbp, %r14
movq %r13, %rbp
cvtsd2ss 0x30(%rsp), %xmm0
cvtpd2ps 0x20(%rsp), %xmm1
movq (%r15), %r13
movlpd %xmm1, -0x2e(%r13,%r12)
movss %xmm0, -0x26(%r13,%r12)
movq 0x8(%rsp), %rdi
callq 0x64300
movq 0x10(%rsp), %rax
cvtsi2sdl 0xc(%rax), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x9e8ab(%rip), %xmm0    # 0xc8dc8
addsd 0x9dc13(%rip), %xmm0    # 0xc8138
cvtsd2ss %xmm0, %xmm0
movss 0x9e8a7(%rip), %xmm1    # 0xc8dd8
minss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movw %ax, -0x12(%r13,%r12)
movw %ax, -0x10(%r13,%r12)
movw $0x8080, -0x2(%r13,%r12) # imm = 0x8080
movb $-0x80, (%r13,%r12)
incq %rbx
addq $0x30, %r12
movq %rbp, %r13
movq %r14, %rbp
movq %r15, %r14
jmp 0x2a496
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a591
jmp 0x2a591
movq %rax, %r14
movq %rbp, %rdi
movq %r15, %rsi
callq 0x139f0
jmp 0x2a594
jmp 0x2a591
jmp 0x2a591
jmp 0x2a591
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x649ae
movq %r14, %rdi
callq 0x138f0