// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdx, -0x40(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x2d(%rbp)
jne 0x2fa7a
movq -0x38(%rbp), %rax
movl 0x34(%rax), %ecx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpl 0x34(%rdx), %ecx
movb %al, -0x2d(%rbp)
jne 0x2fa7a
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x38(%rcx), %eax
sete %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0x2fa83
jmp 0x2fa85
jmp 0x2faa4
leaq 0x1d812(%rip), %rdi     # 0x4d29e
leaq 0x1c8c3(%rip), %rsi     # 0x4c356
movl $0x6bd, %edx            # imm = 0x6BD
leaq 0x1d90f(%rip), %rcx     # 0x4d3ae
callq 0x4240
movq -0x40(%rbp), %rdi
callq 0xe5c0
movq -0x38(%rbp), %rcx
movslq 0x38(%rcx), %rcx
cmpq %rcx, %rax
jne 0x2fabc
jmp 0x2fadb
leaq 0x1d93e(%rip), %rdi     # 0x4d401
leaq 0x1c88c(%rip), %rsi     # 0x4c356
movl $0x6be, %edx            # imm = 0x6BE
leaq 0x1d8d8(%rip), %rcx     # 0x4d3ae
callq 0x4240
movl $0x0, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x2ffdd
movq -0x38(%rbp), %rcx
movl 0x30(%rcx), %eax
imull 0x34(%rcx), %eax
movl %eax, -0x44(%rbp)
movl -0x1c(%rbp), %esi
movl $0x4, %edi
callq 0x1d7f0
movl -0x44(%rbp), %eax
movq -0x40(%rbp), %rdi
cvttsd2si %xmm0, %ecx
cltd
idivl %ecx
movl %eax, -0x20(%rbp)
movslq -0x1c(%rbp), %rsi
callq 0xe670
movsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x194fb(%rip), %xmm1    # 0x49038
ucomisd %xmm1, %xmm0
jne 0x2fb4a
jp 0x2fb4a
jmp 0x2ffcf
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x2ffcd
cmpl $0x0, -0x1c(%rbp)
jne 0x2fc0d
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2fbb9
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd -0x28(%rbp), %xmm0
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fc0b
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
addsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2fc09
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
addsd -0x28(%rbp), %xmm0
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fc0b
jmp 0x2fc0d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2fc83
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd -0x28(%rbp), %xmm0
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fcf9
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
addsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2fcf7
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
addsd -0x28(%rbp), %xmm0
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fcf9
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2fd6f
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd -0x28(%rbp), %xmm0
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fde5
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
addsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2fde3
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
addsd -0x28(%rbp), %xmm0
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fde5
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2fe5b
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd -0x28(%rbp), %xmm0
movq 0x18(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fed1
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
addsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2fecf
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
addsd -0x28(%rbp), %xmm0
movq 0x18(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2fed1
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2ff47
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd -0x28(%rbp), %xmm0
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2ffbd
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
addsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2ffbb
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x2c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
addsd -0x28(%rbp), %xmm0
movq 0x20(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2ffbd
jmp 0x2ffbf
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2fb51
jmp 0x2ffcf
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2fae2
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)