plstcharles / litiv

C++ implementation pool for computer vision R&D projects.
http://www.polymtl.ca/litiv/en/
Other
101 stars 30 forks source link

Remove dependency on constant number of channels #3

Closed medyakovvit closed 8 years ago

medyakovvit commented 8 years ago

Change value of upper bound in for loops from 3 to actual number of image's channels

medyakovvit commented 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?

plstcharles commented 8 years ago

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...

medyakovvit commented 8 years ago

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?

plstcharles commented 8 years ago

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).