// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelBlock.cpp
// Function: gaps::R3SurfelBlock::UpdateResolution()
void R3SurfelBlock::
UpdateResolution(void)
{
  // Initialize resolution
  resolution = 0;

#if 0
  // Estimate resoluton based on surfel radii
  if (nsurfels > 0) {
    // Read block
    if (database) database->ReadBlock(this);

    // Sum surfel radii
    int nsamples = 1000;
    if (nsurfels < nsamples) nsamples = nsurfels;
    int step = nsurfels / nsamples;
    RNLength total_radius = 0;
    for (int i = 0; i < nsamples; i++) {
      R3Surfel *surfel = &surfels[i*step];
      RNLength radius = surfel->Radius();
      total_radius += radius;
    }

    // Resolution is samples / area
    if (RNIsZero(total_radius)) return;
    RNLength average_radius = total_radius / nsamples;
    RNScalar area = RN_PI * average_radius * average_radius;
    resolution = 1.0 / area;

    // Release block
    if (database) database->ReleaseBlock(this);
  }
#else
  // Estimate resolution based on number of surfels per cross-section of bounding box
  R3Box box = BBox();
  int dim = box.ShortestAxis();
  RNLength length1 = box.AxisLength((dim+1)%3);
  RNLength length2 = box.AxisLength((dim+2)%3);
  RNArea area = length1 * length2;
  resolution = (area > 0) ? sqrt(nsurfels / area) : 0;
#endif

  // Mark resolution uptodate
  flags.Add(R3_SURFEL_BLOCK_RESOLUTION_UPTODATE_FLAG);
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movq $0x0, 0x80(%rdi)
callq 0x4a500
movq %rax, %rsi
leaq 0x78(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xc9de0
movq 0x30(%rsp), %rdi
callq 0xcafc0
movl %eax, 0x3c(%rsp)
jmp 0x4aabe
movl 0x3c(%rsp), %eax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %edx
movl %edx, %ecx
incl %ecx
movl %edx, %eax
movslq %ecx, %rcx
imulq $0x55555556, %rcx, %rdx # imm = 0x55555556
movq %rdx, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %edx
negl %edx
movl %edx, %ecx
leal 0x1(%rax,%rcx), %esi
leaq 0x78(%rsp), %rdi
callq 0x456f0
movsd %xmm0, 0x20(%rsp)
jmp 0x4ab06
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0x74(%rsp), %edx
movl %edx, %ecx
addl $0x2, %ecx
movl %edx, %eax
movslq %ecx, %rcx
imulq $0x55555556, %rcx, %rdx # imm = 0x55555556
movq %rdx, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %edx
negl %edx
movl %edx, %ecx
leal 0x2(%rax,%rcx), %esi
leaq 0x78(%rsp), %rdi
callq 0x456f0
movsd %xmm0, 0x18(%rsp)
jmp 0x4ab53
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x58(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4ab9d
movq 0x28(%rsp), %rax
cvtsi2sdl 0x8(%rax), %xmm0
divsd 0x48(%rsp), %xmm0
callq 0x13420
movsd %xmm0, 0x10(%rsp)
jmp 0x4aba8
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x4aba8
movq 0x28(%rsp), %rax
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x80(%rax)
addq $0x88, %rax
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x1b970
jmp 0x4abd7
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x1c2d0
jmp 0x4abe8
leaq 0x78(%rsp), %rdi
callq 0x1b990
addq $0xb8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x1b990
movq 0x68(%rsp), %rdi
callq 0x13970
nopl (%rax)