// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::RGBDSurface(char const*, gaps::R3Mesh*, double)
RGBDSurface::
RGBDSurface(const char *texture_filename, R3Mesh *mesh, RNLength texel_spacing)
  : configuration(NULL),
    configuration_index(-1),
    channels(),
    width(0), height(0),
    opengl_texture_id(-1),
    texture_filename(NULL),
    mesh_filename(NULL),
    surface_bbox(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX),
    color_resident_count(0),
    data(NULL),
    rectangle(NULL),
    mesh(mesh),
    mesh_face_index(NULL),
    thickness(0)
{
  // Check mesh
  if (mesh->NFaces() == 0) return;
  RNArea mesh_area = mesh->Area();
  if (RNIsZero(mesh_area)) {
    RNFail("Warning: RGBDSurface mesh has zero area\n");
    return;
  }

  // Compute bounding box of surface coordinates
  for (int i = 0; i < mesh->NVertices(); i++) {
    R3MeshVertex *vertex = mesh->Vertex(i);
    const R2Point& texcoords = mesh->VertexTextureCoords(vertex);
    surface_bbox.Union(texcoords);
  }

  // Check surface_bbox
  if (RNIsZero(surface_bbox.Area())) {
    // RNFail("Warning: RGBDSurface mesh does not have valid texture coordinates\n");
    surface_bbox.Reset(R2zero_point, R2ones_point);
  }

  // Compute width and height from texel_spacing
  if (texel_spacing <= 0) texel_spacing = 0.01;
  width = (int) (surface_bbox.XLength() / texel_spacing + 0.5);
  height = (int) (surface_bbox.YLength() / texel_spacing + 0.5);
  if (width <= 0) width = 1;
  if (height <= 0) height = 1;

  // Set texture filename
  SetTextureFilename(texture_filename);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movaps %xmm0, 0x10(%rsp)
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r12
leaq 0xe5257(%rip), %rax     # 0xffdb8
movq %rax, (%rdi)
xorl %r14d, %r14d
movq %r14, 0x8(%rdi)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, 0x10(%rdi)
addq $0x18, %rdi
movq %rdi, 0x8(%rsp)
callq 0x753d0
movq %r14, 0x28(%r12)
movl %ebp, 0x30(%r12)
leaq 0x48(%r12), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r12)
movsd 0xa048f(%rip), %xmm0    # 0xbb030
movsd 0xa0497(%rip), %xmm2    # 0xbb040
movq %r14, %rdi
movapd %xmm0, %xmm1
movapd %xmm2, %xmm3
callq 0x6c3cc
movl $0x0, 0x70(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x78(%r12)
movq %r13, 0x88(%r12)
movupd %xmm0, 0x90(%r12)
cmpl $0x0, 0x34(%r13)
je 0x1ad19
movq %r13, %rdi
callq 0x2bac2
leaq 0xea0df(%rip), %rbp     # 0x104cd8
movsd (%rbp), %xmm1
movapd 0xa044a(%rip), %xmm2    # 0xbb050
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x1ac29
ucomisd %xmm0, %xmm1
jb 0x1ac29
leaq 0xa12c8(%rip), %rdi     # 0xbbee5
xorl %eax, %eax
callq 0x77f42
jmp 0x1ad19
cmpl $0x0, 0x14(%r13)
jle 0x1ac53
xorl %r15d, %r15d
movq 0x8(%r13), %rax
movq (%rax,%r15,8), %rsi
addq $0x48, %rsi
movq %r14, %rdi
callq 0x6c9b6
incq %r15
movslq 0x14(%r13), %rax
cmpq %rax, %r15
jl 0x1ac33
movq %r14, %rdi
callq 0x6c7d2
movsd (%rbp), %xmm1
movapd 0xa03e8(%rip), %xmm2    # 0xbb050
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x1ac8e
ucomisd %xmm0, %xmm1
jb 0x1ac8e
leaq 0xec7c1(%rip), %rsi     # 0x107440
leaq 0xec7ca(%rip), %rdx     # 0x107450
movq %r14, %rdi
callq 0x6cbec
xorpd %xmm0, %xmm0
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm1
cmpnlesd %xmm0, %xmm1
andpd %xmm1, %xmm2
movsd 0xa0803(%rip), %xmm0    # 0xbb4b0
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movupd 0x50(%r12), %xmm0
movupd 0x60(%r12), %xmm2
subpd %xmm0, %xmm2
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm2
addpd 0xa11c9(%rip), %xmm2    # 0xbbea0
cvttpd2dq %xmm2, %xmm0
movd %xmm0, %eax
movq %xmm0, 0x28(%r12)
testl %eax, %eax
jg 0x1acf3
movl $0x1, 0x28(%r12)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
testl %eax, %eax
jg 0x1ad09
movl $0x1, 0x2c(%r12)
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
callq *0xc0(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x1ad3a
jmp 0x1ad2f
movq %rax, %r15
movq %r14, %rdi
callq 0x6cc44
movq 0x8(%rsp), %rdi
callq 0x7543a
movq %r15, %rdi
callq 0x11a60