// File: /workspace/github_cpp_makefile_star2_O1/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 0x161a1(%rip), %r14     # 0x1cfc8
leaq 0x1077e(%rip), %rsi     # 0x175ac
movl $0x2a, %edx
movq %r14, %rdi
movq %r13, 0x8(%rsp)
callq 0x3300
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq 0x1616a(%rip), %rdi     # 0x1cfc8
callq 0x3040
movq %rax, %rdi
callq 0x31e0
movq 0x16156(%rip), %rdi     # 0x1cfc8
leaq 0x1075e(%rip), %rsi     # 0x175d7
movl $0xc, %edx
callq 0x3300
movl %ebp, %r12d
movq 0x1613b(%rip), %rdi     # 0x1cfc8
movq %r12, %rsi
callq 0x31d0
movq %rax, %r14
leaq 0x10745(%rip), %rsi     # 0x175e4
movl $0xa, %edx
movq %rax, %rdi
callq 0x3300
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x33d0
movq %rax, %r14
leaq 0x1072b(%rip), %rsi     # 0x175ef
movl $0xf, %edx
movq %rax, %rdi
callq 0x3300
movq %r14, %rdi
movsd (%rsp), %xmm0
callq 0x33d0
cmpl $0x1, %ebp
jbe 0x70c7
xorpd %xmm0, %xmm0
ucomisd 0x10(%rsp), %xmm0
jae 0x710e
ucomisd (%rsp), %xmm0
jae 0x710e
movl (%r15), %eax
decl %eax
shrl %eax
movl %eax, 0x18(%r15)
movq 0x160b4(%rip), %rdi     # 0x1cfc8
leaq 0x1074f(%rip), %rsi     # 0x1766a
movl $0x8, %edx
callq 0x3300
movl 0x18(%r15), %esi
movq 0x16098(%rip), %rdi     # 0x1cfc8
callq 0x3430
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
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 0xd92e
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 0x10115(%rip), %xmm0    # 0x170c0
movsd 0x8(%r15), %xmm1
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
callq 0x3450
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xda90
incq %r14
cmpq %r14, %r12
jne 0x6f7c
incq %rbp
cmpq %r12, %rbp
jne 0x6f79
incq %r13
cmpq %r12, %r13
jne 0x6f77
movsd 0x10(%r15), %xmm0
mulsd 0x1002b(%rip), %xmm0    # 0x17028
xorpd %xmm1, %xmm1
movsd %xmm0, (%rsp)
ucomisd %xmm1, %xmm0
movq 0x8(%rsp), %r14
jb 0x70b8
movsd (%rsp), %xmm0
divsd 0x1000e(%rip), %xmm0    # 0x17030
movsd %xmm0, 0x28(%rsp)
leaq 0x30(%rsp), %r12
movsd 0x10(%r15), %xmm2
movapd %xmm1, 0x10(%rsp)
movapd %xmm1, %xmm0
andpd 0x1008b(%rip), %xmm0    # 0x170d0
movapd %xmm2, %xmm3
mulsd 0xffd7(%rip), %xmm3     # 0x17028
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm0
ja 0x7074
divsd %xmm2, %xmm0
mulsd %xmm0, %xmm0
mulsd 0xffcd(%rip), %xmm0     # 0x17038
callq 0x3450
movapd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movq 0x58(%r15), %rsi
cmpq 0x60(%r15), %rsi
je 0x7092
movsd %xmm1, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%r15)
jmp 0x709d
movq %r14, %rdi
movq %r12, %rdx
callq 0xe0fa
movapd 0x10(%rsp), %xmm1
addsd 0x28(%rsp), %xmm1
movsd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x702d
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)
movb $0x1, %bpl
leaq 0x1051a(%rip), %rsi     # 0x175ff
leaq 0x10544(%rip), %rdx     # 0x17630
movq %r14, %rdi
callq 0x131be
xorl %ebp, %ebp
leaq 0x15c83(%rip), %rsi     # 0x1cd80
movq 0x15ea4(%rip), %rdx     # 0x1cfa8
movq %r14, %rdi
callq 0x3420
jmp 0x7153
movl $0x20, %edi
callq 0x3150
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
movb $0x1, %bpl
leaq 0x10505(%rip), %rsi     # 0x17631
leaq 0x10536(%rip), %rdx     # 0x17669
movq %r14, %rdi
callq 0x131be
xorl %ebp, %ebp
leaq 0x15c3c(%rip), %rsi     # 0x1cd80
movq 0x15e5d(%rip), %rdx     # 0x1cfa8
movq %r14, %rdi
callq 0x3420
jmp 0x7155
movq %rax, %r15
testb %bpl, %bpl
je 0x716e
movq %r14, %rdi
callq 0x3210
jmp 0x716e
jmp 0x716b
jmp 0x716b
movq %rax, %r15
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x7180
callq 0x3290
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x718d
callq 0x3290
movq %r15, %rdi
callq 0x3440
nop