// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, %r15
xorl %ebx, %ebx
movq %rbx, (%rdi)
movl 0xc(%rsi), %eax
movl %eax, 0x8(%rdi)
leaq 0x10(%rdi), %r12
leaq 0x509a8e(%rip), %rsi    # 0x536670
movq %r12, %rdi
callq 0x84d8e
leaq 0x28(%r15), %rdi
movsd 0xb157a(%rip), %xmm0    # 0xde170
movsd 0xb157a(%rip), %xmm3    # 0xde178
movq %rdi, (%rsp)
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm3, %xmm4
movaps %xmm3, %xmm5
callq 0x6e028
movq %rbx, 0x60(%r15)
leaq 0x68(%r15), %rdi
movsd 0xb154d(%rip), %xmm0    # 0xde170
movsd 0xb154d(%rip), %xmm1    # 0xde178
callq 0xace9e
xorps %xmm0, %xmm0
movups %xmm0, 0x90(%r15)
movups %xmm0, 0x80(%r15)
movl $0xffffffff, 0xa0(%r15) # imm = 0xFFFFFFFF
movups %xmm0, 0xa8(%r15)
movq %r15, 0x8(%rsp)
movups %xmm0, 0xb4(%r15)
cmpl $0x0, 0xc(%r14)
je 0x2cdf0
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x536b0
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x850ec
cmpl $0x0, 0xc(%r14)
movq 0x8(%rsp), %r15
jle 0x2ccb4
xorl %ebx, %ebx
movq (%r14), %rax
movq (%rax,%rbx,8), %rsi
movq (%rsp), %rdi
callq 0x6e9a6
incq %rbx
movslq 0xc(%r14), %rax
cmpq %rax, %rbx
jl 0x2cc98
movslq 0x8(%r15), %rbp
movl $0x30, %ecx
movq %rbp, %rax
mulq %rcx
movq $-0x1, %r12
cmovnoq %rax, %r12
movq %r12, %rdi
callq 0x13030
movq %rax, %r13
testl %ebp, %ebp
je 0x2cd02
shlq $0x4, %rbp
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
xorl %ebp, %ebp
movq %r13, %rdi
addq %rbp, %rdi
callq 0x2b548
addq $0x30, %rbp
cmpq %rbp, %rbx
jne 0x2ccee
movq %r13, (%r15)
cmpl $0x0, 0x8(%r15)
jle 0x2cdf0
movl $0x2e, %ebp
xorl %ebx, %ebx
leaq 0x10(%rsp), %r13
leaq 0x30(%rsp), %r15
movq (%r14), %rax
movq (%rax,%rbx,8), %rsi
movq %r13, %rdi
callq 0x84d8e
movq 0x8(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd 0x18(%rax), %xmm1
movsd 0x20(%rax), %xmm2
movq %r15, %rdi
callq 0x85816
movq %r13, %rdi
movq %r15, %rsi
callq 0x856ec
xorps %xmm0, %xmm0
cvtsd2ss 0x20(%rsp), %xmm0
cvtpd2ps 0x10(%rsp), %xmm1
movq 0x8(%rsp), %r15
movq (%r15), %r12
movlpd %xmm1, -0x2e(%r12,%rbp)
movss %xmm0, -0x26(%r12,%rbp)
movq (%rsp), %rdi
callq 0x6e608
xorps %xmm1, %xmm1
cvtsi2sdl 0xc(%r14), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0xb2036(%rip), %xmm0    # 0xdedd8
addsd 0xb1396(%rip), %xmm0    # 0xde140
cvtsd2ss %xmm0, %xmm0
movss 0xb2032(%rip), %xmm1    # 0xdede8
minss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movw %ax, -0x12(%r12,%rbp)
movw %ax, -0x10(%r12,%rbp)
movw $0x8080, -0x2(%r12,%rbp) # imm = 0x8080
movb $-0x80, (%r12,%rbp)
incq %rbx
movslq 0x8(%r15), %rax
addq $0x30, %rbp
cmpq %rax, %rbx
leaq 0x30(%rsp), %r15
jl 0x2cd21
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ce19
jmp 0x2ce19
jmp 0x2ce19
jmp 0x2ce19
movq %rax, %r14
movq %r13, %rdi
movq %r12, %rsi
callq 0x139b0
jmp 0x2ce1c
jmp 0x2ce19
movq %rax, %r14
movq (%rsp), %rdi
callq 0x6ede0
movq %r14, %rdi
callq 0x138b0
nop