// File: /workspace/github_cpp_makefile_star2_O2/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 0x9019a
movsd 0xc25f8(%rip), %xmm0    # 0xed048
movq %rbx, %rdi
callq 0x9183c
movl $0xe0, %ebx
movl $0xe0, %edi
callq 0x238e0
movq %rax, %r15
movq %rax, %rdi
callq 0x536ce
movq %r14, 0x8(%rsp)
movslq 0xcc(%r14), %r14
movq %r14, %rax
mulq %rbx
seto %cl
orq $0x8, %rax
pushq $-0x1
popq %r12
testb %cl, %cl
cmoveq %rax, %r12
movl $0x7800, %ecx           # imm = 0x7800
movl %r14d, %eax
cltd
idivl %ecx
movq %r15, (%rsp)
movl %eax, 0x38(%r15)
movq %r12, %rdi
callq 0x23040
leaq 0x8(%rax), %r15
movq %r14, (%rax)
testq %r14, %r14
je 0x2aae6
movq %rax, %r13
imulq $-0xe0, %r14, %rbp
xorl %ebx, %ebx
movq %r15, %r14
movq %r14, %rdi
callq 0x50aa0
addq $-0xe0, %rbx
addq $0xe0, %r14
cmpq %rbx, %rbp
jne 0x2aacb
movq 0x180(%rsp), %rbx
movq (%rsp), %rax
movq %r15, 0x28(%rax)
leaq 0xc7d4b(%rip), %rax     # 0xf2848
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %ebp, %ebp
leaq 0x1395b8(%rip), %rdx    # 0x1640c8
xorpd %xmm2, %xmm2
leaq 0x68(%rsp), %r12
movq 0x8(%rsp), %rax
cmpl 0xc0(%rax), %ebp
jge 0x2accd
xorl %r14d, %r14d
movq 0x8(%rsp), %rcx
cmpl 0xc4(%rcx), %r14d
jge 0x2acc6
movl 0xc8(%rcx), %eax
imull %r14d, %eax
addl %ebp, %eax
movslq %eax, %r15
movq 0xb8(%rcx), %rax
movsd (%rax,%r15,8), %xmm0
movsd (%rdx), %xmm1
ucomisd %xmm0, %xmm1
jae 0x2acbe
imulq $0xe0, %r15, %r13
movsd 0x13e008(%rip), %xmm1   # 0x168b80
movq (%rsp), %rax
addq 0x28(%rax), %r13
ucomisd %xmm2, %xmm1
jbe 0x2ab90
ucomisd %xmm1, %xmm0
ja 0x2acbe
movsd %xmm0, (%r13)
movq 0x18(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq 0x20(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm1
movq 0x28(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm2
movsd %xmm0, 0x8(%r13)
movsd %xmm1, 0x10(%r13)
movsd %xmm2, 0x18(%r13)
movq 0x40(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq 0xb8(%rbx), %rax
movsd (%rax,%r15,8), %xmm1
movq 0x188(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm2
movsd %xmm0, 0x20(%r13)
movsd %xmm1, 0x28(%r13)
movsd %xmm2, 0x30(%r13)
movq 0x190(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x50(%r13)
movsd %xmm0, 0x58(%r13)
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x70(%r13)
movq %r12, %rdi
movq 0x198(%rsp), %rsi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x9ee92
leaq 0x78(%r13), %rdi
movq %r12, %rsi
callq 0xa3a5e
movq 0x30(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%r15,8), %xmm0
addsd 0xc2384(%rip), %xmm0    # 0xed018
cvttsd2si %xmm0, %rax
movl %eax, 0xa4(%r13)
movl %r15d, 0xd4(%r13)
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x2a97e
xorpd %xmm2, %xmm2
leaq 0x13940a(%rip), %rdx    # 0x1640c8
incl %r14d
jmp 0x2ab2d
incl %ebp
jmp 0x2ab19
leaq 0x68(%rsp), %rdi
callq 0x50aa0
pushq $0x60
popq %rdi
callq 0x238e0
movq %rax, %r12
pushq $0x8
popq %rdx
movq %rax, %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x2b0f4
movq %r12, 0x10(%rbx)
leaq 0xc7b59(%rip), %rax     # 0xf2858
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %edx, %edx
movslq 0xc(%rbx), %rax
cmpq %rax, %rdx
movq 0x8(%rsp), %rcx
jge 0x2af7d
movq (%rbx), %rax
movq %rdx, 0x58(%rsp)
movq (%rax,%rdx,8), %r14
movl 0xd4(%r14), %eax
cltd
idivl 0xc8(%rcx)
movl %eax, %ebp
movl %edx, 0x18(%rsp)
leaq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%r14), %rax
movq %rax, 0x60(%rsp)
leaq 0xb0(%r14), %rax
movq %rax, 0x10(%rsp)
pushq $-0x1
popq %r12
cmpl $0x2, %r12d
je 0x2af6c
movl %r12d, %ebx
addl 0x18(%rsp), %ebx
js 0x2af64
movq 0x8(%rsp), %rax
cmpl 0xc0(%rax), %ebx
jge 0x2af64
pushq $-0x1
popq %r15
cmpl $0x2, %r15d
je 0x2af64
movl %r15d, %eax
orl %r12d, %eax
je 0x2af5c
movl %ebp, %eax
addl %r15d, %eax
js 0x2af5c
movq 0x8(%rsp), %rcx
cmpl 0xc4(%rcx), %eax
jge 0x2af5c
movq 0x8(%rsp), %rcx
imull 0xc8(%rcx), %eax
addl %ebx, %eax
cltq
imulq $0xe0, %rax, %r13
movq (%rsp), %rax
addq 0x28(%rax), %r13
movl 0xa4(%r14), %eax
testb $0x4, %al
je 0x2adf5
testb $0x2, 0xa4(%r13)
jne 0x2af5c
testb $0x2, %al
je 0x2ae07
testb $0x4, 0xa4(%r13)
jne 0x2af5c
movsd 0x138bc9(%rip), %xmm0   # 0x1639d8
ucomisd 0xc2241(%rip), %xmm0    # 0xed058
jbe 0x2ae86
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 0x61fa5
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 0xc2208(%rip), %xmm2    # 0xed078
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
mulsd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
ja 0x2af5c
movsd 0x13dd02(%rip), %xmm0   # 0x168b90
ucomisd 0xc21c2(%rip), %xmm0    # 0xed058
jbe 0x2aefa
movsd 0x78(%r14), %xmm1
subsd 0x78(%r13), %xmm1
andpd 0xc21e4(%rip), %xmm1    # 0xed090
ucomisd %xmm0, %xmm1
ja 0x2af5c
movsd 0x80(%r14), %xmm1
subsd 0x80(%r13), %xmm1
andpd 0xc21c0(%rip), %xmm1    # 0xed090
ucomisd %xmm0, %xmm1
ja 0x2af5c
movsd 0x88(%r14), %xmm1
subsd 0x88(%r13), %xmm1
andpd 0xc219c(%rip), %xmm1    # 0xed090
ucomisd %xmm0, %xmm1
ja 0x2af5c
movsd 0x13dc86(%rip), %xmm0   # 0x168b88
ucomisd 0xc214e(%rip), %xmm0    # 0xed058
jbe 0x2af4f
leaq 0x20(%r13), %rsi
movq 0x60(%rsp), %rdi
callq 0x87dbe
andpd 0xc216e(%rip), %xmm0    # 0xed090
movsd 0xc20fe(%rip), %xmm1    # 0xed028
ucomisd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm1
jbe 0x2af45
callq 0x23860
movsd 0x38(%rsp), %xmm1
subsd %xmm0, %xmm1
ucomisd 0x13dc3b(%rip), %xmm1   # 0x168b88
ja 0x2af5c
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x2a97e
incl %r15d
jmp 0x2ad8b
incl %r12d
jmp 0x2ad5f
movq 0x58(%rsp), %rdx
incq %rdx
movq (%rsp), %rbx
jmp 0x2ad0b
leaq 0x118(%rsp), %rdi
callq 0xa3bc4
cmpl $0x0, 0xc(%rbx)
je 0x2b041
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x55068
testl %eax, %eax
je 0x2b04a
movl 0x24(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
xorl %edx, %edx
movq 0x1a0(%rsp), %r11
leaq 0x139106(%rip), %r14    # 0x1640c8
cmpq %rax, %rdx
je 0x2b021
movq 0x18(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl 0x14(%rsi), %edi
incq %rdx
cvtsi2sd %edx, %xmm0
movq 0xb8(%r11), %r8
testl %edi, %edi
cmovlel %ecx, %edi
xorl %r9d, %r9d
cmpq %r9, %rdi
je 0x2afc2
movq 0x8(%rsi), %r10
movq (%r10,%r9,8), %r10
movsd (%r14), %xmm1
ucomisd (%r10), %xmm1
jae 0x2b01c
movslq 0xd4(%r10), %r10
testq %r10, %r10
js 0x2b01c
cmpl 0xcc(%r11), %r10d
jge 0x2b01c
movsd %xmm0, (%r8,%r10,8)
incq %r9
jmp 0x2afe8
pushq $0x1
popq %rbp
movq 0x1c0(%rsp), %rsi
testq %rsi, %rsi
je 0x2b05a
movq %rbx, %rdi
callq 0x554ea
testl %eax, %eax
jne 0x2b05a
xorl %ebp, %ebp
jmp 0x2b06f
leaq 0xc28e4(%rip), %rdi     # 0xed92c
jmp 0x2b051
leaq 0xc28fa(%rip), %rdi     # 0xed94b
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xa61ce
movq %rbx, %rdi
callq 0x53878
movl $0xe0, %esi
movq %rbx, %rdi
callq 0x23900
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x60
popq %rsi
movq %r12, %rdi
callq 0x23900
jmp 0x2b0df
jmp 0x2b0dc
movq %rax, %r14
movl $0xe0, %esi
movq %r15, %rdi
callq 0x23900
jmp 0x2b0ec
movq %rax, %r14
testq %rbx, %rbx
je 0x2b0cb
negq %rbx
movq %r13, %r15
addq $-0x28, %r15
leaq (%r15,%rbx), %rdi
callq 0xa3bc4
addq $-0xe0, %rbx
jne 0x2b0b9
movq %r13, %rdi
movq %r12, %rsi
callq 0x242d0
jmp 0x2b0ec
jmp 0x2b0dc
jmp 0x2b0dc
movq %rax, %r14
leaq 0x118(%rsp), %rdi
callq 0xa3bc4
movq %r14, %rdi
callq 0x240f0