// File: /workspace/github_cpp_makefile_star2_O1/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 0xe6f93(%rip), %rax     # 0x101db8
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 0x76214
movq %r14, 0x28(%r12)
movl %ebp, 0x30(%r12)
leaq 0x48(%r12), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r12)
movsd 0xa21cb(%rip), %xmm0    # 0xbd030
movsd 0xa21d3(%rip), %xmm2    # 0xbd040
movq %r14, %rdi
movapd %xmm0, %xmm1
movapd %xmm2, %xmm3
callq 0x6d1d4
movl $0x0, 0x70(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x78(%r12)
movq %r13, 0x88(%r12)
movupd %xmm0, 0x90(%r12)
cmpl $0x0, 0x34(%r13)
je 0x1afdd
movq %r13, %rdi
callq 0x2c0d8
leaq 0xebe2b(%rip), %rbp     # 0x106ce8
movsd (%rbp), %xmm1
movapd 0xa2186(%rip), %xmm2    # 0xbd050
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x1aeed
ucomisd %xmm0, %xmm1
jb 0x1aeed
leaq 0xa3004(%rip), %rdi     # 0xbdee5
xorl %eax, %eax
callq 0x79092
jmp 0x1afdd
cmpl $0x0, 0x14(%r13)
jle 0x1af17
xorl %r15d, %r15d
movq 0x8(%r13), %rax
movq (%rax,%r15,8), %rsi
addq $0x48, %rsi
movq %r14, %rdi
callq 0x6d7cc
incq %r15
movslq 0x14(%r13), %rax
cmpq %rax, %r15
jl 0x1aef7
movq %r14, %rdi
callq 0x6d5e8
movsd (%rbp), %xmm1
movapd 0xa2124(%rip), %xmm2    # 0xbd050
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x1af52
ucomisd %xmm0, %xmm1
jb 0x1af52
leaq 0xee50d(%rip), %rsi     # 0x109450
leaq 0xee516(%rip), %rdx     # 0x109460
movq %r14, %rdi
callq 0x6d9fe
xorpd %xmm0, %xmm0
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm1
cmpnlesd %xmm0, %xmm1
andpd %xmm1, %xmm2
movsd 0xa253f(%rip), %xmm0    # 0xbd4b0
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 0xa2f05(%rip), %xmm2    # 0xbdea0
cvttpd2dq %xmm2, %xmm0
movd %xmm0, %eax
movq %xmm0, 0x28(%r12)
testl %eax, %eax
jg 0x1afb7
movl $0x1, 0x28(%r12)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
testl %eax, %eax
jg 0x1afcd
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 0x1affe
jmp 0x1aff3
movq %rax, %r15
movq %r14, %rdi
callq 0x6da54
movq 0x8(%rsp), %rdi
callq 0x7627e
movq %r15, %rdi
callq 0x11a70