// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::UpdateMeshFaceIndex()
void RGBDSurface::
UpdateMeshFaceIndex(void)
{
  // Check everything
  if (!mesh) return;
  if (width == 0) return;
  if (height == 0) return;
  if (RNIsZero(surface_bbox.Area())) return;
  
  // Create face index
  mesh_face_index = new R2Grid(width, height, surface_bbox);

  // Update mesh face index grid
  mesh_face_index->Clear(R2_GRID_UNKNOWN_VALUE);
  for (int i = 0; i < mesh->NFaces(); i++) {
    R3MeshFace *face = mesh->Face(i);
    R3MeshVertex *v0 = mesh->VertexOnFace(face, 0);
    R3MeshVertex *v1 = mesh->VertexOnFace(face, 1);
    R3MeshVertex *v2 = mesh->VertexOnFace(face, 2);
    R2Point s0 = mesh->VertexTextureCoords(v0);
    R2Point s1 = mesh->VertexTextureCoords(v1);
    R2Point s2 = mesh->VertexTextureCoords(v2);
    mesh_face_index->RasterizeWorldTriangle(s0, s1, s2, i, R2_GRID_REPLACE_OPERATION);
  }

  // For debugging
  // mesh_face_index->WriteFile("mesh_face_index.pfm");
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x88(%rax)
jne 0x274eb
jmp 0x276f9
movq 0x18(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jne 0x274fb
jmp 0x276f9
movq 0x18(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x2750b
jmp 0x276f9
movq 0x18(%rsp), %rdi
addq $0x48, %rdi
callq 0xcaf70
leaq 0x18a9a0(%rip), %rax    # 0x1b1ec0
movsd (%rax), %xmm1
callq 0x1a370
cmpl $0x0, %eax
je 0x27533
jmp 0x276f9
movl $0xd0, %edi
callq 0x126d0
movq 0x18(%rsp), %rcx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
movl 0x28(%rcx), %esi
movl 0x2c(%rcx), %edx
addq $0x48, %rcx
callq 0xb2080
jmp 0x2755e
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x90(%rax)
movq 0x90(%rax), %rdi
movsd 0x13eaa2(%rip), %xmm0   # 0x166020
callq 0xb5a20
movl $0x0, 0x70(%rsp)
movq 0x18(%rsp), %rax
movl 0x70(%rsp), %ecx
movl %ecx, 0xc(%rsp)
movq 0x88(%rax), %rdi
callq 0x19f00
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x276f9
movq 0x18(%rsp), %rax
movq 0x88(%rax), %rdi
movl 0x70(%rsp), %esi
callq 0x22bb0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x68(%rsp)
movq 0x88(%rax), %rdi
movq 0x68(%rsp), %rsi
xorl %edx, %edx
callq 0x22be0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x60(%rsp)
movq 0x88(%rax), %rdi
movq 0x68(%rsp), %rsi
movl $0x1, %edx
callq 0x22be0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x58(%rsp)
movq 0x88(%rax), %rdi
movq 0x68(%rsp), %rsi
movl $0x2, %edx
callq 0x22be0
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x50(%rsp)
movq 0x88(%rax), %rdi
movq 0x60(%rsp), %rsi
callq 0x22b90
movq %rax, %rsi
leaq 0x40(%rsp), %rdi
callq 0xcfdb0
movq 0x18(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x58(%rsp), %rsi
callq 0x22b90
movq %rax, %rsi
leaq 0x30(%rsp), %rdi
callq 0xcfdb0
movq 0x18(%rsp), %rax
movq 0x88(%rax), %rdi
movq 0x50(%rsp), %rsi
callq 0x22b90
movq %rax, %rsi
leaq 0x20(%rsp), %rdi
callq 0xcfdb0
movq 0x18(%rsp), %rax
movq 0x90(%rax), %rdi
cvtsi2sdl 0x70(%rsp), %xmm0
leaq 0x40(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movl $0x2, %r8d
callq 0x28000
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x2758b
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
movl $0xd0, %esi
callq 0x126e0
jmp 0x27701
addq $0x88, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x12c20
nopl (%rax,%rax)