// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::CopyCoefficients(SteerablePyramid const&, std::vector<double, std::allocator<double>>)
void SteerablePyramid::CopyCoefficients(const SteerablePyramid& sp, vector<Float_t> thresholds)
{
	assert(width_ == sp.width_ && height_ == sp.height_ && numLevels_ == sp.numLevels_);
	assert(thresholds.size() == numLevels_);
	
	for (int level = 0; level < numLevels_; level++)
	{
		int totalPixels = (width_ * height_) / (int)(pow(4, level));
		Float_t threshold = thresholds[level];
		
		//cout << "Level/Threshold: " << level << "    " << threshold << endl;
		
		//A threshold of -1 is a flag to not copy this level
		if (threshold == -1)
			continue;
		
		//A lower threshold is more likely to cause a change and causes a more drastic change.
		//A threshold of zero changes all coefficients and sets them precisely to sp's coefficients.
		
		//Use threshold as a diff between the two coefficients
		for (int i = 0; i < totalPixels; i++)
		{
			if (level == 0)
			{
				if (h0Coeffs_[i] < sp.h0Coeffs_[i] - threshold)
					h0Coeffs_[i] = sp.h0Coeffs_[i] - threshold;
				else if (h0Coeffs_[i] > sp.h0Coeffs_[i] + threshold)
					h0Coeffs_[i] = sp.h0Coeffs_[i] + threshold;
			}
			
			if (b1Coeffs_[level][i] < sp.b1Coeffs_[level][i] - threshold)
				b1Coeffs_[level][i] = sp.b1Coeffs_[level][i] - threshold;
			else if (b1Coeffs_[level][i] > sp.b1Coeffs_[level][i] + threshold)
				b1Coeffs_[level][i] = sp.b1Coeffs_[level][i] + threshold;
			
			if (b2Coeffs_[level][i] < sp.b2Coeffs_[level][i] - threshold)
				b2Coeffs_[level][i] = sp.b2Coeffs_[level][i] - threshold;
			else if (b2Coeffs_[level][i] > sp.b2Coeffs_[level][i] + threshold)
				b2Coeffs_[level][i] = sp.b2Coeffs_[level][i] + threshold;
			
			if (b3Coeffs_[level][i] < sp.b3Coeffs_[level][i] - threshold)
				b3Coeffs_[level][i] = sp.b3Coeffs_[level][i] - threshold;
			else if (b3Coeffs_[level][i] > sp.b3Coeffs_[level][i] + threshold)
				b3Coeffs_[level][i] = sp.b3Coeffs_[level][i] + threshold;
			
			if (b4Coeffs_[level][i] < sp.b4Coeffs_[level][i] - threshold)
				b4Coeffs_[level][i] = sp.b4Coeffs_[level][i] - threshold;
			else if (b4Coeffs_[level][i] > sp.b4Coeffs_[level][i] + threshold)
				b4Coeffs_[level][i] = sp.b4Coeffs_[level][i] + threshold;
		}
		
		/*
		//Use threshold as a ratio between the two coefficients
		for (int i = 0; i < totalPixels; i++)
		{
			if (level == 0)
				if (fabs(h0Coeffs_[i]) < fabs(sp.h0Coeffs_[i]) * threshold)
					h0Coeffs_[i] = sp.h0Coeffs_[i];
			if (fabs(b1Coeffs_[level][i]) < fabs(sp.b1Coeffs_[level][i]) * threshold)
				b1Coeffs_[level][i] = sp.b1Coeffs_[level][i];
			if (fabs(b2Coeffs_[level][i]) < fabs(sp.b2Coeffs_[level][i]) * threshold)
				b2Coeffs_[level][i] = sp.b2Coeffs_[level][i];
			if (fabs(b3Coeffs_[level][i]) < fabs(sp.b3Coeffs_[level][i]) * threshold)
				b3Coeffs_[level][i] = sp.b3Coeffs_[level][i];
			if (fabs(b4Coeffs_[level][i]) < fabs(sp.b4Coeffs_[level][i]) * threshold)
				b4Coeffs_[level][i] = sp.b4Coeffs_[level][i];
		}
		*/
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
movl 0x30(%rdi), %eax
cmpl 0x30(%rsi), %eax
jne 0x1916a
movl 0x34(%rdi), %eax
cmpl 0x34(%rsi), %eax
jne 0x1916a
movl 0x38(%rdi), %eax
cmpl 0x38(%rsi), %eax
jne 0x1916a
movq %rsi, 0x10(%rsp)
movslq %eax, %rcx
movq (%rsp), %rsi
movq 0x8(%rsi), %rdx
subq (%rsi), %rdx
sarq $0x3, %rdx
cmpq %rcx, %rdx
jne 0x19189
xorl %r13d, %r13d
movq %rdi, 0x8(%rsp)
cltq
cmpq %rax, %r13
jge 0x1915b
movl 0x30(%rdi), %ebx
movl 0x34(%rdi), %ebp
leal (,%r13,2), %eax
cvtsi2sd %rax, %xmm0
callq 0x3280
movq (%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r13,8), %xmm1
ucomisd 0x9084(%rip), %xmm1     # 0x22070
jne 0x18ffd
jp 0x18ffd
incq %r13
movq 0x8(%rsp), %rdi
movl 0x38(%rdi), %eax
jmp 0x18fb4
imull %ebx, %ebp
cvttsd2si %xmm0, %ecx
movl %ebp, %eax
cltd
idivl %ecx
movq 0x8(%rsp), %r14
movq (%r14), %rcx
movq 0x8(%r14), %rdx
movq 0x10(%rsp), %rbx
movq (%rbx), %rsi
movq 0x8(%rbx), %rdi
movq 0x10(%r14), %r8
movq 0x10(%rbx), %r9
movq 0x18(%r14), %r10
movq 0x18(%rbx), %r11
movq 0x20(%r14), %rbp
movq 0x20(%rbx), %r12
testl %eax, %eax
movl $0x0, %ebx
cmovlel %ebx, %eax
xorl %ebx, %ebx
cmpq %rbx, %rax
je 0x18ff0
testq %r13, %r13
jne 0x1907a
movsd (%rcx,%rbx,8), %xmm0
movsd (%rsi,%rbx,8), %xmm2
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
ja 0x19075
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm3
jbe 0x1907a
movsd %xmm3, (%rcx,%rbx,8)
movq (%rdx,%r13,8), %r14
movsd (%r14,%rbx,8), %xmm0
movq (%rdi,%r13,8), %r15
movsd (%r15,%rbx,8), %xmm2
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
ja 0x190aa
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm3
jbe 0x190b0
movsd %xmm3, (%r14,%rbx,8)
movq (%r8,%r13,8), %r14
movsd (%r14,%rbx,8), %xmm0
movq (%r9,%r13,8), %r15
movsd (%r15,%rbx,8), %xmm2
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
ja 0x190e0
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm3
jbe 0x190e6
movsd %xmm3, (%r14,%rbx,8)
movq (%r10,%r13,8), %r14
movsd (%r14,%rbx,8), %xmm0
movq (%r11,%r13,8), %r15
movsd (%r15,%rbx,8), %xmm2
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
ja 0x19116
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm3
jbe 0x1911c
movsd %xmm3, (%r14,%rbx,8)
movq (%rbp,%r13,8), %r14
movsd (%r14,%rbx,8), %xmm0
movq (%r12,%r13,8), %r15
movsd (%r15,%rbx,8), %xmm2
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
ja 0x1914d
addsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm2, %xmm3
jbe 0x19153
movsd %xmm3, (%r14,%rbx,8)
incq %rbx
jmp 0x19045
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd00b(%rip), %rdi      # 0x2617c
leaq 0xc14a(%rip), %rsi      # 0x252c2
leaq 0xd10d(%rip), %rcx      # 0x2628c
movl $0x6bd, %edx            # imm = 0x6BD
callq 0x31a0
leaq 0xd14f(%rip), %rdi      # 0x262df
leaq 0xc12b(%rip), %rsi      # 0x252c2
leaq 0xd0ee(%rip), %rcx      # 0x2628c
movl $0x6be, %edx            # imm = 0x6BE
callq 0x31a0