// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::segment_distBasedSegmentation(ATOM_NETWORK*)
void FEATURE::segment_distBasedSegmentation(ATOM_NETWORK *uc)
{
UnitCellPtr=uc;

int cur_maxId; // id of current max node
double cur_r;
int i;

double scale_factor=1.1;

if(UnitCellPtr==NULL) {cout<< "no distance pointer set";abort();};


do{
/* clear variable */
segments.clear();
segment_max_r.clear();
for(i=0;i<(int)nodes.size();i++)
   {
   segments.push_back(-1);
   };
nsegments=0;

/* adjust scale factor */
scale_factor-=0.05;

if(scale_factor==0.5)
    {
    cerr << "Segmentation failed. Aborting" << "\n";
    abort();
    };

/* perform segmentation */
while(segment_findMaxNode()>-1)
  {
  cur_maxId=segment_findMaxNode();
  cur_r=nodes.at(cur_maxId).max_radius;
  segments[cur_maxId]=nsegments; // assign new segment number to a nw segment
  segment_max_r.push_back(nodes.at(cur_maxId).max_radius); //store maximum r in a segment

  // now assign all nodes with close distance to the current node
  for(i=0;i<(int)nodes.size();i++)
     {
     if(UnitCellPtr->calcDistanceXYZ(nodes.at(cur_maxId).x,nodes.at(cur_maxId).y,nodes.at(cur_maxId).z,nodes.at(i).x,nodes.at(i).y,nodes.at(i).z)<scale_factor*cur_r)
        {
        segments[i]=nsegments;
        };
     };

  nsegments++;
  };

}while(validateSegmentation()==0);
//}while(scale_factor>0.5);

cout << " no segments after segment_distBasedSegmentation: " << nsegments << "\n"; 

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x130(%rdi)
testq %rsi, %rsi
je 0x5c02a
movq %rdi, %rbx
leaq 0x140(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq 0x238(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x60(%rdi), %r12
movsd 0xa0251(%rip), %xmm0    # 0xfc020
movsd %xmm0, 0x8(%rsp)
pushq $0x48
popq %r15
movq 0x140(%rbx), %rax
cmpq %rax, 0x148(%rbx)
je 0x5bdf0
movq %rax, 0x148(%rbx)
movq 0x238(%rbx), %rax
cmpq %rax, 0x240(%rbx)
je 0x5be07
movq %rax, 0x240(%rbx)
xorl %ebp, %ebp
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
cqto
idivq %r15
cmpl %eax, %ebp
jge 0x5be32
orl $-0x1, 0x14(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x10324
incl %ebp
jmp 0x5be09
andl $0x0, 0x138(%rbx)
movsd 0x8(%rsp), %xmm0
addsd 0xa7da1(%rip), %xmm0    # 0x103be8
movsd %xmm0, 0x8(%rsp)
ucomisd 0xa01e3(%rip), %xmm0    # 0xfc038
jne 0x5bfa4
jp 0x5bfa4
jmp 0x5c003
callq 0x5bcfc
movslq %eax, %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0xabe2
movl 0x138(%rbx), %ecx
movq 0x140(%rbx), %rdx
movsd 0x38(%rax), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movl %ecx, (%rdx,%rbp,4)
movq %r12, %rdi
movq %rbp, %rsi
callq 0xabe2
leaq 0x38(%rax), %rsi
movq 0x18(%rsp), %rdi
callq 0xac88
xorl %r13d, %r13d
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
cqto
idivq %r15
cltq
cmpq %rax, %r13
jge 0x5bf9e
movq 0x130(%rbx), %r14
movq %r12, %rdi
movq %rbp, %rsi
callq 0xabe2
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0xabe2
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0xabe2
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xabe2
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xabe2
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xabe2
movsd 0x18(%rax), %xmm5
movq %r14, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
callq 0x3f636
movsd 0x28(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5bf96
movl 0x138(%rbx), %eax
movq 0x140(%rbx), %rcx
movl %eax, (%rcx,%r13,4)
incq %r13
jmp 0x5beb6
incl 0x138(%rbx)
movq %rbx, %rdi
callq 0x5bcfc
movq %rbx, %rdi
testl %eax, %eax
jns 0x5be66
callq 0x5c514
testl %eax, %eax
je 0x5bdd9
movq 0xf3ff5(%rip), %rdi     # 0x14ffc0
leaq 0xa7dab(%rip), %rsi     # 0x103d7d
callq 0x4480
movl 0x138(%rbx), %esi
movq %rax, %rdi
callq 0x4760
leaq 0xa6592(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf3fe6(%rip), %rdi     # 0x14fff0
leaq 0xa7d4e(%rip), %rsi     # 0x103d5f
callq 0x4480
leaq 0xa6561(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
callq 0x4290
movq 0xf3f8f(%rip), %rdi     # 0x14ffc0
leaq 0xa7d0f(%rip), %rsi     # 0x103d47
jmp 0x5c020