// File: /workspace/github_cpp_makefile_star2_O2/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 0xd911f(%rip), %rax     # 0xf2dd8
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
orl $-0x1, 0x10(%rdi)
addq $0x18, %rdi
movq %rdi, 0x8(%rsp)
callq 0x6c0ba
andq $0x0, 0x28(%r12)
orl $-0x1, 0x30(%r12)
leaq 0x48(%r12), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r12)
movsd 0x8e32b(%rip), %xmm0    # 0xa8020
movsd 0x8e343(%rip), %xmm2    # 0xa8040
movq %r14, %rdi
movapd %xmm0, %xmm1
movapd %xmm2, %xmm3
callq 0x63c42
andl $0x0, 0x70(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x78(%r12)
movq %r13, 0x88(%r12)
movupd %xmm0, 0x90(%r12)
cmpl $0x0, 0x34(%r13)
je 0x19e65
movq %r13, %rdi
callq 0x29102
leaq 0xddfae(%rip), %rbp     # 0xf7cf8
movsd (%rbp), %xmm1
movapd 0x8e2f9(%rip), %xmm2    # 0xa8050
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x19d7a
ucomisd %xmm0, %xmm1
jb 0x19d7a
leaq 0x8f0f7(%rip), %rdi     # 0xa8e65
xorl %eax, %eax
callq 0x6e732
jmp 0x19e65
xorl %r15d, %r15d
movslq 0x14(%r13), %rax
cmpq %rax, %r15
jge 0x19d9f
movq 0x8(%r13), %rax
movq (%rax,%r15,8), %rsi
addq $0x48, %rsi
movq %r14, %rdi
callq 0x64150
incq %r15
jmp 0x19d7d
movq %r14, %rdi
callq 0x63ff8
movsd (%rbp), %xmm1
movapd 0x8e29c(%rip), %xmm2    # 0xa8050
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x19dda
ucomisd %xmm0, %xmm1
jb 0x19dda
leaq 0xe0695(%rip), %rsi     # 0xfa460
leaq 0xe069e(%rip), %rdx     # 0xfa470
movq %r14, %rdi
callq 0x64352
xorpd %xmm0, %xmm0
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm1
cmpnlesd %xmm0, %xmm1
andpd %xmm1, %xmm2
movsd 0x8e6b7(%rip), %xmm0    # 0xa84b0
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 0x8effd(%rip), %xmm2    # 0xa8e20
cvttpd2dq %xmm2, %xmm0
movd %xmm0, %eax
movq %xmm0, 0x28(%r12)
testl %eax, %eax
jg 0x19e3f
movl $0x1, 0x28(%r12)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
testl %eax, %eax
jg 0x19e55
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 0x19e86
jmp 0x19e7b
movq %rax, %r15
movq %r14, %rdi
callq 0x643b6
movq 0x8(%rsp), %rdi
callq 0x6c128
movq %r15, %rdi
callq 0x11a80