// File: /workspace/github_cpp_makefile_star2_O1/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 0x9e484
movsd 0xdc704(%rip), %xmm0    # 0x108048
movq %rbx, %rdi
callq 0x9fcca
movl $0xe0, %ebx
movl $0xe0, %edi
callq 0x238d0
movq %rax, %r12
movq %rax, %rdi
callq 0x5a7c0
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 0x2b9eb
movq %rax, %r12
imulq $-0xe0, %r13, %rbp
xorl %ebx, %ebx
movq %r15, %r13
movq %r13, %rdi
callq 0x5766c
addq $-0xe0, %rbx
addq $0xe0, %r13
cmpq %rbx, %rbp
jne 0x2b9d0
movq (%rsp), %rcx
movq %r15, 0x28(%rcx)
movq 0x8(%rsp), %rdx
cmpl $0x0, 0xc0(%rdx)
jle 0x2bbeb
leaq 0xe1f2c(%rip), %rax     # 0x10d938
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
leaq 0x14c688(%rip), %r15    # 0x1780a8
xorpd %xmm2, %xmm2
leaq 0x68(%rsp), %rbp
cmpl $0x0, 0xc4(%rdx)
jle 0x2bbdb
xorl %r14d, %r14d
movl 0xc8(%rdx), %eax
imull %r14d, %eax
addl %r13d, %eax
movslq %eax, %rbx
movq 0xb8(%rdx), %rax
movsd (%rax,%rbx,8), %xmm0
movsd (%r15), %xmm1
ucomisd %xmm0, %xmm1
jae 0x2bbcb
imulq $0xe0, %rbx, %r12
movsd 0x1510ed(%rip), %xmm1   # 0x17cb60
addq 0x28(%rcx), %r12
ucomisd %xmm2, %xmm1
jbe 0x2ba87
ucomisd %xmm1, %xmm0
ja 0x2bbcb
movsd %xmm0, (%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 0xae4bc
leaq 0x78(%r12), %rdi
movq %rbp, %rsi
callq 0xb3892
movq 0x30(%rsp), %rax
movq 0xb8(%rax), %rax
movsd (%rax,%rbx,8), %xmm0
addsd 0xdc482(%rip), %xmm0    # 0x108018
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 0xb3a22
xorpd %xmm2, %xmm2
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
incl %r14d
cmpl 0xc4(%rdx), %r14d
jl 0x2ba39
incl %r13d
cmpl 0xc0(%rdx), %r13d
jl 0x2ba29
leaq 0x68(%rsp), %rdi
callq 0x5766c
movl $0x60, %edi
callq 0x238d0
movq %rax, %r14
movq %rax, %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
movl $0x8, %edx
callq 0x2c062
movq %r14, 0x10(%rbx)
cmpl $0x0, 0xc(%rbx)
jle 0x2beb3
movq %rbx, %rcx
leaq 0xe1d1a(%rip), %rax     # 0x10d948
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 0x2be91
cmpl 0xc0(%rdx), %ebx
jge 0x2be91
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
orl %r12d, %eax
je 0x2be84
movl %ebp, %eax
addl %r15d, %eax
js 0x2be84
cmpl 0xc4(%rdx), %eax
jge 0x2be84
imull 0xc8(%rdx), %eax
addl %ebx, %eax
cltq
imulq $0xe0, %rax, %r13
addq 0x28(%rcx), %r13
movl 0xa4(%r14), %eax
testb $0x4, %al
je 0x2bcfb
testb $0x2, 0xa4(%r13)
jne 0x2be84
testb $0x2, %al
je 0x2bd0d
testb $0x4, 0xa4(%r13)
jne 0x2be84
movsd 0x14bca3(%rip), %xmm0   # 0x1779b8
ucomisd %xmm2, %xmm0
jbe 0x2bd95
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 0x6b003
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 0xdc306(%rip), %xmm2    # 0x108078
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
mulsd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
xorpd %xmm2, %xmm2
ja 0x2be84
movsd 0x150dd3(%rip), %xmm0   # 0x17cb70
ucomisd %xmm2, %xmm0
jbe 0x2be05
movsd 0x78(%r14), %xmm1
subsd 0x78(%r13), %xmm1
andpd 0xdc2d9(%rip), %xmm1    # 0x108090
ucomisd %xmm0, %xmm1
ja 0x2be84
movsd 0x80(%r14), %xmm1
subsd 0x80(%r13), %xmm1
andpd 0xdc2b5(%rip), %xmm1    # 0x108090
ucomisd %xmm0, %xmm1
ja 0x2be84
movsd 0x88(%r14), %xmm1
subsd 0x88(%r13), %xmm1
andpd 0xdc291(%rip), %xmm1    # 0x108090
ucomisd %xmm0, %xmm1
ja 0x2be84
movsd 0x150d5b(%rip), %xmm0   # 0x17cb68
ucomisd %xmm2, %xmm0
jbe 0x2be63
leaq 0x20(%r13), %rsi
movq 0x60(%rsp), %rdi
callq 0x951ea
andpd 0xdc267(%rip), %xmm0    # 0x108090
movsd 0xdc1f7(%rip), %xmm1    # 0x108028
ucomisd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm1
jbe 0x2be4c
callq 0x23850
movsd 0x38(%rsp), %xmm1
subsd %xmm0, %xmm1
ucomisd 0x150d14(%rip), %xmm1   # 0x17cb68
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
xorpd %xmm2, %xmm2
ja 0x2be84
movl 0xbc(%r14), %edx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb3a22
xorpd %xmm2, %xmm2
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
incl %r15d
cmpl $0x2, %r15d
jne 0x2bca9
incl %r12d
cmpl $0x2, %r12d
jne 0x2bc8a
movq 0x58(%rsp), %rdx
incq %rdx
movslq 0xc(%rcx), %rax
cmpq %rax, %rdx
jl 0x2bc3e
leaq 0x118(%rsp), %rdi
callq 0xb39f6
movq (%rsp), %rdi
cmpl $0x0, 0xc(%rdi)
je 0x2bee6
movl $0x3, %esi
callq 0x5c3f0
testl %eax, %eax
movq 0x1a0(%rsp), %r15
je 0x2bef7
movq (%rsp), %rax
jmp 0x2bf20
leaq 0xdca42(%rip), %rdi     # 0x10892f
movq 0x1a0(%rsp), %r15
jmp 0x2befe
leaq 0xdca50(%rip), %rdi     # 0x10894e
xorl %eax, %eax
callq 0xb680a
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x5a976
movl $0xe0, %esi
movq %rbx, %rdi
callq 0x238f0
xorl %eax, %eax
xorl %ebp, %ebp
testq %rax, %rax
je 0x2bfda
movq 0x1c0(%rsp), %rsi
movq %rax, %r14
movslq 0x24(%rax), %rax
testq %rax, %rax
jle 0x2bfac
movq 0x18(%r14), %rcx
xorl %edx, %edx
leaq 0x14c15c(%rip), %rdi    # 0x1780a8
movq (%rcx,%rdx,8), %r9
movslq 0x14(%r9), %r8
testq %r8, %r8
jle 0x2bfa4
movq 0x8(%r9), %r9
leal 0x1(%rdx), %r10d
xorps %xmm0, %xmm0
cvtsi2sd %r10d, %xmm0
movq 0xb8(%r15), %r10
xorl %r11d, %r11d
movq (%r9,%r11,8), %rbx
movsd (%rdi), %xmm1
ucomisd (%rbx), %xmm1
jae 0x2bf9c
movslq 0xd4(%rbx), %rbx
testq %rbx, %rbx
js 0x2bf9c
cmpl 0xcc(%r15), %ebx
jge 0x2bf9c
movsd %xmm0, (%r10,%rbx,8)
incq %r11
cmpq %r11, %r8
jne 0x2bf73
incq %rdx
cmpq %rax, %rdx
jne 0x2bf4c
testq %rsi, %rsi
movq %r14, %rbx
je 0x2bfc0
movq %rbx, %rdi
callq 0x5ca6a
testl %eax, %eax
je 0x2bfda
movq %rbx, %rdi
callq 0x5a976
movl $0xe0, %esi
movq %rbx, %rdi
callq 0x238f0
movl $0x1, %ebp
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 0x2c04c
jmp 0x2c049
movq %rax, %r15
movl $0xe0, %esi
movq %r12, %rdi
callq 0x238f0
jmp 0x2c059
movq %rax, %r15
testq %rbx, %rbx
je 0x2c038
negq %rbx
movq %r12, %r13
addq $-0x28, %r13
leaq (%rbx,%r13), %rdi
callq 0xb39f6
addq $-0xe0, %rbx
jne 0x2c026
movq %r12, %rdi
movq %r14, %rsi
callq 0x242b0
jmp 0x2c059
jmp 0x2c049
jmp 0x2c049
movq %rax, %r15
leaq 0x118(%rsp), %rdi
callq 0xb39f6
movq %r15, %rdi
callq 0x240e0
nop