// File: kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::GenerateHistograms(int, char*)
void SteerablePyramid::GenerateHistograms(int numBins, char* filename)
{
	vector<Float_t> maxCoeffs, maxThumbnailPixels;
	FindStrongestCoefficients(maxCoeffs, maxThumbnailPixels);
	Float_t maxCoeff = 0;
	for (int i = 0; i < maxCoeffs.size(); i++)
		if (maxCoeffs[i] > maxCoeff)
			maxCoeff = maxCoeffs[i];
	Float_t maxThumbnailPixel = 0;
	for (int i = 0; i < maxThumbnailPixels.size(); i++)
		if (maxThumbnailPixels[i] > maxThumbnailPixel)
			maxThumbnailPixel = maxThumbnailPixels[i];
	
	Float_t binSpan = maxCoeff / numBins;
	
	//Generate coefficient histograms
	vector<vector<int> > coeffHistograms(numLevels_);
	for (int i = 0; i < numLevels_; i++)
	{
		coeffHistograms[i].resize(numBins);
		
		int horDim = width_ / pow(2, i);
		int verDim = height_ / pow(2, i);
		
		if (i == 0)
			AccumulateHistograms(h0Coeffs_, horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b1Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b2Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b3Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
		AccumulateHistograms(b4Coeffs_[i], horDim, verDim, coeffHistograms[i], binSpan);
	}
	
	binSpan = maxThumbnailPixel / numBins;
	
	//Generate thumbnail histograms
	vector<vector<int> > thumbnailHistograms(numLevels_);
	for (int i = 0; i < numLevels_; i++)
	{
		thumbnailHistograms[i].resize(numBins);
		
		int horDim = width_ / pow(2, i + 1);
		int verDim = height_ / pow(2, i + 1);
		
		AccumulateHistograms(l1Coeffs_[i], horDim, verDim, thumbnailHistograms[i], binSpan);
	}
	
	//Dump the histograms to a tab delimited file
	ofstream ofs;
	ofs.open(filename);
	assert(ofs);
	
	cout << "Histograms:" << endl;
	for (int i = 0; i < numBins; i++)
	{
		for (int j = 0; j < numLevels_; j++)
		{
			ofs << coeffHistograms[j][i] << '\t';
			cout << coeffHistograms[j][i] << '\t';
		}
		for (int j = 0; j < numLevels_; j++)
		{
			ofs << thumbnailHistograms[j][i] << '\t';
			cout << thumbnailHistograms[j][i] << '\t';
		}
		ofs << endl;
		
		cout << endl;
	}
	cout << "Done" << endl;
	
	ofs.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x400, %rsp            # imm = 0x400
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0xe240
leaq -0x48(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0xe240
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
movq -0x2e8(%rbp), %rdx
callq 0x2fff0
jmp 0x31eed
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xe5c0
movq %rax, %rcx
movq -0x300(%rbp), %rax
cmpq %rcx, %rax
jae 0x31f6d
movslq -0x64(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xe670
movsd (%rax), %xmm0
ucomisd -0x60(%rbp), %xmm0
jbe 0x31f60
movslq -0x64(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xe670
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x31f60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x328a9
jmp 0x31f62
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x31efc
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movslq -0x74(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xe5c0
movq %rax, %rcx
movq -0x308(%rbp), %rax
cmpq %rcx, %rax
jae 0x31fda
movslq -0x74(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xe670
movsd (%rax), %xmm0
ucomisd -0x70(%rbp), %xmm0
jbe 0x31fcd
movslq -0x74(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xe670
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x31fcf
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x31f7c
movq -0x2f8(%rbp), %rax
movsd -0x60(%rbp), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movslq 0x38(%rax), %rax
movq %rax, -0x318(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x33120
movq -0x318(%rbp), %rsi
movq -0x310(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x33140
jmp 0x3202e
leaq -0x99(%rbp), %rdi
callq 0x331b0
movl $0x0, -0xa0(%rbp)
movq -0x2f8(%rbp), %rcx
movl -0xa0(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x32373
movslq -0xa0(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq %rax, %rdi
movslq -0xc(%rbp), %rsi
callq 0x331f0
jmp 0x3207b
movq -0x2f8(%rbp), %rax
cvtsi2sdl 0x30(%rax), %xmm0
movsd %xmm0, -0x328(%rbp)
movl -0xa0(%rbp), %esi
movl $0x2, %edi
callq 0x1d7f0
movsd %xmm0, -0x320(%rbp)
jmp 0x320a9
movq -0x2f8(%rbp), %rax
movsd -0x320(%rbp), %xmm1
movsd -0x328(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0xa4(%rbp)
cvtsi2sdl 0x34(%rax), %xmm0
movsd %xmm0, -0x338(%rbp)
movl -0xa0(%rbp), %esi
movl $0x2, %edi
callq 0x1d7f0
movsd %xmm0, -0x330(%rbp)
jmp 0x320f5
movsd -0x330(%rbp), %xmm1
movsd -0x338(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0xa0(%rbp)
jne 0x321b5
movq -0x2f8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x348(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x340(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x33c(%rbp)
movslq -0xa0(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq -0x2f8(%rbp), %rdi
movq -0x348(%rbp), %rsi
movl -0x340(%rbp), %edx
movl -0x33c(%rbp), %ecx
movq %rax, %r8
movsd -0x80(%rbp), %xmm0
callq 0x328d0
jmp 0x32185
jmp 0x321b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x331b0
jmp 0x328a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3289d
movq -0x2f8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xa0(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movq %rax, -0x358(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x350(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x34c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq -0x2f8(%rbp), %rdi
movq -0x358(%rbp), %rsi
movl -0x350(%rbp), %edx
movl -0x34c(%rbp), %ecx
movq %rax, %r8
movsd -0x80(%rbp), %xmm0
callq 0x328d0
jmp 0x3221f
movq -0x2f8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xa0(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movq %rax, -0x368(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x360(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x35c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq -0x2f8(%rbp), %rdi
movq -0x368(%rbp), %rsi
movl -0x360(%rbp), %edx
movl -0x35c(%rbp), %ecx
movq %rax, %r8
movsd -0x80(%rbp), %xmm0
callq 0x328d0
jmp 0x32289
movq -0x2f8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xa0(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movq %rax, -0x378(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x370(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x36c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq -0x2f8(%rbp), %rdi
movq -0x378(%rbp), %rsi
movl -0x370(%rbp), %edx
movl -0x36c(%rbp), %ecx
movq %rax, %r8
movsd -0x80(%rbp), %xmm0
callq 0x328d0
jmp 0x322f3
movq -0x2f8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xa0(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movq %rax, -0x388(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0x380(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x37c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq -0x2f8(%rbp), %rdi
movq -0x388(%rbp), %rsi
movl -0x380(%rbp), %edx
movl -0x37c(%rbp), %ecx
movq %rax, %r8
movsd -0x80(%rbp), %xmm0
callq 0x328d0
jmp 0x3235d
jmp 0x3235f
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x32044
movq -0x2f8(%rbp), %rax
movsd -0x70(%rbp), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movslq 0x38(%rax), %rax
movq %rax, -0x398(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x390(%rbp)
callq 0x33120
movq -0x398(%rbp), %rsi
movq -0x390(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x33140
jmp 0x323c7
leaq -0xc1(%rbp), %rdi
callq 0x331b0
movl $0x0, -0xc8(%rbp)
movq -0x2f8(%rbp), %rcx
movl -0xc8(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x3255e
movslq -0xc8(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x331d0
movq %rax, %rdi
movslq -0xc(%rbp), %rsi
callq 0x331f0
jmp 0x32414
movq -0x2f8(%rbp), %rax
cvtsi2sdl 0x30(%rax), %xmm0
movsd %xmm0, -0x3a8(%rbp)
movl -0xc8(%rbp), %esi
incl %esi
movl $0x2, %edi
callq 0x1d7f0
movsd %xmm0, -0x3a0(%rbp)
jmp 0x32444
movq -0x2f8(%rbp), %rax
movsd -0x3a0(%rbp), %xmm1
movsd -0x3a8(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0xcc(%rbp)
cvtsi2sdl 0x34(%rax), %xmm0
movsd %xmm0, -0x3b8(%rbp)
movl -0xc8(%rbp), %esi
incl %esi
movl $0x2, %edi
callq 0x1d7f0
movsd %xmm0, -0x3b0(%rbp)
jmp 0x32492
movq -0x2f8(%rbp), %rax
movsd -0x3b0(%rbp), %xmm1
movsd -0x3b8(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0xd0(%rbp)
movq 0x28(%rax), %rax
movslq -0xc8(%rbp), %rsi
movq (%rax,%rsi,8), %rax
movq %rax, -0x3c8(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x3c0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, -0x3bc(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x331d0
movq -0x2f8(%rbp), %rdi
movq -0x3c8(%rbp), %rsi
movl -0x3c0(%rbp), %edx
movl -0x3bc(%rbp), %ecx
movq %rax, %r8
movsd -0x80(%rbp), %xmm0
callq 0x328d0
jmp 0x3251a
jmp 0x3251c
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x323dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc1(%rbp), %rdi
callq 0x331b0
jmp 0x3289d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x32891
leaq -0x2d0(%rbp), %rdi
callq 0x45e0
jmp 0x3256c
movq -0x18(%rbp), %rsi
leaq -0x2d0(%rbp), %rdi
movl $0x10, %edx
callq 0x4070
jmp 0x32583
movq -0x2d0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2d0(%rbp,%rax), %rdi
callq 0x44a0
movb %al, -0x3c9(%rbp)
jmp 0x325a3
movb -0x3c9(%rbp), %al
testb $0x1, %al
jne 0x325af
jmp 0x325b1
jmp 0x325ed
leaq 0x17d02(%rip), %rdi     # 0x4a2ba
leaq 0x19d97(%rip), %rsi     # 0x4c356
movl $0x7f3, %edx            # imm = 0x7F3
leaq 0x1af00(%rip), %rcx     # 0x4d4cb
callq 0x4240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x4540
jmp 0x32891
movq 0x279dc(%rip), %rdi     # 0x59fd0
leaq 0x1af07(%rip), %rsi     # 0x4d502
callq 0x4390
movq %rax, -0x3d8(%rbp)
jmp 0x32609
movq -0x3d8(%rbp), %rdi
movq 0x279a1(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x3261e
movl $0x0, -0x2d4(%rbp)
movl -0x2d4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x32813
movl $0x0, -0x2d8(%rbp)
movq -0x2f8(%rbp), %rcx
movl -0x2d8(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x32705
movslq -0x2d8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq %rax, %rdi
movslq -0x2d4(%rbp), %rsi
callq 0x33280
movl (%rax), %esi
leaq -0x2d0(%rbp), %rdi
callq 0x4600
movq %rax, -0x3e0(%rbp)
jmp 0x32690
movq -0x3e0(%rbp), %rdi
movl $0x9, %esi
callq 0x4440
jmp 0x326a3
movslq -0x2d8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x331d0
movq %rax, %rdi
movslq -0x2d4(%rbp), %rsi
callq 0x33280
movl (%rax), %esi
movq 0x27902(%rip), %rdi     # 0x59fd0
callq 0x4600
movq %rax, -0x3e8(%rbp)
jmp 0x326dc
movq -0x3e8(%rbp), %rdi
movl $0x9, %esi
callq 0x4440
jmp 0x326ef
jmp 0x326f1
movl -0x2d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d8(%rbp)
jmp 0x32641
movl $0x0, -0x2dc(%rbp)
movq -0x2f8(%rbp), %rcx
movl -0x2dc(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x327d3
movslq -0x2dc(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x331d0
movq %rax, %rdi
movslq -0x2d4(%rbp), %rsi
callq 0x33280
movl (%rax), %esi
leaq -0x2d0(%rbp), %rdi
callq 0x4600
movq %rax, -0x3f0(%rbp)
jmp 0x3275e
movq -0x3f0(%rbp), %rdi
movl $0x9, %esi
callq 0x4440
jmp 0x32771
movslq -0x2dc(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x331d0
movq %rax, %rdi
movslq -0x2d4(%rbp), %rsi
callq 0x33280
movl (%rax), %esi
movq 0x27834(%rip), %rdi     # 0x59fd0
callq 0x4600
movq %rax, -0x3f8(%rbp)
jmp 0x327aa
movq -0x3f8(%rbp), %rdi
movl $0x9, %esi
callq 0x4440
jmp 0x327bd
jmp 0x327bf
movl -0x2dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2dc(%rbp)
jmp 0x3270f
movq 0x277de(%rip), %rsi     # 0x59fb8
leaq -0x2d0(%rbp), %rdi
callq 0x43d0
jmp 0x327e8
movq 0x277e1(%rip), %rdi     # 0x59fd0
movq 0x277c2(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x327fd
jmp 0x327ff
movl -0x2d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2d4(%rbp)
jmp 0x32628
movq 0x277b6(%rip), %rdi     # 0x59fd0
leaq 0x1aced(%rip), %rsi     # 0x4d50e
callq 0x4390
movq %rax, -0x400(%rbp)
jmp 0x3282f
movq -0x400(%rbp), %rdi
movq 0x2777b(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x32844
leaq -0x2d0(%rbp), %rdi
callq 0x4520
jmp 0x32852
leaq -0x2d0(%rbp), %rdi
callq 0x4540
leaq -0xc0(%rbp), %rdi
callq 0x332a0
leaq -0x98(%rbp), %rdi
callq 0x332a0
leaq -0x48(%rbp), %rdi
callq 0xe260
leaq -0x30(%rbp), %rdi
callq 0xe260
addq $0x400, %rsp            # imm = 0x400
popq %rbp
retq
leaq -0xc0(%rbp), %rdi
callq 0x332a0
leaq -0x98(%rbp), %rdi
callq 0x332a0
leaq -0x48(%rbp), %rdi
callq 0xe260
leaq -0x30(%rbp), %rdi
callq 0xe260
movq -0x50(%rbp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)