// File: tomfunkhouser[P]gaps/pkgs/R3Surfels/R3SurfelObject.cpp
// Function: gaps::R3SurfelObject::SetParent(gaps::R3SurfelObject*)
void R3SurfelObject::
SetParent(R3SurfelObject *parent)
{
  // Just checking
  // assert(parent);
  // assert(this->parent);
  assert(!this->parent || (scene == this->parent->scene));
  assert(!parent || !this->parent || (parent->scene == this->parent->scene));
  if (parent == this->parent) return;

  // Invalidate bounding boxes starting at current parent
  R3SurfelObject *ancestor = this->parent;
  while (ancestor) {
    if (ancestor->bbox[0][0] == FLT_MAX) break;
    ancestor->bbox[0][0] = FLT_MAX;
    ancestor = ancestor->parent;
  }

  // Invalidate timestamps starting at current parent
  ancestor = this->parent;
  while (ancestor) {
    if (ancestor->timestamp_range[0] == FLT_MAX) break;
    ancestor->timestamp_range[0] = FLT_MAX;
    ancestor = ancestor->parent;
  }

  // Invalidate bounding boxes starting at new parent
  ancestor = parent;
  while (ancestor) {
    if (ancestor->bbox[0][0] == FLT_MAX) break;
    ancestor->bbox[0][0] = FLT_MAX;
    ancestor = ancestor->parent;
  }

  // Invalidate timestamp ranges starting at new parent
  ancestor = parent;
  while (ancestor) {
    if (ancestor->timestamp_range[0] == FLT_MAX) break;
    ancestor->timestamp_range[0] = FLT_MAX;
    ancestor = ancestor->parent;
  }

  // Update hierarchy
  if (this->parent) this->parent->parts.Remove(this);
  if (parent) parent->parts.Insert(this);
  this->parent = parent;

  // Mark scene as dirty
  if (scene) scene->SetDirty();
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x20(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x18(%rcx), %rax
jne 0x1a838
jmp 0x1aa6c
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x1a8ba
movq 0x10(%rsp), %rdi
addq $0xa0, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movsd (%rax), %xmm0
movsd 0x189919(%rip), %xmm1   # 0x1a4190
ucomisd %xmm1, %xmm0
jne 0x1a881
jp 0x1a881
jmp 0x1a8ba
movq 0x10(%rsp), %rdi
addq $0xa0, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movsd 0x1898ea(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x1a846
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x1a928
movq 0x10(%rsp), %rdi
addq $0xd8, %rdi
xorl %esi, %esi
callq 0x1be00
movsd (%rax), %xmm0
movsd 0x1898a1(%rip), %xmm1   # 0x1a4190
ucomisd %xmm1, %xmm0
jne 0x1a8f9
jp 0x1a8f9
jmp 0x1a928
movq 0x10(%rsp), %rdi
addq $0xd8, %rdi
xorl %esi, %esi
callq 0x1be00
movsd 0x18987c(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x1a8c8
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x1a9a6
movq 0x10(%rsp), %rdi
addq $0xa0, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movsd (%rax), %xmm0
movsd 0x18982d(%rip), %xmm1   # 0x1a4190
ucomisd %xmm1, %xmm0
jne 0x1a96d
jp 0x1a96d
jmp 0x1a9a6
movq 0x10(%rsp), %rdi
addq $0xa0, %rdi
xorl %esi, %esi
callq 0x1bda0
movq %rax, %rdi
xorl %esi, %esi
callq 0x1bde0
movsd 0x1897fe(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x1a932
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x1aa10
movq 0x10(%rsp), %rdi
addq $0xd8, %rdi
xorl %esi, %esi
callq 0x1be00
movsd (%rax), %xmm0
movsd 0x1897b9(%rip), %xmm1   # 0x1a4190
ucomisd %xmm1, %xmm0
jne 0x1a9e1
jp 0x1a9e1
jmp 0x1aa10
movq 0x10(%rsp), %rdi
addq $0xd8, %rdi
xorl %esi, %esi
callq 0x1be00
movsd 0x189794(%rip), %xmm0   # 0x1a4190
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x1a9b0
movq 0x8(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1aa2e
movq 0x8(%rsp), %rsi
movq 0x18(%rsi), %rdi
addq $0x20, %rdi
callq 0x1be40
cmpq $0x0, 0x18(%rsp)
je 0x1aa49
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdi
addq $0x20, %rdi
callq 0x1be70
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x8(%rax)
je 0x1aa6c
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1bea0
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)