// File: /workspace/github_cpp_makefile_star2_O1/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
movl %edx, %r14d
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
xorl %ebx, %ebx
movq %rbx, (%rdi)
movl %edx, 0x8(%rdi)
leaq 0x10(%rdi), %r12
leaq 0x509d04(%rip), %rsi    # 0x536670
movq %r12, %rdi
callq 0x84d8e
leaq 0x28(%r15), %rdi
movsd 0xb17f0(%rip), %xmm0    # 0xde170
movsd 0xb17f0(%rip), %xmm3    # 0xde178
movq %rdi, 0x18(%rsp)
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm3, %xmm4
movaps %xmm3, %xmm5
callq 0x6e028
movq %rbx, 0x60(%r15)
leaq 0x68(%r15), %rdi
movsd 0xb17c2(%rip), %xmm0    # 0xde170
movsd 0xb17c2(%rip), %xmm1    # 0xde178
callq 0xace9e
movl $0xffffffff, 0x78(%r15) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x7c(%r15)
movups %xmm0, 0x8c(%r15)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x9c(%r15)
movups %xmm0, 0xa8(%r15)
movups %xmm0, 0xb4(%r15)
testl %r14d, %r14d
je 0x2cb7a
leaq 0x20(%rsp), %rdi
movl %r14d, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x5501d
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x850ec
testl %r14d, %r14d
jle 0x2ca41
movl %r14d, %ebx
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x6e9a6
addq $0x18, %r12
decq %rbx
jne 0x2ca2b
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
movl %r14d, 0x8(%rsp)
testl %ebp, %ebp
je 0x2ca93
shlq $0x4, %rbp
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
xorl %r14d, %r14d
leaq (%r14,%r13), %rdi
callq 0x2b548
addq $0x30, %r14
cmpq %r14, %rbx
jne 0x2ca81
movq %r13, (%r15)
cmpl $0x0, 0x8(%r15)
movl 0x8(%rsp), %eax
jle 0x2cb7a
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %r12
leaq 0x40(%rsp), %r13
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
leaq (%rax,%rbp), %rsi
movq %r12, %rdi
callq 0x84d8e
movsd 0x10(%r15), %xmm0
movsd 0x18(%r15), %xmm1
movsd 0x20(%r15), %xmm2
movq %r13, %rdi
callq 0x85816
movq %r12, %rdi
movq %r13, %rsi
callq 0x856ec
xorps %xmm0, %xmm0
cvtsd2ss 0x30(%rsp), %xmm0
cvtpd2ps 0x20(%rsp), %xmm1
movq (%r15), %rbx
movlpd %xmm1, (%rbx,%rbp,2)
movss %xmm0, 0x8(%rbx,%rbp,2)
movq 0x18(%rsp), %rdi
callq 0x6e608
divsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0xb22a4(%rip), %xmm0    # 0xdedd8
addsd 0xb1604(%rip), %xmm0    # 0xde140
cvtsd2ss %xmm0, %xmm0
movss 0xb22a0(%rip), %xmm1    # 0xdede8
minss %xmm0, %xmm1
cvttss2si %xmm1, %eax
movw %ax, 0x1c(%rbx,%rbp,2)
movw %ax, 0x1e(%rbx,%rbp,2)
movw $0x8080, 0x2c(%rbx,%rbp,2) # imm = 0x8080
movb $-0x80, 0x2e(%rbx,%rbp,2)
incq %r14
movslq 0x8(%r15), %rax
addq $0x18, %rbp
cmpq %rax, %r14
jl 0x2cac1
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2cba3
jmp 0x2cba3
jmp 0x2cba3
jmp 0x2cba3
movq %rax, %r14
movq %r13, %rdi
movq %r12, %rsi
callq 0x139b0
jmp 0x2cba6
jmp 0x2cba3
movq %rax, %r14
movq 0x18(%rsp), %rdi
callq 0x6ede0
movq %r14, %rdi
callq 0x138b0