Closed medyakovvit closed 8 years ago
There are some places in code with template functions. Template functions uses only constant expressions as template parameter. So, we need some way to dynamically point number of image's channels for such functions. Any thoughts on that?
I don't think the proposed patch is ideal here, as an entire branch now becomes useless (channels==0?), and many loops are no longer unrollable at compile time. The optimal solution to clean the code and keep identical performance would be to rewrite the entire apply function to receive the number of image channels as a template argument, and deal with single-channel peculiarities via static/compile time conditions.
I already drafted how to do it on my side, but I don't really have time to implement it right now --- LOBSTER and PAWCS would benefit from the same cleanup simultaneously. I might reopen this in some time...
this patch is just to show place in code i talked about. I want to avoid using "if" branching for 1 channel images and multy channel and use same "for" loop for both. So, if i undetstand you, you want to make apply function as template function. Or i am wrong?
Yup, that's exactly it. The entire first if (for single channel images) could be deleted if the entire function was templated to a static channel count variable, and the leftover difference could be optimized out at compile time with simple ternary/if's, or with the upcoming constexpr if (can't wait for C++17).
Change value of upper bound in for loops from 3 to actual number of image's channels