// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDImage.cpp
// Function: gaps::RGBDImage::WorldBBox() const
R3Box RGBDImage::
WorldBBox(void) const
{
  // Return remembered bounding box of points in world coordinates, if valid
  if (!world_bbox.IsEmpty()) return world_bbox;

  // Compute world bounding box
  R3Box b = R3null_box;
  if (DepthChannel()) {
    // Compute world bounding box of points
    int skip = 1;
    b = R3null_box;
    for (int iy = 0; iy < height; iy += skip) {
      for (int ix = 0; ix < width; ix += skip) {
        R3Point world_position;
        R2Point image_position(ix+0.5, iy+0.5);
        if (RGBDTransformImageToWorld(image_position, world_position, this)) {
          b.Union(world_position);
        }
      }
    }

    // Just so that don't compute again if empty
    if (b.IsEmpty()) b.Union(WorldViewpoint());

    // Remember world bounding box
    ((RGBDImage *) this)->world_bbox = b;
  }
  else {
    // Return conservative bounding box without reading image
    RNLength max_depth = 7.0;
    RNScalar xfocal = Intrinsics()[0][0];
    RNScalar yfocal = Intrinsics()[1][1];
    RNScalar tan_xfov = (xfocal > 0) ? 0.5*NPixels(RN_X) / xfocal : 1.0;
    RNScalar tan_yfov = (yfocal > 0) ? 0.5*NPixels(RN_Y) / yfocal : 1.0;
    R3Point c = WorldViewpoint() + max_depth * WorldTowards();
    R3Vector dx = WorldRight() * max_depth * tan_xfov * WorldRight();
    R3Vector dy = WorldRight() * max_depth * tan_yfov * WorldUp();
    b.Union(WorldViewpoint());
    b.Union(c - dx - dy);
    b.Union(c + dx - dy);
    b.Union(c - dx + dy);
    b.Union(c + dx + dy);
  }

  // Return computed bounding box
  return b;
}

// Assembly:
subq $0x338, %rsp            # imm = 0x338
movq %rdi, 0x60(%rsp)
movq %rdi, %rax
movq %rax, 0x68(%rsp)
movq %rdi, 0x330(%rsp)
movq %rsi, 0x328(%rsp)
movq 0x328(%rsp), %rdi
movq %rdi, 0x70(%rsp)
addq $0x188, %rdi            # imm = 0x188
callq 0x19cf0
cmpl $0x0, %eax
jne 0x28dcd
movq 0x60(%rsp), %rdi
movq 0x70(%rsp), %rsi
addq $0x188, %rsi            # imm = 0x188
callq 0x75370
jmp 0x293fe
movq 0x60(%rsp), %rdi
movb $0x0, 0x327(%rsp)
leaq 0x189747(%rip), %rsi    # 0x1b2528
callq 0x75370
movq 0x70(%rsp), %rdi
callq 0x303c0
movq %rax, 0x58(%rsp)
jmp 0x28df7
movq 0x58(%rsp), %rax
cmpq $0x0, %rax
je 0x28f9e
movq 0x60(%rsp), %rdi
movl $0x1, 0x310(%rsp)
leaq 0x18970b(%rip), %rsi    # 0x1b2528
callq 0x22c20
jmp 0x28e24
movl $0x0, 0x30c(%rsp)
movq 0x70(%rsp), %rcx
movl 0x30c(%rsp), %eax
cmpl 0x2c(%rcx), %eax
jge 0x28f3e
movl $0x0, 0x308(%rsp)
movq 0x70(%rsp), %rcx
movl 0x308(%rsp), %eax
cmpl 0x28(%rcx), %eax
jge 0x28f22
leaq 0x2f0(%rsp), %rdi
callq 0x8a990
jmp 0x28e73
cvtsi2sdl 0x308(%rsp), %xmm0
movsd 0x13d1a4(%rip), %xmm2   # 0x166028
addsd %xmm2, %xmm0
cvtsi2sdl 0x30c(%rsp), %xmm1
addsd %xmm2, %xmm1
leaq 0x2e0(%rsp), %rdi
callq 0xcfd80
jmp 0x28ea4
movq 0x70(%rsp), %rdx
leaq 0x2e0(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x1ae00
movl %eax, 0x54(%rsp)
jmp 0x28ec4
movl 0x54(%rsp), %eax
cmpl $0x0, %eax
je 0x28f06
movq 0x60(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x76f60
jmp 0x28ee1
jmp 0x28f06
movq 0x60(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x318(%rsp)
movl %eax, 0x314(%rsp)
callq 0x19b90
jmp 0x2940b
jmp 0x28f08
movl 0x310(%rsp), %eax
addl 0x308(%rsp), %eax
movl %eax, 0x308(%rsp)
jmp 0x28e4f
jmp 0x28f24
movl 0x310(%rsp), %eax
addl 0x30c(%rsp), %eax
movl %eax, 0x30c(%rsp)
jmp 0x28e2f
movq 0x60(%rsp), %rdi
callq 0x19cf0
movl %eax, 0x50(%rsp)
jmp 0x28f4e
movl 0x50(%rsp), %eax
cmpl $0x0, %eax
je 0x28f81
movq 0x70(%rsp), %rsi
leaq 0x2c8(%rsp), %rdi
callq 0x19db0
jmp 0x28f6b
movq 0x60(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x76f60
jmp 0x28f7f
jmp 0x28f81
movq 0x60(%rsp), %rsi
movq 0x70(%rsp), %rdi
addq $0x188, %rdi            # imm = 0x188
callq 0x22c20
jmp 0x28f99
jmp 0x293e0
movq 0x70(%rsp), %rdi
movabsq $0x401c000000000000, %rax # imm = 0x401C000000000000
movq %rax, 0x2c0(%rsp)
callq 0x226a0
movq %rax, 0x48(%rsp)
jmp 0x28fc1
movq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x238a0
movq %rax, 0x40(%rsp)
jmp 0x28fd4
movq 0x70(%rsp), %rdi
movq 0x40(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x2b8(%rsp)
callq 0x226a0
movq %rax, 0x38(%rsp)
jmp 0x28ff7
movq 0x38(%rsp), %rdi
movl $0x1, %esi
callq 0x238a0
movq %rax, 0x30(%rsp)
jmp 0x2900d
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x2b0(%rsp)
movsd 0x2b8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x29069
movq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x1af30
movl %eax, 0x2c(%rsp)
jmp 0x29044
movl 0x2c(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x13cfd4(%rip), %xmm0   # 0x166028
mulsd %xmm1, %xmm0
divsd 0x2b8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x29079
movsd 0x13cfbf(%rip), %xmm0   # 0x166030
movsd %xmm0, 0x20(%rsp)
jmp 0x29079
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x2a8(%rsp)
movsd 0x2b0(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x290d4
movq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x1af30
movl %eax, 0x1c(%rsp)
jmp 0x290af
movl 0x1c(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x13cf69(%rip), %xmm0   # 0x166028
mulsd %xmm1, %xmm0
divsd 0x2b0(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x290e4
movsd 0x13cf54(%rip), %xmm0   # 0x166030
movsd %xmm0, 0x10(%rsp)
jmp 0x290e4
movq 0x70(%rsp), %rsi
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x2a0(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x19db0
jmp 0x29107
movq 0x70(%rsp), %rsi
movsd 0x2c0(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x1a320
jmp 0x2912a
movsd 0x8(%rsp), %xmm0
leaq 0x258(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x227f0
jmp 0x29147
leaq 0x288(%rsp), %rdi
leaq 0x270(%rsp), %rsi
leaq 0x258(%rsp), %rdx
callq 0x8af60
jmp 0x29166
movq 0x70(%rsp), %rsi
leaq 0x1e0(%rsp), %rdi
callq 0x303e0
jmp 0x2917a
movsd 0x2c0(%rsp), %xmm0
leaq 0x1f8(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x8c9d0
jmp 0x2919a
movsd 0x2a8(%rsp), %xmm0
leaq 0x210(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x8c9d0
jmp 0x291ba
movq 0x70(%rsp), %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x303e0
jmp 0x291ce
leaq 0x228(%rsp), %rdi
leaq 0x210(%rsp), %rsi
leaq 0x1c8(%rsp), %rdx
callq 0x8cf60
jmp 0x291ed
movq 0x70(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0x303e0
jmp 0x29201
movsd 0x2c0(%rsp), %xmm0
leaq 0x180(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x8c9d0
jmp 0x29221
movsd 0x2a0(%rsp), %xmm0
leaq 0x198(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x8c9d0
jmp 0x29241
movq 0x70(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x22a50
jmp 0x29255
leaq 0x1b0(%rsp), %rdi
leaq 0x198(%rsp), %rsi
leaq 0x150(%rsp), %rdx
callq 0x8cf60
jmp 0x29274
movq 0x70(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0x19db0
jmp 0x29288
movq 0x60(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x76f60
jmp 0x2929c
leaq 0x108(%rsp), %rdi
leaq 0x288(%rsp), %rsi
leaq 0x228(%rsp), %rdx
callq 0x8b900
jmp 0x292bb
leaq 0x120(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0x8b900
jmp 0x292da
movq 0x60(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x76f60
jmp 0x292ee
leaq 0xd8(%rsp), %rdi
leaq 0x288(%rsp), %rsi
leaq 0x228(%rsp), %rdx
callq 0x8af60
jmp 0x2930d
leaq 0xf0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0x8b900
jmp 0x2932c
movq 0x60(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x76f60
jmp 0x29340
leaq 0xa8(%rsp), %rdi
leaq 0x288(%rsp), %rsi
leaq 0x228(%rsp), %rdx
callq 0x8b900
jmp 0x2935f
leaq 0xc0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0x8af60
jmp 0x2937e
movq 0x60(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x76f60
jmp 0x29392
leaq 0x78(%rsp), %rdi
leaq 0x288(%rsp), %rsi
leaq 0x228(%rsp), %rdx
callq 0x8af60
jmp 0x293ae
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0x8af60
jmp 0x293ca
movq 0x60(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x76f60
jmp 0x293de
jmp 0x293e0
movb $0x1, 0x327(%rsp)
testb $0x1, 0x327(%rsp)
jne 0x293fc
movq 0x60(%rsp), %rdi
callq 0x19b90
jmp 0x293fe
movq 0x68(%rsp), %rax
addq $0x338, %rsp            # imm = 0x338
retq
movq 0x318(%rsp), %rdi
callq 0x12c20
nopl (%rax,%rax)