// File: spatialfruitsalad[P]volume2position/./selectedAreaHistogram.hpp
// Function: void selectedAreaHistogram::Process<unsigned short>(tomogram3d<unsigned short>&, std::vector<double, std::allocator<double>>&, std::vector<double, std::allocator<double>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned int)
void Process (tomogram3d<VALUE>& t, std::vector<double>& binvec, std::vector<double>& histvec, std::string foldername, unsigned int bins = 150)
    {
        std::cout << "start processing tomogram" << std::endl;

        unsigned int nx, ny, nz;
        nx = t.get_sx();
        ny = t.get_sy();
        nz = t.get_sz();

        std::vector<VALUE> greyvalues;
        long double mean = 0.0;
        unsigned int pixelsCounted = 0;
        // get all selected areas and create a vector of all grey values
        for (unsigned long k = 0; k != nz; ++k)
        for (unsigned long j = 0; j != ny; ++j)
        for (unsigned long i = 0; i != nx; ++i)
        {
            // check if the current voxel is in one of the areas
            for(auto it = m_areas.begin(); it != m_areas.end(); ++it)
            {
                if((*it).contains(i,j,k))
                {
                    pixelsCounted++;           
                    VALUE v = t.get(i,j,k);
                    greyvalues.push_back(v);
                    mean += v;
                }
            }
        }
        std::cout << "voxels counted: " << pixelsCounted << " which is a fraction of " << static_cast<double>(pixelsCounted)/static_cast<double>((nx*ny*nz)) << " of all voxels" << std::endl;
        mean /= static_cast<double>(pixelsCounted);
        std::cout << "mean value of: " << mean << std::endl;

        auto min =  (*std::min_element(greyvalues.begin(), greyvalues.end()));
        auto max =  (*std::max_element(greyvalues.begin(), greyvalues.end()));
        std::cout << "min: " << static_cast<int>(min) << std::endl << "max: " << static_cast<int>(max) << std::endl;

        auto diff = max - min;
        // create a histogram of all selected grey values
        long double binsize = static_cast<long double>(diff)/static_cast<long double>(bins);

        binvec.resize(bins + 1, 0);
        for (size_t i = 0; i != binvec.size(); ++i)
        {
           double gv = min + i * binsize;
           binvec.at(i) = gv;
        }
        histvec.resize(bins + 1, 0);
        for(auto n : greyvalues)
        {
            long double u = static_cast<long double>(n - min);
            long double v = static_cast<long double>(binsize);
            size_t idx = static_cast<size_t>(u/v);
            histvec.at(idx) += 1;
        }

        {
        std::cout << "write selected Area Histogram" << std::endl;
        std::ofstream out(foldername + "/selectedAreaHist.dat");
        for (size_t i = 0; i != histvec.size(); ++i)
        {
            long double gv = binvec.at(i);
            auto f = histvec.at(i);
            out << gv << " " << f << std::endl;      
        }
        out.close();
        }
    }

// Assembly:
subq $0x4e8, %rsp            # imm = 0x4E8
movq %r8, 0xf8(%rsp)
movq %rdi, 0x4e0(%rsp)
movq %rsi, 0x4d8(%rsp)
movq %rdx, 0x4d0(%rsp)
movq %rcx, 0x4c8(%rsp)
movq %r8, 0x4c0(%rsp)
movl %r9d, 0x4bc(%rsp)
movq 0x4e0(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x2acea(%rip), %rdi     # 0x33fc0
leaq 0x1f96d(%rip), %rsi     # 0x28c4a
callq 0x3290
movq %rax, %rdi
movq 0x2acb4(%rip), %rsi     # 0x33fa0
callq 0x32c0
movq 0x4d8(%rsp), %rdi
callq 0x208b0
movl %eax, 0x4b8(%rsp)
movq 0x4d8(%rsp), %rdi
callq 0x208c0
movl %eax, 0x4b4(%rsp)
movq 0x4d8(%rsp), %rdi
callq 0x208d0
movl %eax, 0x4b0(%rsp)
leaq 0x498(%rsp), %rdi
callq 0xfe20
fldz
fstpt 0x480(%rsp)
movl $0x0, 0x47c(%rsp)
movq $0x0, 0x470(%rsp)
movq 0x470(%rsp), %rax
movl 0x4b0(%rsp), %ecx
cmpq %rcx, %rax
je 0x9551
movq $0x0, 0x468(%rsp)
movq 0x468(%rsp), %rax
movl 0x4b4(%rsp), %ecx
cmpq %rcx, %rax
je 0x9536
movq $0x0, 0x460(%rsp)
movq 0x460(%rsp), %rax
movl 0x4b8(%rsp), %ecx
cmpq %rcx, %rax
je 0x951b
movq 0x100(%rsp), %rdi
callq 0x11db0
movq %rax, 0x458(%rsp)
movq 0x100(%rsp), %rdi
callq 0x11c10
movq %rax, 0x450(%rsp)
leaq 0x458(%rsp), %rdi
leaq 0x450(%rsp), %rsi
callq 0x22790
testb $0x1, %al
jne 0x9402
jmp 0x9500
leaq 0x458(%rsp), %rdi
callq 0x227d0
movq %rax, %rdi
movl 0x460(%rsp), %esi
movl 0x468(%rsp), %edx
movl 0x470(%rsp), %ecx
callq 0x227e0
movb %al, 0xf7(%rsp)
jmp 0x9435
movb 0xf7(%rsp), %al
testb $0x1, %al
jne 0x9445
jmp 0x94ec
movl 0x47c(%rsp), %eax
incl %eax
movl %eax, 0x47c(%rsp)
movq 0x4d8(%rsp), %rdi
movq 0x460(%rsp), %rsi
movq 0x468(%rsp), %rdx
movq 0x470(%rsp), %rcx
callq 0xa350
movw %ax, 0xf4(%rsp)
jmp 0x9484
movw 0xf4(%rsp), %ax
movw %ax, 0x442(%rsp)
leaq 0x498(%rsp), %rdi
leaq 0x442(%rsp), %rsi
callq 0x22860
jmp 0x94ab
movzwl 0x442(%rsp), %eax
movl %eax, 0x110(%rsp)
fildl 0x110(%rsp)
fldt 0x480(%rsp)
faddp %st, %st(1)
fstpt 0x480(%rsp)
jmp 0x94ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x448(%rsp)
movl %eax, 0x444(%rsp)
jmp 0x9d18
jmp 0x94ee
leaq 0x458(%rsp), %rdi
callq 0x228d0
jmp 0x93cf
jmp 0x9502
movq 0x460(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x460(%rsp)
jmp 0x93a2
jmp 0x951d
movq 0x468(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x468(%rsp)
jmp 0x937e
jmp 0x9538
movq 0x470(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x470(%rsp)
jmp 0x935a
movq 0x2aa68(%rip), %rdi     # 0x33fc0
leaq 0x1f705(%rip), %rsi     # 0x28c64
callq 0x3290
movq %rax, 0xe8(%rsp)
jmp 0x956e
movq 0xe8(%rsp), %rdi
movl 0x47c(%rsp), %esi
callq 0x3350
movq %rax, 0xe0(%rsp)
jmp 0x958c
movq 0xe0(%rsp), %rdi
leaq 0x1f6da(%rip), %rsi     # 0x28c75
callq 0x3290
movq %rax, 0xd8(%rsp)
jmp 0x95aa
movq 0xd8(%rsp), %rdi
movl 0x47c(%rsp), %eax
cvtsi2sd %rax, %xmm0
movl 0x4b8(%rsp), %eax
movl 0x4b4(%rsp), %ecx
imull %ecx, %eax
movl 0x4b0(%rsp), %ecx
imull %ecx, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
callq 0x34e0
movq %rax, 0xd0(%rsp)
jmp 0x95f1
movq 0xd0(%rsp), %rdi
leaq 0x1f68e(%rip), %rsi     # 0x28c8e
callq 0x3290
movq %rax, 0xc8(%rsp)
jmp 0x960f
movq 0xc8(%rsp), %rdi
movq 0x2a982(%rip), %rsi     # 0x33fa0
callq 0x32c0
jmp 0x9625
movl 0x47c(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x140(%rsp)
fldl 0x140(%rsp)
fldt 0x480(%rsp)
fdivp %st, %st(1)
fstpt 0x480(%rsp)
movq 0x2a968(%rip), %rdi     # 0x33fc0
leaq 0x1f63e(%rip), %rsi     # 0x28c9d
callq 0x3290
movq %rax, 0xc0(%rsp)
jmp 0x966e
movq 0xc0(%rsp), %rdi
fldt 0x480(%rsp)
movq %rsp, %rax
fstpt (%rax)
callq 0x32f0
movq %rax, 0xb8(%rsp)
jmp 0x9691
movq 0xb8(%rsp), %rdi
movq 0x2a900(%rip), %rsi     # 0x33fa0
callq 0x32c0
jmp 0x96a7
leaq 0x498(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x22940
movq 0xa8(%rsp), %rdi
movq %rax, 0x430(%rsp)
callq 0x22970
movq %rax, 0x428(%rsp)
movq 0x430(%rsp), %rdi
movq 0x428(%rsp), %rsi
callq 0x228f0
movq %rax, 0xb0(%rsp)
jmp 0x96f8
movq 0xb0(%rsp), %rax
movq %rax, 0x438(%rsp)
leaq 0x438(%rsp), %rdi
callq 0x229a0
movw (%rax), %ax
movw %ax, 0x440(%rsp)
leaq 0x498(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x22940
movq 0x98(%rsp), %rdi
movq %rax, 0x410(%rsp)
callq 0x22970
movq %rax, 0x408(%rsp)
movq 0x410(%rsp), %rdi
movq 0x408(%rsp), %rsi
callq 0x229b0
movq %rax, 0xa0(%rsp)
jmp 0x9771
movq 0xa0(%rsp), %rax
movq %rax, 0x418(%rsp)
leaq 0x418(%rsp), %rdi
callq 0x229a0
movw (%rax), %ax
movw %ax, 0x426(%rsp)
movq 0x2a820(%rip), %rdi     # 0x33fc0
leaq 0x1f506(%rip), %rsi     # 0x28cad
callq 0x3290
movq %rax, 0x90(%rsp)
jmp 0x97b6
movq 0x90(%rsp), %rdi
movzwl 0x440(%rsp), %esi
callq 0x3470
movq %rax, 0x88(%rsp)
jmp 0x97d5
movq 0x88(%rsp), %rdi
movq 0x2a7bc(%rip), %rsi     # 0x33fa0
callq 0x32c0
movq %rax, 0x80(%rsp)
jmp 0x97f3
movq 0x80(%rsp), %rdi
leaq 0x1f4b1(%rip), %rsi     # 0x28cb3
callq 0x3290
movq %rax, 0x78(%rsp)
jmp 0x980e
movq 0x78(%rsp), %rdi
movzwl 0x426(%rsp), %esi
callq 0x3470
movq %rax, 0x70(%rsp)
jmp 0x9827
movq 0x70(%rsp), %rdi
movq 0x2a76d(%rip), %rsi     # 0x33fa0
callq 0x32c0
jmp 0x983a
movzwl 0x426(%rsp), %eax
movzwl 0x440(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x404(%rsp)
movl 0x404(%rsp), %eax
movl %eax, 0x13c(%rsp)
fildl 0x13c(%rsp)
movl 0x4bc(%rsp), %eax
movq %rax, 0x130(%rsp)
fildll 0x130(%rsp)
fdivrp %st, %st(1)
fstpt 0x3f0(%rsp)
movq 0x4d0(%rsp), %rdi
movl 0x4bc(%rsp), %eax
incl %eax
movl %eax, %esi
movq $0x0, 0x3e8(%rsp)
leaq 0x3e8(%rsp), %rdx
callq 0x22a00
jmp 0x98b5
movq $0x0, 0x3e0(%rsp)
movq 0x3e0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x4d0(%rsp), %rdi
callq 0x10520
movq %rax, %rcx
movq 0x68(%rsp), %rax
cmpq %rcx, %rax
je 0x9995
movzwl 0x440(%rsp), %eax
movl %eax, 0x114(%rsp)
fildl 0x114(%rsp)
movq 0x3e0(%rsp), %rax
movq %rax, 0x118(%rsp)
testq %rax, %rax
sets %al
movzbl %al, %eax
movl %eax, %ecx
fildll 0x118(%rsp)
leaq 0x1e725(%rip), %rax     # 0x28050
flds (%rax,%rcx,4)
faddp %st, %st(1)
fldt 0x3f0(%rsp)
fmulp %st, %st(1)
faddp %st, %st(1)
fstpl 0x3d8(%rsp)
movsd 0x3d8(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x4d0(%rsp), %rdi
movq 0x3e0(%rsp), %rsi
callq 0xa1c0
movq %rax, 0x60(%rsp)
jmp 0x996d
movq 0x60(%rsp), %rax
movsd 0x58(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x3e0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x3e0(%rsp)
jmp 0x98c1
movq 0x4c8(%rsp), %rdi
movl 0x4bc(%rsp), %eax
incl %eax
movl %eax, %esi
movq $0x0, 0x3d0(%rsp)
leaq 0x3d0(%rsp), %rdx
callq 0x22a00
jmp 0x99c3
leaq 0x498(%rsp), %rax
movq %rax, 0x3c8(%rsp)
movq 0x3c8(%rsp), %rdi
callq 0x22940
movq %rax, 0x3c0(%rsp)
movq 0x3c8(%rsp), %rdi
callq 0x22970
movq %rax, 0x3b8(%rsp)
leaq 0x3c0(%rsp), %rdi
leaq 0x3b8(%rsp), %rsi
callq 0x22ac0
testb $0x1, %al
jne 0x9a1b
jmp 0x9b1e
leaq 0x3c0(%rsp), %rdi
callq 0x229a0
movw (%rax), %ax
movw %ax, 0x3b6(%rsp)
movzwl 0x3b6(%rsp), %eax
movzwl 0x440(%rsp), %ecx
subl %ecx, %eax
movl %eax, 0x124(%rsp)
fildl 0x124(%rsp)
fstpt 0x3a0(%rsp)
fldt 0x3f0(%rsp)
fstpt 0x390(%rsp)
fldt 0x3a0(%rsp)
fldt 0x390(%rsp)
fdivrp %st, %st(1)
flds 0x1e682(%rip)           # 0x28100
fxch %st(1)
fucomi %st(1), %st
fldz
fcmovnb %st(2), %st
fstp %st(2)
fsubp %st, %st(1)
setae %al
fnstcw 0x10e(%rsp)
movzwl 0x10e(%rsp), %ecx
orl $0xc00, %ecx            # imm = 0xC00
movw %cx, 0x10c(%rsp)
fldcw 0x10c(%rsp)
fistpll 0x128(%rsp)
fldcw 0x10e(%rsp)
movzbl %al, %eax
movl %eax, %ecx
shlq $0x3f, %rcx
movq 0x128(%rsp), %rax
xorq %rcx, %rax
movq %rax, 0x388(%rsp)
movq 0x4c8(%rsp), %rdi
movq 0x388(%rsp), %rsi
callq 0xa1c0
movq %rax, 0x50(%rsp)
jmp 0x9af7
movq 0x50(%rsp), %rax
movsd 0x1e53c(%rip), %xmm0    # 0x28040
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq 0x3c0(%rsp), %rdi
callq 0x22b00
jmp 0x99fd
movq 0x2a49b(%rip), %rdi     # 0x33fc0
leaq 0x1f18d(%rip), %rsi     # 0x28cb9
callq 0x3290
movq %rax, 0x48(%rsp)
jmp 0x9b38
movq 0x48(%rsp), %rdi
movq 0x2a45c(%rip), %rsi     # 0x33fa0
callq 0x32c0
jmp 0x9b4b
movq 0xf8(%rsp), %rsi
leaq 0x1f17d(%rip), %rdx     # 0x28cd7
leaq 0x168(%rsp), %rdi
callq 0x6100
jmp 0x9b69
leaq 0x188(%rsp), %rdi
leaq 0x168(%rsp), %rsi
movl $0x10, %edx
callq 0x3500
jmp 0x9b85
leaq 0x168(%rsp), %rdi
callq 0x3538
movq $0x0, 0x160(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x4c8(%rsp), %rdi
callq 0x10520
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
je 0x9ce7
movq 0x4d0(%rsp), %rdi
movq 0x160(%rsp), %rsi
callq 0xa1c0
movq %rax, 0x38(%rsp)
jmp 0x9be5
movq 0x38(%rsp), %rax
fldl (%rax)
fstpt 0x150(%rsp)
movq 0x4c8(%rsp), %rdi
movq 0x160(%rsp), %rsi
callq 0xa1c0
movq %rax, 0x30(%rsp)
jmp 0x9c0f
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x148(%rsp)
fldt 0x150(%rsp)
movq %rsp, %rax
fstpt (%rax)
leaq 0x188(%rsp), %rdi
callq 0x32f0
movq %rax, 0x28(%rsp)
jmp 0x9c41
movq 0x28(%rsp), %rdi
leaq 0x1effb(%rip), %rsi     # 0x28c48
callq 0x3290
movq %rax, 0x20(%rsp)
jmp 0x9c59
movq 0x20(%rsp), %rdi
movsd 0x148(%rsp), %xmm0
callq 0x34e0
movq %rax, 0x18(%rsp)
jmp 0x9c73
movq 0x18(%rsp), %rdi
movq 0x2a321(%rip), %rsi     # 0x33fa0
callq 0x32c0
jmp 0x9c86
jmp 0x9c88
movq 0x160(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x160(%rsp)
jmp 0x9b9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x448(%rsp)
movl %eax, 0x444(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x3538
jmp 0x9d18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x448(%rsp)
movl %eax, 0x444(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x3390
jmp 0x9d18
leaq 0x188(%rsp), %rdi
callq 0x3370
jmp 0x9cf6
leaq 0x188(%rsp), %rdi
callq 0x3390
leaq 0x498(%rsp), %rdi
callq 0x116a0
addq $0x4e8, %rsp            # imm = 0x4E8
retq
leaq 0x498(%rsp), %rdi
callq 0x116a0
movq 0x448(%rsp), %rdi
callq 0x34a0
nopw %cs:(%rax,%rax)
nopl (%rax)