// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, 0x130(%rax)
movsd 0x116c4a(%rip), %xmm0   # 0x1f2018
movsd %xmm0, -0x30(%rbp)
cmpq $0x0, 0x130(%rax)
jne 0xdb3f5
movq 0x197bdc(%rip), %rdi    # 0x272fc0
leaq 0x120654(%rip), %rsi    # 0x1fba3f
callq 0x5540
callq 0x52b0
jmp 0xdb3f7
movq -0x40(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
callq 0x163b0
movq -0x40(%rbp), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0x851f0
movl $0x0, -0x24(%rbp)
movq -0x40(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0x44(%rbp)
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
jge 0xdb461
movq -0x40(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
leaq -0x34(%rbp), %rsi
callq 0xffc0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xdb41e
movq -0x40(%rbp), %rax
movl $0x0, 0x138(%rax)
movsd -0x30(%rbp), %xmm0
movsd 0x120464(%rip), %xmm1   # 0x1fb8e0
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0x116be6(%rip), %xmm1   # 0x1f2078
ucomisd %xmm1, %xmm0
jne 0xdb4c1
jp 0xdb4c1
movq 0x197b4f(%rip), %rdi    # 0x272ff0
leaq 0x1205af(%rip), %rsi    # 0x1fba57
callq 0x5540
movq %rax, %rdi
leaq 0x11e16e(%rip), %rsi    # 0x1f9625
callq 0x5540
callq 0x52b0
jmp 0xdb4c3
movq -0x40(%rbp), %rdi
callq 0xdb2e0
cmpl $-0x1, %eax
jle 0xdb6a7
movq -0x40(%rbp), %rdi
callq 0xdb2e0
movq -0x40(%rbp), %rdi
movl %eax, -0x14(%rbp)
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq -0x40(%rbp), %rdi
movsd 0x38(%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
movl 0x138(%rdi), %eax
movl %eax, -0x54(%rbp)
addq $0x140, %rdi            # imm = 0x140
movslq -0x14(%rbp), %rsi
callq 0xed60
movl -0x54(%rbp), %ecx
movq -0x40(%rbp), %rdi
movl %ecx, (%rax)
movq %rdi, %rax
addq $0x238, %rax            # imm = 0x238
movq %rax, -0x50(%rbp)
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq -0x50(%rbp), %rdi
movq %rax, %rsi
addq $0x38, %rsi
callq 0x105c0
movl $0x0, -0x24(%rbp)
movq -0x40(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0x58(%rbp)
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movl -0x58(%rbp), %eax
cmpl %ecx, %eax
jge 0xdb68f
movq -0x40(%rbp), %rdi
movq 0x130(%rdi), %rax
movq %rax, -0x88(%rbp)
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq -0x40(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq -0x40(%rbp), %rdi
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
addq $0x60, %rdi
movslq -0x14(%rbp), %rsi
callq 0x10130
movq -0x40(%rbp), %rdi
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
addq $0x60, %rdi
movslq -0x24(%rbp), %rsi
callq 0x10130
movq -0x40(%rbp), %rdi
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
addq $0x60, %rdi
movslq -0x24(%rbp), %rsi
callq 0x10130
movq -0x40(%rbp), %rdi
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
addq $0x60, %rdi
movslq -0x24(%rbp), %rsi
callq 0x10130
movq -0x88(%rbp), %rdi
movsd -0x80(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x70(%rbp), %xmm2
movsd -0x68(%rbp), %xmm3
movsd -0x60(%rbp), %xmm4
movsd 0x18(%rax), %xmm5
callq 0x97a10
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xdb67f
movq -0x40(%rbp), %rdi
movl 0x138(%rdi), %eax
movl %eax, -0x8c(%rbp)
addq $0x140, %rdi            # imm = 0x140
movslq -0x24(%rbp), %rsi
callq 0xed60
movl -0x8c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xdb681
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xdb553
movq -0x40(%rbp), %rax
movl 0x138(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x138(%rax)
jmp 0xdb4c3
jmp 0xdb6a9
movq -0x40(%rbp), %rdi
callq 0xdbfb0
cmpl $0x0, %eax
je 0xdb3f7
movq 0x1978fe(%rip), %rdi    # 0x272fc0
leaq 0x1203ac(%rip), %rsi    # 0x1fba75
callq 0x5540
movq %rax, %rdi
movq -0x40(%rbp), %rax
movl 0x138(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x11df3b(%rip), %rsi    # 0x1f9625
callq 0x5540
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)