// File: 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:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movl %edx, 0x104(%rsp)
movq 0x110(%rsp), %rdi
movq %rdi, 0x80(%rsp)
movq $0x0, (%rdi)
movl 0x104(%rsp), %eax
movl %eax, 0x8(%rdi)
addq $0x10, %rdi
leaq 0x5b4856(%rip), %rsi    # 0x5fe0b0
callq 0xf8390
movq 0x80(%rsp), %rdi
addq $0x28, %rdi
movq %rdi, 0x78(%rsp)
movsd 0x15a918(%rip), %xmm2   # 0x1a4190
movsd %xmm2, 0x88(%rsp)
movsd 0x15a8ff(%rip), %xmm5   # 0x1a4188
movsd %xmm5, 0x90(%rsp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
movaps %xmm5, %xmm3
movaps %xmm5, %xmm4
callq 0xc9ee0
movq 0x80(%rsp), %rdi
movsd 0x88(%rsp), %xmm0
movsd 0x90(%rsp), %xmm1
movq $0x0, 0x60(%rdi)
addq $0x68, %rdi
callq 0x144d90
jmp 0x498d0
movq 0x80(%rsp), %rdi
movl $0xffffffff, 0x78(%rdi) # imm = 0xFFFFFFFF
movl $0x0, 0x7c(%rdi)
movq $0x0, 0x80(%rdi)
addq $0x88, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1b970
jmp 0x49903
movq 0x80(%rsp), %rax
movq $0x0, 0x90(%rax)
movq $0x0, 0x98(%rax)
movl $0xffffffff, 0xa0(%rax) # imm = 0xFFFFFFFF
movq $0x0, 0xa8(%rax)
movl $0x0, 0xb0(%rax)
movl $0x0, 0xb4(%rax)
movq $0x0, 0xb8(%rax)
movl $0x0, 0xc0(%rax)
cmpl $0x0, 0x104(%rsp)
jne 0x49987
jmp 0x49c87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0x49c8f
movl 0x104(%rsp), %esi
movq 0x108(%rsp), %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq 0xd8(%rsp), %rdi
callq 0x97b20
jmp 0x499a9
movq 0x80(%rsp), %rdi
addq $0x10, %rdi
leaq 0xd8(%rsp), %rsi
callq 0xf89e0
jmp 0x499c4
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0x104(%rsp), %eax
jge 0x49a1f
movq 0x80(%rsp), %rdi
addq $0x28, %rdi
movq 0x108(%rsp), %rax
movslq 0xd4(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
callq 0xcb9d0
jmp 0x49a0a
jmp 0x49a0c
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x499cf
movq 0x80(%rsp), %rax
movslq 0x8(%rax), %rax
movq %rax, 0x60(%rsp)
movl $0x30, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
movq %rdi, 0x68(%rsp)
callq 0x13030
movq %rax, 0x70(%rsp)
jmp 0x49a57
movq 0x60(%rsp), %rax
cmpq $0x0, %rax
je 0x49aa9
movq 0x70(%rsp), %rax
movq 0x60(%rsp), %rcx
imulq $0x30, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x47310
jmp 0x49a91
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rax
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, 0x58(%rsp)
jne 0x49a80
movq 0x80(%rsp), %rax
movq 0x70(%rsp), %rcx
movq %rcx, (%rax)
movl $0x0, 0xd0(%rsp)
movq 0x80(%rsp), %rcx
movl 0xd0(%rsp), %eax
cmpl 0x8(%rcx), %eax
jge 0x49c87
movq 0x108(%rsp), %rax
movslq 0xd0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xb8(%rsp), %rdi
callq 0xf8390
jmp 0x49b03
movq 0x80(%rsp), %rsi
addq $0x10, %rsi
leaq 0xa0(%rsp), %rdi
callq 0x4f890
jmp 0x49b1e
leaq 0xb8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xf9090
jmp 0x49b35
movq 0x80(%rsp), %rax
movq (%rax), %rax
movslq 0xd0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x187b0
movsd %xmm0, 0x40(%rsp)
jmp 0x49b7d
movsd 0x40(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x187c0
movsd %xmm0, 0x30(%rsp)
jmp 0x49ba2
movsd 0x30(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x187a0
movsd %xmm0, 0x20(%rsp)
jmp 0x49bc7
movss 0x1c(%rsp), %xmm1
movss 0x2c(%rsp), %xmm0
movq 0x38(%rsp), %rdi
movsd 0x20(%rsp), %xmm2
cvtsd2ss %xmm2, %xmm2
callq 0x44cd0
jmp 0x49be9
movq 0x80(%rsp), %rdi
movq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x28, %rdi
callq 0xcb280
movsd %xmm0, 0x10(%rsp)
jmp 0x49c0f
movq 0x8(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
cvtsi2sdl 0x104(%rsp), %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x479d0
jmp 0x49c32
movq 0x98(%rsp), %rdi
movl $0x80, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x47a50
jmp 0x49c4a
jmp 0x49c4c
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x49ac4
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
callq 0x13a90
jmp 0x49c8f
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x78(%rsp), %rdi
callq 0x1b990
movq 0xf8(%rsp), %rdi
callq 0x13970
nopw %cs:(%rax,%rax)