// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/conf2img/RGBDSegmentation.cpp
// Function: gaps::RGBDCreateSegmentationChannel(gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Grid const&, gaps::R2Image const&, gaps::R2Grid&, gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, char const*)
int
RGBDCreateSegmentationChannel(const R2Grid& depth_image, 
  const R2Grid& px_image, const R2Grid& py_image, const R2Grid& pz_image, const R2Grid& boundary_image, 
  const R2Grid& nx_image, const R2Grid& ny_image, const R2Grid& nz_image, const R2Grid& radius_image, 
  const R2Image& color_image, R2Grid& output_segmentation_image,
  const R3Point& viewpoint, const R3Vector& towards, const R3Vector& up,
  const char *output_segmentation_filename = NULL)
{
  // Initialize segmentation image
  output_segmentation_image = depth_image;
  output_segmentation_image.Clear(R2_GRID_UNKNOWN_VALUE);
  
  // Create segmentation
  R3Segmentation *segmentation = RGBDCreateSegmentation(
    px_image, py_image, pz_image, nx_image, ny_image, nz_image, 
    depth_image, radius_image, boundary_image, color_image, 
    viewpoint, towards, up);

  // Check segmentation
  if (!segmentation) return 0;

  // Fill segmentation image
  for (int i = 0; i < segmentation->clusters.NEntries(); i++) {
    R3SegmentationCluster *cluster = segmentation->clusters.Kth(i);
    for (int j = 0; j < cluster->points.NEntries(); j++) {
      R3SegmentationPoint *point = cluster->points.Kth(j);
      if (RNIsNegativeOrZero(point->depth)) continue;
      if (point->data_index < 0) continue;
      if (point->data_index >= output_segmentation_image.NEntries()) continue;
      output_segmentation_image.SetGridValue(point->data_index, i+1);
    }
  }

  // Write segmentation file (this is a hack)
  if (output_segmentation_filename) {
    // if (!RGBDWriteSegmentation(segmentation, output_segmentation_filename)) return 0;
    if (!segmentation->WriteFile(output_segmentation_filename)) return 0;
  }
  
  // Delete segmentation
  delete segmentation;

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, 0x40(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movq 0x1a0(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9cf2e
movsd 0xd978c(%rip), %xmm0    # 0x105048
movq %rbx, %rdi
callq 0x9e73c
movl $0xe0, %ebx
movl $0xe0, %edi
callq 0x238d0
movq %rax, %r12
movq %rax, %rdi
callq 0x59db4
movq %r14, 0x8(%rsp)
movslq 0xcc(%r14), %r13
movq %r13, %rax
mulq %rbx
seto %cl
orq $0x8, %rax
movq $-0x1, %r14
testb %cl, %cl
cmoveq %rax, %r14
imulq $-0x77777777, %r13, %rax # imm = 0x88888889
shrq $0x20, %rax
addl %r13d, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0xe, %eax
addl %ecx, %eax
movq %r12, (%rsp)
movl %eax, 0x38(%r12)
movq %r14, %rdi
callq 0x23040
leaq 0x8(%rax), %r15
movq %r13, (%rax)
testq %r13, %r13
je 0x2b963
movq %rax, %r12
imulq $-0xe0, %r13, %rbp
xorl %ebx, %ebx
movq %r15, %r13
movq %r13, %rdi
callq 0x56d88
addq $-0xe0, %rbx
addq $0xe0, %r13
cmpq %rbx, %rbp
jne 0x2b948
movq (%rsp), %rdx
movq %r15, 0x28(%rdx)
movq 0x8(%rsp), %rax
movl 0xc0(%rax), %ecx
testl %ecx, %ecx
jle 0x2bb7d
leaq 0xdefb3(%rip), %rax     # 0x10a938
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x8(%rsp), %rax
movl 0xc4(%rax), %eax
xorl %r13d, %r13d
leaq 0x149704(%rip), %r15    # 0x1750a8
xorpd %xmm3, %xmm3
leaq 0x68(%rsp), %rbp
testl %eax, %eax
jle 0x2bb71
movsd (%r15), %xmm0
xorl %r14d, %r14d
movq 0x8(%rsp), %rsi
movl 0xc8(%rsi), %ecx
imull %r14d, %ecx
addl %r13d, %ecx
movslq %ecx, %rbx
movq 0xb8(%rsi), %rcx
movsd (%rcx,%rbx,8), %xmm1
ucomisd %xmm1, %xmm0
jae 0x2bb5a
imulq $0xe0, %rbx, %r12
movsd 0x14e169(%rip), %xmm2   # 0x179b60
addq 0x28(%rdx), %r12
ucomisd %xmm3, %xmm2
jbe 0x2ba0b
ucomisd %xmm2, %xmm1
ja 0x2bb5a
movsd %xmm1, (%r12)
movq 0x18(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x20(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0x28(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm2
movsd %xmm0, 0x8(%r12)
movsd %xmm1, 0x10(%r12)
movsd %xmm2, 0x18(%r12)
movq 0x40(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x180(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0x188(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm2
movsd %xmm0, 0x20(%r12)
movsd %xmm1, 0x28(%r12)
movsd %xmm2, 0x30(%r12)
movq 0x190(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x50(%r12)
movsd %xmm0, 0x58(%r12)
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x70(%r12)
movq %rbp, %rdi
movq 0x198(%rsp), %rsi
movl %r13d, %edx
movl %r14d, %ecx
callq 0xace7e
leaq 0x78(%r12), %rdi
movq %rbp, %rsi
callq 0xb2292
movq 0x30(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm0
addsd 0xd94fe(%rip), %xmm0    # 0x105018
cvttsd2si %xmm0, %rax
movl %eax, 0xa4(%r12)
movl %ebx, 0xd4(%r12)
movq (%rsp), %rax
movl 0xc(%rax), %edx
movq (%rsp), %rdi
movq %r12, %rsi
callq 0xb2422
xorpd %xmm3, %xmm3
movq (%rsp), %rdx
movsd (%r15), %xmm0
movq 0x8(%rsp), %rax
movl 0xc4(%rax), %eax
incl %r14d
cmpl %eax, %r14d
jl 0x2b9bd
movq 0x8(%rsp), %rcx
movl 0xc0(%rcx), %ecx
incl %r13d
cmpl %ecx, %r13d
jl 0x2b9ad
leaq 0x68(%rsp), %rdi
callq 0x56d88
movl $0x60, %edi
callq 0x238d0
movq %rax, %r14
movq %rax, %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
movl $0x8, %edx
callq 0x2bfd2
movq %r14, 0x10(%rbx)
cmpl $0x0, 0xc(%rbx)
jle 0x2be45
movq %rbx, %rcx
leaq 0xded88(%rip), %rax     # 0x10a948
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %edx, %edx
xorpd %xmm2, %xmm2
movq (%rcx), %rax
movq %rdx, 0x58(%rsp)
movq (%rax,%rdx,8), %r14
movl 0xd4(%r14), %eax
cltd
movq 0x8(%rsp), %rsi
idivl 0xc8(%rsi)
movl %eax, %ebp
movl %edx, 0x18(%rsp)
movq %rsi, %rdx
leaq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%r14), %rax
movq %rax, 0x60(%rsp)
leaq 0xb0(%r14), %rax
movq %rax, 0x10(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %ebx
addl 0x18(%rsp), %ebx
js 0x2be23
cmpl 0xc0(%rdx), %ebx
jge 0x2be23
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
orl %r12d, %eax
je 0x2be16
movl %ebp, %eax
addl %r15d, %eax
js 0x2be16
cmpl 0xc4(%rdx), %eax
jge 0x2be16
imull 0xc8(%rdx), %eax
addl %ebx, %eax
cltq
imulq $0xe0, %rax, %r13
addq 0x28(%rcx), %r13
movl 0xa4(%r14), %eax
testb $0x4, %al
je 0x2bc8d
testb $0x2, 0xa4(%r13)
jne 0x2be16
testb $0x2, %al
je 0x2bc9f
testb $0x4, 0xa4(%r13)
jne 0x2be16
movsd 0x148d11(%rip), %xmm0   # 0x1749b8
ucomisd %xmm2, %xmm0
jbe 0x2bd27
movapd %xmm0, 0x40(%rsp)
movsd 0x50(%r14), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x50(%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x8(%r13), %rsi
movq 0x20(%rsp), %rdi
callq 0x69f47
movsd 0x30(%rsp), %xmm2
minsd 0x28(%rsp), %xmm2
movapd 0x40(%rsp), %xmm3
mulsd %xmm2, %xmm3
xorpd %xmm1, %xmm1
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm3
movsd 0xd9374(%rip), %xmm2    # 0x105078
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
mulsd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
xorpd %xmm2, %xmm2
ja 0x2be16
movsd 0x14de41(%rip), %xmm0   # 0x179b70
ucomisd %xmm2, %xmm0
jbe 0x2bd97
movsd 0x78(%r14), %xmm1
subsd 0x78(%r13), %xmm1
andpd 0xd9347(%rip), %xmm1    # 0x105090
ucomisd %xmm0, %xmm1
ja 0x2be16
movsd 0x80(%r14), %xmm1
subsd 0x80(%r13), %xmm1
andpd 0xd9323(%rip), %xmm1    # 0x105090
ucomisd %xmm0, %xmm1
ja 0x2be16
movsd 0x88(%r14), %xmm1
subsd 0x88(%r13), %xmm1
andpd 0xd92ff(%rip), %xmm1    # 0x105090
ucomisd %xmm0, %xmm1
ja 0x2be16
movsd 0x14ddc9(%rip), %xmm0   # 0x179b68
ucomisd %xmm2, %xmm0
jbe 0x2bdf5
leaq 0x20(%r13), %rsi
movq 0x60(%rsp), %rdi
callq 0x93dd6
andpd 0xd92d5(%rip), %xmm0    # 0x105090
movsd 0xd9265(%rip), %xmm1    # 0x105028
ucomisd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm1
jbe 0x2bdde
callq 0x23850
movsd 0x38(%rsp), %xmm1
subsd %xmm0, %xmm1
ucomisd 0x14dd82(%rip), %xmm1   # 0x179b68
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
xorpd %xmm2, %xmm2
ja 0x2be16
movl 0xbc(%r14), %edx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb2422
xorpd %xmm2, %xmm2
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
incl %r15d
cmpl $0x2, %r15d
jne 0x2bc3b
incl %r12d
cmpl $0x2, %r12d
jne 0x2bc1c
movq 0x58(%rsp), %rdx
incq %rdx
movslq 0xc(%rcx), %rax
cmpq %rax, %rdx
jl 0x2bbd0
leaq 0x118(%rsp), %rdi
callq 0xb23f6
movq (%rsp), %rdi
cmpl $0x0, 0xc(%rdi)
je 0x2bf19
movq %rdi, %rbx
movl $0x3, %esi
callq 0x5b972
testl %eax, %eax
je 0x2bf22
movq 0x1c0(%rsp), %rsi
movslq 0x24(%rbx), %rax
testq %rax, %rax
movq 0x1a0(%rsp), %r14
jle 0x2befe
movq (%rsp), %rcx
movq 0x18(%rcx), %rcx
xorl %edx, %edx
leaq 0x149209(%rip), %rdi    # 0x1750a8
movq (%rcx,%rdx,8), %r9
movslq 0x14(%r9), %r8
incq %rdx
testq %r8, %r8
jle 0x2bef9
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movq 0x8(%r9), %r9
movq 0xb8(%r14), %r10
movsd (%rdi), %xmm1
xorl %r11d, %r11d
movq (%r9,%r11,8), %rbx
ucomisd (%rbx), %xmm1
jae 0x2bef1
movslq 0xd4(%rbx), %rbx
testq %rbx, %rbx
js 0x2bef1
cmpl 0xcc(%r14), %ebx
jge 0x2bef1
movsd %xmm0, (%r10,%rbx,8)
movsd (%rdi), %xmm1
incq %r11
cmpq %r11, %r8
jne 0x2bec8
cmpq %rax, %rdx
jne 0x2be9f
movl $0x1, %ebp
testq %rsi, %rsi
je 0x2bf32
movq (%rsp), %rdi
callq 0x5bfb0
testl %eax, %eax
jne 0x2bf32
xorl %ebp, %ebp
jmp 0x2bf4b
leaq 0xd9a0c(%rip), %rdi     # 0x10592c
jmp 0x2bf29
leaq 0xd9a22(%rip), %rdi     # 0x10594b
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xb4efe
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x59f6a
movl $0xe0, %esi
movq %rbx, %rdi
callq 0x238f0
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movl $0x60, %esi
movq %r14, %rdi
callq 0x238f0
jmp 0x2bfbd
jmp 0x2bfba
movq %rax, %r15
movl $0xe0, %esi
movq %r12, %rdi
callq 0x238f0
jmp 0x2bfca
movq %rax, %r15
testq %rbx, %rbx
je 0x2bfa9
negq %rbx
movq %r12, %r13
addq $-0x28, %r13
leaq (%rbx,%r13), %rdi
callq 0xb23f6
addq $-0xe0, %rbx
jne 0x2bf97
movq %r12, %rdi
movq %r14, %rsi
callq 0x242a0
jmp 0x2bfca
jmp 0x2bfba
jmp 0x2bfba
movq %rax, %r15
leaq 0x118(%rsp), %rdi
callq 0xb23f6
movq %r15, %rdi
callq 0x240d0