// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::R3SurfelBlock(gaps::R3Point const*, int)
R3SurfelBlock::
R3SurfelBlock(const R3Point *points, int npoints)
  : surfels(NULL),
    nsurfels(npoints),
    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),
    min_identifier(UINT_MAX),
    max_identifier(0),
    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 number of points
  if (npoints == 0) return;

  // Compute position_origin
  position_origin = R3Centroid(npoints, (R3Point *) points);

  // Compute bounding box
  for (int i = 0; i < npoints; 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() / npoints);
    surfel.SetColor(128, 128, 128);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
xorl %r15d, %r15d
movq %r15, (%rdi)
movl %edx, 0x8(%rsp)
movl %edx, 0x8(%rdi)
leaq 0x10(%rdi), %r12
leaq 0x509144(%rip), %rsi    # 0x535670
movq %r12, %rdi
callq 0x83dd2
leaq 0x28(%r14), %rdi
movsd 0xb0c28(%rip), %xmm0    # 0xdd168
movsd 0xb0c28(%rip), %xmm3    # 0xdd170
movq %rdi, 0x10(%rsp)
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm3, %xmm4
movaps %xmm3, %xmm5
callq 0x6d3f4
movq %r15, 0x60(%r14)
leaq 0x68(%r14), %rdi
movsd 0xb0bfa(%rip), %xmm0    # 0xdd168
movsd 0xb0bfa(%rip), %xmm1    # 0xdd170
callq 0xab9aa
movl $0xffffffff, 0x78(%r14) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x7c(%r14)
movups %xmm0, 0x8c(%r14)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x9c(%r14)
movups %xmm0, 0xa8(%r14)
movups %xmm0, 0xb4(%r14)
movl 0x8(%rsp), %ebp
testl %ebp, %ebp
je 0x2c749
leaq 0x20(%rsp), %rdi
movl %ebp, %esi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq 0x545c1
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x8412a
testl %ebp, %ebp
movq 0x10(%rsp), %rbx
jle 0x2c605
movl %ebp, %r15d
movq 0x18(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6dd46
addq $0x18, %r12
decq %r15
jne 0x2c5f1
movslq 0x8(%r14), %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 0x2c746
shlq $0x4, %rbp
leaq (,%rbp,2), %r15
addq %rbp, %r15
xorl %ebp, %ebp
movq %r13, %rdi
addq %rbp, %rdi
callq 0x2b118
addq $0x30, %rbp
cmpq %rbp, %r15
jne 0x2c643
cmpl $0x0, 0x8(%r14)
movq %r13, (%r14)
movl 0x8(%rsp), %eax
jle 0x2c749
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %rbx
leaq 0x40(%rsp), %r13
xorl %r15d, %r15d
movq 0x18(%rsp), %rax
leaq (%rax,%rbp), %rsi
movq %rbx, %rdi
callq 0x83dd2
movsd 0x10(%r14), %xmm0
movsd 0x18(%r14), %xmm1
movsd 0x20(%r14), %xmm2
movq %r13, %rdi
callq 0x84856
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8472a
xorps %xmm0, %xmm0
cvtsd2ss 0x30(%rsp), %xmm0
cvtpd2ps 0x20(%rsp), %xmm1
movq (%r14), %r12
movlpd %xmm1, (%r12,%rbp,2)
movss %xmm0, 0x8(%r12,%rbp,2)
movq 0x10(%rsp), %rdi
callq 0x6d9a8
divsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0xb16ce(%rip), %xmm0    # 0xdddc8
addsd 0xb0a36(%rip), %xmm0    # 0xdd138
cvtsd2ss %xmm0, %xmm0
movss 0xb16ca(%rip), %xmm1    # 0xdddd8
minss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movw %ax, 0x1c(%r12,%rbp,2)
movw %ax, 0x1e(%r12,%rbp,2)
movw $0x8080, 0x2c(%r12,%rbp,2) # imm = 0x8080
movb $-0x80, 0x2e(%r12,%rbp,2)
incq %r15
movslq 0x8(%r14), %rax
addq $0x18, %rbp
cmpq %rax, %r15
jl 0x2c685
jmp 0x2c749
movq %r13, (%r14)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c772
jmp 0x2c772
jmp 0x2c772
jmp 0x2c772
movq %rax, %r14
movq %r13, %rdi
movq %r12, %rsi
callq 0x139b0
jmp 0x2c775
jmp 0x2c772
movq %rax, %r14
movq 0x10(%rsp), %rdi
callq 0x6e174
movq %r14, %rdi
callq 0x138b0
nop