// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movsd %xmm0, 0x8(%rdi)
movsd %xmm1, 0x10(%rsp)
movsd %xmm1, 0x10(%rdi)
leaq 0x20(%rdi), %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rdi)
andq $0x0, 0x30(%rdi)
leaq 0x50(%rdi), %rax
movq %rax, 0x20(%rsp)
movupd %xmm0, 0x50(%rdi)
andq $0x0, 0x60(%rdi)
movq 0x127f7(%rip), %rdi     # 0x17fc8
leaq 0xbd89(%rip), %rsi      # 0x11561
callq 0x3260
movq %rax, %rdi
callq 0x3110
movq 0x127dc(%rip), %rdi     # 0x17fc8
leaq 0xbd99(%rip), %rsi      # 0x1158c
callq 0x3260
movl %ebp, %r12d
movq %rax, %rdi
movq %r12, %rsi
callq 0x31a0
leaq 0xbd8c(%rip), %rsi      # 0x11599
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
movsd 0x18(%rsp), %xmm0
callq 0x33a0
leaq 0xbd7a(%rip), %rsi      # 0x115a4
movq %rax, %rdi
callq 0x3260
movq %rax, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x33a0
cmpl $0x1, %ebp
jbe 0x59a5
xorpd %xmm0, %xmm0
ucomisd 0x18(%rsp), %xmm0
jae 0x59dc
ucomisd 0x10(%rsp), %xmm0
jae 0x59dc
movl (%r15), %eax
decl %eax
shrl %eax
movl %eax, 0x18(%r15)
movq 0x12751(%rip), %rdi     # 0x17fc8
leaq 0xbda1(%rip), %rsi      # 0x1161f
callq 0x3260
movl 0x18(%r15), %esi
movq %rax, %rdi
callq 0x3410
movq %rax, %rdi
callq 0x3110
xorpd %xmm0, %xmm0
movq %rbx, %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r12, %rcx
callq 0x9de8
xorl %r13d, %r13d
cmpq %r12, %r13
je 0x592a
xorl %ebp, %ebp
cmpq %r12, %rbp
je 0x5925
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x5920
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
cvtsi2sd %rcx, %xmm0
orpd 0xb7c1(%rip), %xmm0     # 0x110b0
movsd 0x8(%r15), %xmm1
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm2, %xmm0
callq 0x3430
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x9ed2
incq %r14
jmp 0x58be
incq %rbp
jmp 0x58b6
incq %r13
jmp 0x58af
movsd 0x10(%r15), %xmm0
mulsd 0xb6f0(%rip), %xmm0     # 0x11028
movsd %xmm0, 0x10(%rsp)
divsd 0xb6ea(%rip), %xmm0     # 0x11030
movsd %xmm0, 0x28(%rsp)
xorpd %xmm1, %xmm1
leaq 0x30(%rsp), %r14
movq 0x20(%rsp), %r12
movsd 0x10(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x5996
movsd 0x10(%r15), %xmm0
movsd %xmm1, 0x18(%rsp)
callq 0xa116
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0xa430
movsd 0x18(%rsp), %xmm1
addsd 0x28(%rsp), %xmm1
jmp 0x595a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x3120
movq %rax, %r15
leaq 0xbbfd(%rip), %rsi      # 0x115b4
leaq 0xf(%rsp), %rdx
movq %rax, %rdi
callq 0x30d0
leaq 0x123bd(%rip), %rsi     # 0x17d88
movq 0x125de(%rip), %rdx     # 0x17fb0
movq %r15, %rdi
callq 0x3400
jmp 0x5a11
pushq $0x20
popq %rdi
callq 0x3120
movq %rax, %r15
leaq 0xbbf8(%rip), %rsi      # 0x115e6
leaq 0xe(%rsp), %rdx
movq %rax, %rdi
callq 0x30d0
leaq 0x12386(%rip), %rsi     # 0x17d88
movq 0x125a7(%rip), %rdx     # 0x17fb0
movq %r15, %rdi
callq 0x3400
jmp 0x5a28
jmp 0x5a17
jmp 0x5a28
movq %rax, %r14
movq %r15, %rdi
callq 0x31d0
jmp 0x5a2b
jmp 0x5a28
jmp 0x5a28
movq %rax, %r14
movq 0x20(%rsp), %rdi
callq 0xe210
movq %rbx, %rdi
callq 0xe210
movq %r14, %rdi
callq 0x3420
nop