// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x94d10
movq -0x58(%rbp), %rax
movq %rax, %rdi
addq $0x208, %rdi            # imm = 0x208
movslq 0x138(%rax), %rsi
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
leaq -0x44(%rbp), %rdx
callq 0x84b00
movq -0x58(%rbp), %rax
movl $0x0, 0x1b8(%rax)
movl $0x0, -0xc(%rbp)
movq -0x58(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0x5c(%rbp)
addq $0x158, %rdi            # imm = 0x158
callq 0xe0920
movq %rax, %rcx
movl -0x5c(%rbp), %eax
cmpl %ecx, %eax
jge 0xdd5bc
movq -0x58(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movq -0x58(%rbp), %rdi
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq %rdi, %rax
addq $0x238, %rax            # imm = 0x238
movq %rax, -0x80(%rbp)
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movq -0x80(%rbp), %rdi
movslq 0x8(%rax), %rsi
callq 0xedb0
movq -0x58(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movq %rdi, %rax
addq $0x238, %rax            # imm = 0x238
movq %rax, -0x78(%rbp)
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movq -0x78(%rbp), %rdi
movslq 0xc(%rax), %rsi
callq 0xedb0
movsd -0x70(%rbp), %xmm2
movsd -0x68(%rbp), %xmm0
addsd (%rax), %xmm2
movsd 0x114ad9(%rip), %xmm1   # 0x1f2060
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xdd5ac
movq -0x58(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movl $0x1, 0x20(%rax)
jmp 0xdd5ae
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xdd4ca
jmp 0xdd5be
movq -0x58(%rbp), %rdi
callq 0xdd8d0
movq -0x58(%rbp), %rsi
movl %eax, -0x10(%rbp)
movq %rsi, %rdi
addq $0x1c0, %rdi            # imm = 0x1C0
addq $0x1b8, %rsi            # imm = 0x1B8
callq 0xd1b0
movq -0x58(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0xdd940
movq -0x58(%rbp), %rax
movl 0x1b8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1b8(%rax)
movq -0x58(%rbp), %rdi
callq 0xdd8d0
cmpl $-0x1, %eax
jne 0xdd5be
movq -0x58(%rbp), %rax
movq %rax, %rdi
addq $0x250, %rdi            # imm = 0x250
movslq 0x1b8(%rax), %rsi
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x50(%rbp), %rdx
callq 0x85210
movl $0x0, -0xc(%rbp)
movq -0x58(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0x84(%rbp)
addq $0x208, %rdi            # imm = 0x208
callq 0x10090
movq %rax, %rcx
movl -0x84(%rbp), %eax
cmpl %ecx, %eax
jge 0xdd73c
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x250, %rax            # imm = 0x250
movq %rax, -0x98(%rbp)
addq $0x208, %rdi            # imm = 0x208
movslq -0xc(%rbp), %rsi
callq 0xed60
movq -0x98(%rbp), %rdi
movslq (%rax), %rsi
callq 0xedb0
movq -0x58(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
addq $0x238, %rdi            # imm = 0x238
movslq -0xc(%rbp), %rsi
callq 0xedb0
movsd -0x90(%rbp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xdd72c
movq -0x58(%rbp), %rdi
addq $0x238, %rdi            # imm = 0x238
movslq -0xc(%rbp), %rsi
callq 0xedb0
movq -0x58(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
movq %rdi, %rax
addq $0x250, %rax            # imm = 0x250
movq %rax, -0xa8(%rbp)
addq $0x208, %rdi            # imm = 0x208
movslq -0xc(%rbp), %rsi
callq 0xed60
movq -0xa8(%rbp), %rdi
movslq (%rax), %rsi
callq 0xedb0
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0xdd72e
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xdd63e
movl $0x0, -0xc(%rbp)
movq -0x58(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0xac(%rbp)
addq $0x60, %rdi
callq 0x10100
movq %rax, %rcx
movl -0xac(%rbp), %eax
cmpl %ecx, %eax
jge 0xdd7c3
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x1d8, %rax            # imm = 0x1D8
movq %rax, -0xb8(%rbp)
movq %rdi, %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, -0xc0(%rbp)
addq $0x140, %rdi            # imm = 0x140
movslq -0xc(%rbp), %rsi
callq 0xed60
movq -0xc0(%rbp), %rdi
movslq (%rax), %rsi
callq 0xed60
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0xd1b0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xdd743
movl $0x0, -0xc(%rbp)
movq -0x58(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0xc4(%rbp)
addq $0x158, %rdi            # imm = 0x158
callq 0xe0920
movq %rax, %rcx
movl -0xc4(%rbp), %eax
cmpl %ecx, %eax
jge 0xdd8c6
movq -0x58(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
cmpl $0x1, 0x20(%rax)
je 0xdd8b6
movq -0x58(%rbp), %rdi
movq %rdi, %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, -0xd8(%rbp)
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movq -0xd8(%rbp), %rdi
movslq 0x8(%rax), %rsi
callq 0xed60
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq %rdi, %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, -0xd0(%rbp)
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movq -0xd0(%rbp), %rdi
movslq 0xc(%rax), %rsi
callq 0xed60
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x34(%rbp)
addq $0x158, %rdi            # imm = 0x158
movslq -0xc(%rbp), %rsi
callq 0xe0950
movq -0x58(%rbp), %rdi
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
addq $0x1f0, %rdi            # imm = 0x1F0
leaq -0x40(%rbp), %rsi
callq 0xe08b0
jmp 0xdd8b8
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xdd7ca
addq $0xe0, %rsp
popq %rbp
retq
nop