// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelConstraint.cpp
// Function: gaps::R3SurfelViewConstraint::R3SurfelViewConstraint(gaps::R3SurfelImage const&, double, double, gaps::R2Grid const*, int)
R3SurfelViewConstraint::
R3SurfelViewConstraint(
  const R3SurfelImage& image,
  RNLength neardist, RNLength fardist, 
  const R2Grid *image_mask,
  RNBoolean must_be_inside_frustum)
  : frustum(image.Frustum()),
    world_to_camera(image.Extrinsics()),
    w(image.ImageWidth()), h(image.ImageHeight()),
    fx(image.XFocal()), fy(image.YFocal()),
    cx(image.ImageCenter().X()), cy(image.ImageCenter().Y()),
    neardist(neardist), fardist(fardist),
    image_mask(image_mask),
    must_be_inside_frustum(must_be_inside_frustum)
{
  // Compute default image center
  if (this->cx <= 0) this->cx = 0.5*w;
  if (this->cy <= 0) this->cy = 0.5*h;

  // Compute default near and far distances
  if (this->neardist <= 0) this->neardist = RN_EPSILON;
  if (this->fardist <= 0) this->fardist = RN_INFINITY;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movsd %xmm0, 0xb0(%rsp)
movsd %xmm1, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movl %ecx, 0x9c(%rsp)
movq 0xc0(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x50470
movq 0x78(%rsp), %rdi
leaq 0x19b9d2(%rip), %rax    # 0x1ee3b8
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, 0x80(%rsp)
movq 0xb8(%rsp), %rsi
leaq 0x1a9b44(%rip), %rax    # 0x1fc548
movsd (%rax), %xmm0
leaq 0x1a9b49(%rip), %rax    # 0x1fc558
movsd (%rax), %xmm1
callq 0x54b60
jmp 0x52a1a
movq 0x78(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
movq 0xb8(%rsp), %rsi
callq 0x54c10
jmp 0x52a35
movq 0x78(%rsp), %rax
addq $0x1d0, %rax            # imm = 0x1D0
movq %rax, 0x68(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x308f0
movl %eax, 0x74(%rsp)
jmp 0x52a58
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
movl 0x74(%rsp), %edx
movl %edx, (%rcx)
addq $0x1d4, %rax            # imm = 0x1D4
movq %rax, 0x58(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x30920
movl %eax, 0x64(%rsp)
jmp 0x52a86
movq 0x78(%rsp), %rax
movq 0x58(%rsp), %rcx
movl 0x64(%rsp), %edx
movl %edx, (%rcx)
addq $0x1d8, %rax            # imm = 0x1D8
movq %rax, 0x48(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x31540
movsd %xmm0, 0x50(%rsp)
jmp 0x52ab6
movq 0x78(%rsp), %rax
movq 0x48(%rsp), %rcx
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rcx)
addq $0x1e0, %rax            # imm = 0x1E0
movq %rax, 0x38(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x31560
movsd %xmm0, 0x40(%rsp)
jmp 0x52aea
movq 0x78(%rsp), %rax
movq 0x38(%rsp), %rcx
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rcx)
addq $0x1e8, %rax            # imm = 0x1E8
movq %rax, 0x28(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x31580
movq %rax, 0x30(%rsp)
jmp 0x52b1d
movq 0x30(%rsp), %rdi
callq 0x308e0
movsd %xmm0, 0x20(%rsp)
jmp 0x52b2f
movq 0x78(%rsp), %rax
movq 0x28(%rsp), %rcx
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rcx)
addq $0x1f0, %rax            # imm = 0x1F0
movq %rax, 0x10(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x31580
movq %rax, 0x18(%rsp)
jmp 0x52b62
movq 0x18(%rsp), %rdi
callq 0x30910
movsd %xmm0, 0x8(%rsp)
jmp 0x52b74
movq 0x78(%rsp), %rax
movq 0x10(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rcx)
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, 0x1f8(%rax)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x200(%rax)
movq 0xa0(%rsp), %rcx
movq %rcx, 0x208(%rax)
movl 0x9c(%rsp), %ecx
movl %ecx, 0x210(%rax)
xorps %xmm0, %xmm0
ucomisd 0x1e8(%rax), %xmm0
jb 0x52c35
movq 0x78(%rsp), %rax
cvtsi2sdl 0x1d0(%rax), %xmm1
movsd 0x151570(%rip), %xmm0   # 0x1a4158
mulsd %xmm1, %xmm0
movsd %xmm0, 0x1e8(%rax)
jmp 0x52c35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0x52cc4
movq 0x80(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
callq 0x54b50
jmp 0x52cc4
movq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
ucomisd 0x1f0(%rax), %xmm0
jb 0x52c68
movq 0x78(%rsp), %rax
cvtsi2sdl 0x1d4(%rax), %xmm1
movsd 0x1514fc(%rip), %xmm0   # 0x1a4158
mulsd %xmm1, %xmm0
movsd %xmm0, 0x1f0(%rax)
movq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
ucomisd 0x1f8(%rax), %xmm0
jb 0x52c92
movq 0x78(%rsp), %rax
leaq 0x1a98c2(%rip), %rcx    # 0x1fc548
movsd (%rcx), %xmm0
movsd %xmm0, 0x1f8(%rax)
movq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
ucomisd 0x200(%rax), %xmm0
jb 0x52cbc
movq 0x78(%rsp), %rax
leaq 0x1a98a8(%rip), %rcx    # 0x1fc558
movsd (%rcx), %xmm0
movsd %xmm0, 0x200(%rax)
addq $0xc8, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x50490
movq 0x90(%rsp), %rdi
callq 0x13970
nopl (%rax,%rax)