// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/feature.cc
// Function: FEATURE::merge_segments()
void FEATURE::merge_segments()
{
	int i;
	int current_segment;
	SEGCONN featcon;
	segment_merge_list.resize(nsegments,-1);

	nfeatures=0;


	/* loop over all segment connections and mark ones to be merge
	* Merging criteria - restriction is smaller than % of average max radii for each segment
	* */
	for(i=0;i<(int)segment_conn.size();i++)
	{
		if(segment_conn.at(i).max_radius>FEAT_NODE_R_EDGE_R_RATIO*0.5*(segment_max_r[(segment_conn.at(i).from_seg)]+segment_max_r[(segment_conn.at(i).to_seg)]))
			segment_conn.at(i).merged=1;
	/* new function to merge short edges: */

	//   if(segment_conn.at(i).length<max(segment_max_r[(segment_conn.at(i).from_seg)],segment_max_r[(segment_conn.at(i).to_seg)]))
	//       segment_conn.at(i).merged=1;

	};

	/* after connections of to-be-merged segments have been identified, we build
	* features, this includes 'flood fill' of segments */ 

	do{
		//find first segment not assigned to feature 
		current_segment=merge_findNotAssignedFragment();  
		//creature new feature
		features.push_back(nfeatures); // number of segments after merging 
		//grow
		//  cout << current_segment << "\n";
		merge_newSegmentGrow(current_segment);
		//increase counter (number of segments)
		nfeatures++;
	}while(merge_findNotAssignedFragment()!=-1);

	// update feature radii vector
	feature_max_r.resize(nfeatures,0);
	for(i=0;i<(int)segment_merge_list.size();i++)
	{
		if(feature_max_r[segment_merge_list[i]]<segment_max_r[i]) feature_max_r[segment_merge_list[i]]=segment_max_r[i]; 
	};
	// update feature information on all nodes in a channel
	for(i=0;i<(int)nodes.size();i++)
	{
		feature_node_mapping.push_back(segment_merge_list[segments[i]]);
	};

	/* having identified features we need to convert segments connectivity info
	* into feature connectivity */

	for(i=0;i<(int)segment_conn.size();i++)
	{
		if(segment_conn.at(i).merged!=1)
		{
			featcon.from_seg=segment_merge_list[segment_conn.at(i).from_seg];
			featcon.to_seg=segment_merge_list[segment_conn.at(i).to_seg];
			featcon.max_radius=segment_conn.at(i).max_radius;
			feature_conn.push_back(featcon);
		};
	};

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3d98a
leaq 0x208(%rbx), %rdi
movslq 0x138(%rbx), %rsi
leaq 0x20(%rsp), %rdx
orl $-0x1, (%rdx)
movq %rdi, 0x8(%rsp)
callq 0x36f18
leaq 0x1b8(%rbx), %r12
andl $0x0, 0x1b8(%rbx)
leaq 0x158(%rbx), %r15
xorl %r13d, %r13d
pushq $0x30
popq %r14
movq 0x160(%rbx), %rax
subq 0x158(%rbx), %rax
cqto
idivq %r14
cltq
cmpq %rax, %r13
jge 0x5d41b
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movslq 0x8(%rax), %rax
movq 0x238(%rbx), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movslq 0xc(%rax), %rax
movq 0x238(%rbx), %rcx
movsd 0x10(%rsp), %xmm1
addsd (%rcx,%rax,8), %xmm1
mulsd 0x9ec73(%rip), %xmm1    # 0xfc068
movsd 0x18(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5d413
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movl $0x1, 0x20(%rax)
incq %r13
jmp 0x5d377
leaq 0x1c0(%rbx), %r13
movq %rbx, %rdi
callq 0x5d5a8
movl %eax, %ebp
movq %r13, %rdi
movq %r12, %rsi
callq 0x9434
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5d5f4
incl 0x1b8(%rbx)
movq %rbx, %rdi
callq 0x5d5a8
cmpl $-0x1, %eax
jne 0x5d422
leaq 0x250(%rbx), %rdi
movslq 0x1b8(%rbx), %rsi
leaq 0x20(%rsp), %rdx
andq $0x0, (%rdx)
callq 0x3713c
movq 0x208(%rbx), %rax
movq 0x210(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movq 0x250(%rbx), %rdx
movq 0x238(%rbx), %rsi
xorl %edi, %edi
testl %ecx, %ecx
cmovlel %edi, %ecx
cmpq %rdi, %rcx
je 0x5d4bb
movslq (%rax,%rdi,4), %r8
movsd (%rsi,%rdi,8), %xmm0
ucomisd (%rdx,%r8,8), %xmm0
jbe 0x5d4b6
movsd %xmm0, (%rdx,%r8,8)
incq %rdi
jmp 0x5d49a
leaq 0x1d8(%rbx), %r12
xorl %r13d, %r13d
pushq $0x48
popq %rbp
movq 0x68(%rbx), %rax
subq 0x60(%rbx), %rax
cqto
idivq %rbp
cltq
cmpq %rax, %r13
jge 0x5d4ff
movq 0x140(%rbx), %rax
movslq (%rax,%r13,4), %rsi
shlq $0x2, %rsi
addq 0x208(%rbx), %rsi
movq %r12, %rdi
callq 0x9434
incq %r13
jmp 0x5d4c8
leaq 0x1f0(%rbx), %r12
xorl %r13d, %r13d
movq 0x8(%rsp), %rbp
movq 0x160(%rbx), %rax
subq 0x158(%rbx), %rax
cqto
idivq %r14
cltq
cmpq %rax, %r13
jge 0x5d598
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
cmpl $0x1, 0x20(%rax)
je 0x5d590
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movslq 0x8(%rax), %rax
movq (%rbp), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x30(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movslq 0xc(%rax), %rax
movq (%rbp), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x34(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f2b8
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0x5f28a
incq %r13
jmp 0x5d50e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop