// File: Luthaf[P]zeopp/feature.cc
// Function: FEATURE::segmentChannel(ATOM_NETWORK*)
void FEATURE::segmentChannel(ATOM_NETWORK *uc){
int i;

cout << "Current channel has " << nodes.size() << " nodes" << "\n";

for(i=0;i<(int)nodes.size();i++)
   {
   segments.push_back(-1);
   };
nsegments=0;

while(segment_findMaxNode()>-1)
   {
//   segment_growSegment_start(uc,segment_findMaxNode());
   segment_distBasedSegmentation(uc);
   };

cout << "Initial number of segments (minima) " << nsegments << "\n";

/*
fstream output1;
output1.open("segments.zvis",fstream::out);
segment_saveVis(output1);
output1.close();
*/

//segment_identify_connections(); // analyzes connectivity of each segment to find segment's 'faces' - connection between segments 



//merge_segments(); // analyze segments and merge if neccesary

//merge_nothing(); // this function copies segments into features

merge_singlenode_segments();


//calculateVolumeForAllFeatures(); // calculate volume of each segment


/* Print results */
cout << "\n" << "Segment info (ID - r):"<<"\n";
for(i=0;i<(int)segment_max_r.size();i++)
   {
   cout << i<< "   " << segment_max_r[i]  << "\n";
   };
cout << "\n" << "Segment connection info (from to radii merge_stat):"<<"\n";

/*
for(i=0;i<(int)segment_conn.size();i++)
   {
   cout << segment_conn.at(i).from_seg << "   " << segment_conn.at(i).to_seg << "   " <<segment_conn.at(i).max_radius << "   " << segment_conn.at(i).merged << "\n";
   };

cout << "\n" << "Total number of segment connecting edges :  "<< segment_conn_fulllist.size()  <<"\n";

cout << "\n" << "Segment info vs features (segment ID - feature ID):"<<"\n";
for(i=0;i<nsegments;i++)
   {
   cout << i<< "   " << segment_merge_list[i]  << "\n";
   };
*/
cout << "\n" << "Features info (ID - r - volume):"<<"\n";
for(i=0;i<(int)feature_max_r.size();i++)
   {
//   cout << i<< "   " << feature_max_r[i]  << "   " << feature_volume[i] << "\n";
   cout << i<< "   " << feature_max_r[i]   << "\n";
   };
/*
cout << "\n" << "Features connection info (from to radii ):"<<"\n";
for(i=0;i<(int)feature_conn.size();i++)
   {
   cout << feature_conn.at(i).from_seg << "   " << feature_conn.at(i).to_seg << "   " <<feature_conn.at(i).max_radius << "\n";
   };
*/

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq 0x19a761(%rip), %rdi    # 0x272fc0
leaq 0x123133(%rip), %rsi    # 0x1fb999
callq 0x5540
movq -0x28(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x60, %rdi
callq 0x10100
movq -0x20(%rbp), %rdi
movq %rax, %rsi
callq 0x5160
movq %rax, %rdi
leaq 0x11e2be(%rip), %rsi    # 0x1f6b50
callq 0x5540
movq %rax, %rdi
leaq 0x120d84(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x0, -0x14(%rbp)
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movl -0x2c(%rbp), %eax
cmpl %ecx, %eax
jge 0xd88f0
movq -0x28(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
leaq -0x18(%rbp), %rsi
callq 0xffc0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xd88ad
movq -0x28(%rbp), %rax
movl $0x0, 0x138(%rax)
movq -0x28(%rbp), %rdi
callq 0xdb2e0
cmpl $-0x1, %eax
jle 0xd891b
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xdb3a0
jmp 0xd88fe
movq 0x19a69e(%rip), %rdi    # 0x272fc0
leaq 0x123085(%rip), %rsi    # 0x1fb9ae
callq 0x5540
movq %rax, %rdi
movq -0x28(%rbp), %rax
movl 0x138(%rax), %esi
callq 0x58d0
movq %rax, %rdi
leaq 0x120cdb(%rip), %rsi    # 0x1f9625
callq 0x5540
movq -0x28(%rbp), %rdi
callq 0xdb700
movq 0x19a661(%rip), %rdi    # 0x272fc0
leaq 0x120cbf(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x12305e(%rip), %rsi    # 0x1fb9d3
callq 0x5540
movq %rax, %rdi
leaq 0x120ca1(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x0, -0x14(%rbp)
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x30(%rbp)
addq $0x238, %rdi            # imm = 0x238
callq 0xf990
movq %rax, %rcx
movl -0x30(%rbp), %eax
cmpl %ecx, %eax
jge 0xd8a0d
movl -0x14(%rbp), %esi
movq 0x19a606(%rip), %rdi    # 0x272fc0
callq 0x58d0
movq %rax, %rdi
leaq 0x119abe(%rip), %rsi    # 0x1f2487
callq 0x5540
movq -0x28(%rbp), %rdi
movq %rax, -0x38(%rbp)
addq $0x238, %rdi            # imm = 0x238
movslq -0x14(%rbp), %rsi
callq 0xedb0
movq -0x38(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x5980
movq %rax, %rdi
leaq 0x120c28(%rip), %rsi    # 0x1f9625
callq 0x5540
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xd8990
movq 0x19a5ac(%rip), %rdi    # 0x272fc0
leaq 0x120c0a(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x122fc0(%rip), %rsi    # 0x1fb9ea
callq 0x5540
movq %rax, %rdi
leaq 0x120bec(%rip), %rsi    # 0x1f9625
callq 0x5540
movq 0x19a57b(%rip), %rdi    # 0x272fc0
leaq 0x120bd9(%rip), %rsi    # 0x1f9625
callq 0x5540
movq %rax, %rdi
leaq 0x122fc3(%rip), %rsi    # 0x1fba1e
callq 0x5540
movq %rax, %rdi
leaq 0x120bbb(%rip), %rsi    # 0x1f9625
callq 0x5540
movl $0x0, -0x14(%rbp)
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
addq $0x250, %rdi            # imm = 0x250
callq 0xf990
movq %rax, %rcx
movl -0x3c(%rbp), %eax
cmpl %ecx, %eax
jge 0xd8af3
movl -0x14(%rbp), %esi
movq 0x19a520(%rip), %rdi    # 0x272fc0
callq 0x58d0
movq %rax, %rdi
leaq 0x1199d8(%rip), %rsi    # 0x1f2487
callq 0x5540
movq -0x28(%rbp), %rdi
movq %rax, -0x48(%rbp)
addq $0x250, %rdi            # imm = 0x250
movslq -0x14(%rbp), %rsi
callq 0xedb0
movq -0x48(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x5980
movq %rax, %rdi
leaq 0x120b42(%rip), %rsi    # 0x1f9625
callq 0x5540
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xd8a76
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)