// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelImage.cpp
// Function: gaps::R3SurfelImage::R3SurfelImage(gaps::R3SurfelImage const&)
R3SurfelImage::
R3SurfelImage(const R3SurfelImage& image)
  : scene(NULL),
    scene_index(-1),
    scan(NULL),
    channels(),
    pose(image.pose),
    timestamp(image.timestamp),
    image_width(image.image_width), 
    image_height(image.image_height),
    image_center(image.image_center),
    xfocal(image.xfocal),
    yfocal(image.yfocal),
    distortion_type(R3_SURFEL_NO_DISTORTION),
    name((image.name) ? RNStrdup(image.name) : NULL),
    flags(0),
    data(NULL)
{
  // Intialize distortion parameters
  radial_distortion[0] = image.radial_distortion[0];
  radial_distortion[1] = image.radial_distortion[1];
  radial_distortion[2] = image.radial_distortion[2];
  tangential_distortion[0] = image.tangential_distortion[0];
  tangential_distortion[1] = image.tangential_distortion[1];

  // Initialize rolling shutter pose parameters
  rolling_shutter_poses[0] = image.rolling_shutter_poses[0];
  rolling_shutter_poses[1] = image.rolling_shutter_poses[1];
  rolling_shutter_timestamps[0] = image.rolling_shutter_timestamps[0];
  rolling_shutter_timestamps[1] = image.rolling_shutter_timestamps[1];

  // Copy all channels
  for (int i = 0; i < image.channels.NEntries(); i++) {
    R2Grid *channel = image.channels.Kth(i);
    if (channel) channels.Insert(new R2Grid(*channel));
    else channels.Insert(NULL);
  }
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq 0x80(%rsp), %rdi
movq %rdi, 0x58(%rsp)
leaq 0x1878e8(%rip), %rax    # 0x1eec70
movq %rax, (%rdi)
movq $0x0, 0x8(%rdi)
movl $0xffffffff, 0x10(%rdi) # imm = 0xFFFFFFFF
movq $0x0, 0x18(%rdi)
addq $0x20, %rdi
movq %rdi, 0x50(%rsp)
callq 0x6b820
movq 0x58(%rsp), %rdi
addq $0x30, %rdi
movq 0x78(%rsp), %rsi
addq $0x30, %rsi
callq 0xd5530
jmp 0x673c9
movq 0x58(%rsp), %rdi
movq 0x78(%rsp), %rax
movsd 0x90(%rax), %xmm0
movsd %xmm0, 0x90(%rdi)
movq 0x78(%rsp), %rax
movl 0x98(%rax), %eax
movl %eax, 0x98(%rdi)
movq 0x78(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, 0x9c(%rdi)
addq $0xa0, %rdi
movq 0x78(%rsp), %rsi
addq $0xa0, %rsi
callq 0x133990
jmp 0x6741f
movq 0x58(%rsp), %rax
movq 0x78(%rsp), %rcx
movsd 0xb0(%rcx), %xmm0
movsd %xmm0, 0xb0(%rax)
movq 0x78(%rsp), %rcx
movsd 0xb8(%rcx), %xmm0
movsd %xmm0, 0xb8(%rax)
movl $0x0, 0xc0(%rax)
addq $0xf0, %rax
movq %rax, %rcx
addq $0xc0, %rcx
movq %rcx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xd5500
jmp 0x67483
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %rax
addq $0x60, %rax
cmpq %rcx, %rax
movq %rax, 0x48(%rsp)
jne 0x67472
movq 0x58(%rsp), %rax
addq $0x1c0, %rax            # imm = 0x1C0
movq %rax, 0x30(%rsp)
movq 0x78(%rsp), %rax
cmpq $0x0, 0x1c0(%rax)
je 0x674de
movq 0x78(%rsp), %rax
movq 0x1c0(%rax), %rdi
callq 0x1461b0
movq %rax, 0x28(%rsp)
jmp 0x674d2
movq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x674e7
xorl %eax, %eax
movq %rax, 0x20(%rsp)
jmp 0x674e7
movq 0x58(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, (%rax)
addq $0x1c8, %rdi            # imm = 0x1C8
xorl %eax, %eax
movl %eax, %esi
callq 0x1b970
jmp 0x6750b
movq 0x58(%rsp), %rdi
movq $0x0, 0x1d0(%rdi)
movq 0x78(%rsp), %rax
movsd 0xc8(%rax), %xmm0
movsd %xmm0, 0xc8(%rdi)
movq 0x78(%rsp), %rax
movsd 0xd0(%rax), %xmm0
movsd %xmm0, 0xd0(%rdi)
movq 0x78(%rsp), %rax
movsd 0xd8(%rax), %xmm0
movsd %xmm0, 0xd8(%rdi)
movq 0x78(%rsp), %rax
movsd 0xe0(%rax), %xmm0
movsd %xmm0, 0xe0(%rdi)
movq 0x78(%rsp), %rax
movsd 0xe8(%rax), %xmm0
movsd %xmm0, 0xe8(%rdi)
movq 0x78(%rsp), %rsi
addq $0xf0, %rsi
addq $0xf0, %rdi
callq 0x457f0
jmp 0x6759e
movq 0x58(%rsp), %rdi
movq 0x78(%rsp), %rsi
addq $0x150, %rsi            # imm = 0x150
addq $0x150, %rdi            # imm = 0x150
callq 0x457f0
jmp 0x675bd
movq 0x58(%rsp), %rax
movq 0x78(%rsp), %rcx
movsd 0x1b0(%rcx), %xmm0
movsd %xmm0, 0x1b0(%rax)
movq 0x78(%rsp), %rcx
movsd 0x1b8(%rcx), %xmm0
movsd %xmm0, 0x1b8(%rax)
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x78(%rsp), %rdi
addq $0x20, %rdi
callq 0x16d50
movl %eax, 0x1c(%rsp)
jmp 0x67610
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x676e3
movq 0x78(%rsp), %rdi
addq $0x20, %rdi
movl 0x68(%rsp), %esi
callq 0x6b840
movq %rax, 0x10(%rsp)
jmp 0x67639
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
cmpq $0x0, 0x60(%rsp)
je 0x676bb
movq 0x58(%rsp), %rax
addq $0x20, %rax
movq %rax, (%rsp)
movl $0xd0, %edi
callq 0x13570
movq %rax, 0x8(%rsp)
jmp 0x67669
movq 0x8(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x1124c0
jmp 0x6767a
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
callq 0x6b860
jmp 0x6768a
jmp 0x676d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x676eb
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
movl $0xd0, %esi
callq 0x13580
jmp 0x676eb
movq 0x58(%rsp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6b860
jmp 0x676cf
jmp 0x676d1
jmp 0x676d3
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x675f4
addq $0x88, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x6b830
movq 0x70(%rsp), %rdi
callq 0x13970
nop