// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelConstraint.cpp
// Function: gaps::R3SurfelViewConstraint::R3SurfelViewConstraint(gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, int, int, double, double, double, double, double, double, gaps::R2Grid const*, int)
R3SurfelViewConstraint::
R3SurfelViewConstraint(const R3Point& world_viewpoint,
  const R3Vector& world_towards, const R3Vector& world_up,
  int w, int h, RNScalar fx, RNScalar fy, RNScalar cx, RNScalar cy,
  RNLength neardist, RNLength fardist, 
  const R2Grid *image_mask,
  RNBoolean must_be_inside_frustum)
  : frustum(world_viewpoint, world_towards, world_up, atan(0.5*w/fx), atan(0.5*h/fy), neardist, fardist),
    world_to_camera(),
    w(w), h(h),
    fx(fx), fy(fy),
    cx(cx), cy(cy),
    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;

  // Compute world_to_camera matrix
  R3CoordSystem cs(world_viewpoint, R3Triad(world_towards, world_up));
  world_to_camera = cs.InverseMatrix();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movsd %xmm5, 0x18(%rsp)
movsd %xmm4, 0x10(%rsp)
movsd %xmm3, 0x50(%rsp)
movsd %xmm2, 0x48(%rsp)
movsd %xmm1, 0x8(%rsp)
movapd %xmm0, %xmm1
movl %r9d, %ebx
movl %r8d, %r14d
movq %rcx, 0x60(%rsp)
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbp
leaq 0xfd104(%rip), %rax     # 0x12e3a8
movq %rax, (%rdi)
leaq 0x8(%rdi), %r13
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
mulsd 0xabe7d(%rip), %xmm0    # 0xdd138
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x40(%rsp)
divsd %xmm1, %xmm0
callq 0x13410
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movsd %xmm0, 0x58(%rsp)
mulsd 0xabe53(%rip), %xmm1    # 0xdd138
movsd %xmm1, 0x28(%rsp)
movapd %xmm1, %xmm0
divsd 0x8(%rsp), %xmm0
callq 0x13410
movapd %xmm0, %xmm1
movq %r13, 0x20(%rsp)
movq %r13, %rdi
movq %r15, 0x38(%rsp)
movq %r15, %rsi
movq 0x60(%rsp), %r15
movq %r12, %rdx
movq %r15, %rcx
movsd 0x58(%rsp), %xmm0
movsd 0x10(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
callq 0x6abf0
leaq 0x150(%rbp), %r13
movq %r13, %rdi
callq 0x7233c
movl 0x188(%rsp), %eax
movq 0x180(%rsp), %rcx
movl %r14d, 0x1d0(%rbp)
movl %ebx, 0x1d4(%rbp)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x1d8(%rbp)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rbp)
movsd 0x48(%rsp), %xmm4
movsd %xmm4, 0x1e8(%rbp)
movsd 0x50(%rsp), %xmm3
movsd %xmm3, 0x1f0(%rbp)
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x1f8(%rbp)
movsd 0x18(%rsp), %xmm2
movsd %xmm2, 0x200(%rbp)
movq %rcx, 0x208(%rbp)
movl %eax, 0x210(%rbp)
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
jb 0x313d4
movsd 0x30(%rsp), %xmm4
movsd %xmm4, 0x1e8(%rbp)
ucomisd %xmm3, %xmm0
jb 0x313e8
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x1f0(%rbp)
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x31405
leaq 0x10280f(%rip), %rax    # 0x133c08
movsd (%rax), %xmm1
movsd %xmm1, 0x1f8(%rbp)
ucomisd %xmm2, %xmm0
jb 0x3141e
leaq 0x102806(%rip), %rax    # 0x133c18
movsd (%rax), %xmm0
movsd %xmm0, 0x200(%rbp)
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x70ca6
leaq 0xe8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
movq 0x38(%rsp), %rsi
callq 0x707a8
leaq 0x68(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x70856
leaq 0x68(%rsp), %rsi
movq %r13, %rdi
callq 0x73f22
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3147a
jmp 0x3147a
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x6e174
movq %rbx, %rdi
callq 0x138b0
nop