// File: /workspace/github_cpp_makefile_star2_O3/spatialfruitsalad[P]volume2position/./bilateral.hpp
// Function: bilateralFilter::bilateralFilter(unsigned int, double, double)
bilateralFilter(unsigned int masksize, double sigma, double similarity) : m_masksize(masksize), m_sigma(sigma), m_sigmaSimilarity(similarity)
    {
        std::cout << "creating bilateral Filter with parameters:" << std::endl;
        std::cout << "\tmasksize = " << masksize << "\n\tsigma = " << sigma << "\n\tsimilarity = " << similarity;
        // initial checks
        if(masksize <= 1)
        {
            throw std::string("bilateral filter: masksize must be larger than 1!");
        }
        if (sigma <= 0 || similarity <= 0)
        {
            throw std::string("bilateral filter: sigma/similarity must be larger than 0");
        }


        // create mask
        tol = (m_masksize-1)/2;
        std::cout << "\n\ttol = " << tol << std::endl;
        mask.initialise (masksize, masksize, masksize, 0);
        double sum = 0;
        
        // precalculate gaussian mask (this speeds up the process alot
        for (unsigned int k = 0; k != masksize; ++k)
        {
            for (unsigned int j = 0; j != masksize; ++j)
            {
                for (unsigned int i = 0; i != masksize; ++i)
                {
                    double distance_square = (i-tol)*(i-tol) + (j-tol)*(j-tol) + (k-tol)*(k-tol);
                    double val = exp(-1*distance_square/(2*m_sigma*m_sigma));
                    mask.set(i,j,k, val);
                    sum += val;
                }
            }
        }

        // creating gauss table (also a big speedup)
        double x0 = 0;
        double x1 = 4 * m_sigmaSimilarity; // dumb cutoff

        // prerendered version of the gauss
        unsigned int steps = 500;
        double dx = (x1 - x0)/static_cast<double>(steps + 1);
        for (double x = x0; x <= x1; x += dx)
        {
            gaussTable.push_back(gauss(m_sigmaSimilarity, x));
        }

    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq %rdi, %r15
movl %esi, (%rdi)
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x8(%rdi)
movsd %xmm1, (%rsp)
movsd %xmm1, 0x10(%rdi)
leaq 0x20(%rdi), %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rdi)
xorl %eax, %eax
movq %rax, 0x30(%rdi)
leaq 0x50(%rdi), %r13
movupd %xmm0, 0x50(%rdi)
movq %rax, 0x60(%rdi)
movq 0x1624d(%rip), %r14     # 0x1cfc8
leaq 0x1081a(%rip), %rsi     # 0x1759c
movl $0x2a, %edx
movq %r14, %rdi
movq %r13, 0x8(%rsp)
callq 0x32f0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq 0x16216(%rip), %rdi     # 0x1cfc8
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x16202(%rip), %rdi     # 0x1cfc8
leaq 0x107fa(%rip), %rsi     # 0x175c7
movl $0xc, %edx
callq 0x32f0
movl %ebp, %r12d
movq 0x161e7(%rip), %rdi     # 0x1cfc8
movq %r12, %rsi
callq 0x31d0
movq %rax, %r14
leaq 0x107e1(%rip), %rsi     # 0x175d4
movl $0xa, %edx
movq %rax, %rdi
callq 0x32f0
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x33c0
movq %rax, %r14
leaq 0x107c7(%rip), %rsi     # 0x175df
movl $0xf, %edx
movq %rax, %rdi
callq 0x32f0
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x33c0
cmpl $0x1, %ebp
jbe 0x701b
xorpd %xmm0, %xmm0
ucomisd 0x10(%rsp), %xmm0
jae 0x705d
ucomisd (%rsp), %xmm0
jae 0x705d
movl (%r15), %eax
decl %eax
shrl %eax
movl %eax, 0x18(%r15)
movq 0x16160(%rip), %rdi     # 0x1cfc8
leaq 0x107eb(%rip), %rsi     # 0x1765a
movl $0x8, %edx
callq 0x32f0
movl 0x18(%r15), %esi
movq 0x16144(%rip), %rdi     # 0x1cfc8
callq 0x3420
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31e0
xorpd %xmm0, %xmm0
movq %rbx, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r12, %rcx
callq 0xd802
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r14d, %r14d
movl 0x18(%r15), %eax
movl %r14d, %ecx
subl %eax, %ecx
imull %ecx, %ecx
movl %ebp, %edx
subl %eax, %edx
imull %edx, %edx
addl %ecx, %edx
movl %r13d, %ecx
subl %eax, %ecx
imull %ecx, %ecx
addl %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
orpd 0x101c1(%rip), %xmm0    # 0x170c0
movsd 0x8(%r15), %xmm1
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
callq 0x3440
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xd968
incq %r14
cmpq %r14, %r12
jne 0x6ed0
incq %rbp
cmpq %r12, %rbp
jne 0x6ecd
incq %r13
cmpq %r12, %r13
jne 0x6ecb
movsd 0x10(%r15), %xmm0
mulsd 0x100d7(%rip), %xmm0    # 0x17028
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
ucomisd %xmm1, %xmm0
movq 0x8(%rsp), %r14
jb 0x700c
movsd (%rsp), %xmm0
divsd 0x100ba(%rip), %xmm0    # 0x17030
movsd %xmm0, 0x28(%rsp)
leaq 0x30(%rsp), %r12
movsd 0x10(%r15), %xmm2
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
andpd 0x10137(%rip), %xmm0    # 0x170d0
movapd %xmm2, %xmm3
mulsd 0x10083(%rip), %xmm3    # 0x17028
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm0
ja 0x6fc8
divsd %xmm2, %xmm0
mulsd %xmm0, %xmm0
mulsd 0x10079(%rip), %xmm0    # 0x17038
callq 0x3440
movapd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movq 0x58(%r15), %rsi
cmpq 0x60(%r15), %rsi
je 0x6fe6
movsd %xmm1, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%r15)
jmp 0x6ff1
movq %r14, %rdi
movq %r12, %rdx
callq 0xdfe2
movapd 0x10(%rsp), %xmm1
addsd 0x28(%rsp), %xmm1
movsd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x6f81
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x3150
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
leaq 0x105b9(%rip), %rsi     # 0x175ef
leaq 0x105e3(%rip), %rdx     # 0x17620
movq %r14, %rdi
callq 0x13074
leaq 0x15d34(%rip), %rsi     # 0x1cd80
movq 0x15f55(%rip), %rdx     # 0x1cfa8
movq %r14, %rdi
callq 0x3410
jmp 0x709d
movl $0x20, %edi
callq 0x3150
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
leaq 0x105a9(%rip), %rsi     # 0x17621
leaq 0x105da(%rip), %rdx     # 0x17659
movq %r14, %rdi
callq 0x13074
leaq 0x15cf2(%rip), %rsi     # 0x1cd80
movq 0x15f13(%rip), %rdx     # 0x1cfa8
movq %r14, %rdi
callq 0x3410
jmp 0x70b4
jmp 0x70a3
jmp 0x70b4
movq %rax, %r15
movq %r14, %rdi
callq 0x3210
jmp 0x70b7
jmp 0x70b4
jmp 0x70b4
movq %rax, %r15
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x70c9
callq 0x3280
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x70d6
callq 0x3280
movq %r15, %rdi
callq 0x3430