// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::RGBDSurface(char const*, gaps::R3Rectangle*, double)
RGBDSurface::
RGBDSurface(const char *texture_filename, R3Rectangle *rectangle, 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(rectangle),
    mesh(NULL),
    mesh_face_index(NULL),
    thickness(0)
{
  // Check rectangle
  if (!rectangle) return;
  
  // Set texture filename
  SetTextureFilename(texture_filename);

  // Compute coordinate stuff
  RNLength xlength = 2*rectangle->Radius(0);
  RNLength ylength = 2*rectangle->Radius(1);
  if (texel_spacing <= 0) texel_spacing = 0.01;
  width = (int) (xlength / texel_spacing + 0.5);
  height = (int) (ylength / texel_spacing + 0.5);
  if (width <= 0) width = 1;
  if (height <= 0) height = 1;

  // Compute bounding box of surface coordinates
  surface_bbox.Reset(R2zero_point, R2Point(xlength, ylength));
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdx, 0x70(%rsp)
movsd %xmm0, 0x68(%rsp)
movq 0x80(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x189075(%rip), %rax    # 0x1acd88
movq %rax, (%rdi)
movq $0x0, 0x8(%rdi)
movl $0xffffffff, 0x10(%rdi) # imm = 0xFFFFFFFF
addq $0x18, %rdi
movq %rdi, 0x20(%rsp)
callq 0x27780
movq 0x28(%rsp), %rdi
movl $0x0, 0x28(%rdi)
movl $0x0, 0x2c(%rdi)
movl $0xffffffff, 0x30(%rdi) # imm = 0xFFFFFFFF
movq $0x0, 0x38(%rdi)
movq $0x0, 0x40(%rdi)
addq $0x48, %rdi
movq %rdi, 0x30(%rsp)
movsd 0x14229a(%rip), %xmm1   # 0x166008
movsd 0x14229a(%rip), %xmm3   # 0x166010
movaps %xmm1, %xmm0
movaps %xmm3, %xmm2
callq 0xca300
jmp 0x23d83
movq 0x28(%rsp), %rax
movl $0x0, 0x70(%rax)
movq $0x0, 0x78(%rax)
movq 0x70(%rsp), %rcx
movq %rcx, 0x80(%rax)
movq $0x0, 0x88(%rax)
movq $0x0, 0x90(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x98(%rax)
cmpq $0x0, 0x70(%rsp)
jne 0x23de4
jmp 0x23f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
jmp 0x23f39
movq 0x28(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq (%rdi), %rax
movq 0xc0(%rax), %rax
callq *%rax
jmp 0x23dfc
movq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x22630
movsd %xmm0, 0x18(%rsp)
jmp 0x23e10
movsd 0x18(%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x22630
movsd %xmm0, 0x10(%rsp)
jmp 0x23e37
movsd 0x10(%rsp), %xmm1
movsd 0x142713(%rip), %xmm0   # 0x166558
mulsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x68(%rsp), %xmm0
jb 0x23e87
movsd 0x14301e(%rip), %xmm0   # 0x166e80
movsd %xmm0, 0x68(%rsp)
jmp 0x23e87
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
callq 0x1a200
jmp 0x23f39
movq 0x28(%rsp), %rax
movsd 0x50(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
movsd 0x142188(%rip), %xmm1   # 0x166028
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x28(%rax)
movsd 0x48(%rsp), %xmm0
divsd 0x68(%rsp), %xmm0
movsd 0x142169(%rip), %xmm1   # 0x166028
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x2c(%rax)
cmpl $0x0, 0x28(%rax)
jg 0x23edc
movq 0x28(%rsp), %rax
movl $0x1, 0x28(%rax)
movq 0x28(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
jg 0x23ef3
movq 0x28(%rsp), %rax
movl $0x1, 0x2c(%rax)
movq 0x28(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x8(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
leaq 0x38(%rsp), %rdi
callq 0xcfd80
jmp 0x23f19
movq 0x8(%rsp), %rdi
leaq 0x190963(%rip), %rsi    # 0x1b4888
leaq 0x38(%rsp), %rdx
callq 0xcb730
jmp 0x23f31
addq $0x88, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x27790
movq 0x60(%rsp), %rdi
callq 0x12c20
nopl (%rax)