Hereby I would like to draw your attention to a class (template) that I just submitted: ENH: Added NeighborhoodRange for efficient modern C++ style iteration. It aims to support modern C++ style iteration on a pixel neighborhood, in an efficient way.
Features:
- Can be used in C++11 range-based for loops, for example:
for (PixelType pixel : neighborhoodRange) … - Can be used to easily construct an std container of pixels, for example:
std::vector< PixelType > pixels(neighborhoodRange.begin(), neighborhoodRange.end()) - Can be passed directly to std algorithms (std::for_each, std::copy, etc.)
- Can also be used with std C++ < numeric> functions, e.g., std::inner_product
- Supports bidirectional iteration (both ++it and --it)
Performance related properties:
- No dynamic memory allocation (not even during construction)
- No virtual functions (even its destructors are non-virtual)
- No ‘mutable’ data members, making it easier to write thread-safe code.
itk::NeighborhoodRange would allow a significantly performance improvement of GaussianDerivativeImageFunction, as I observed from rerunning the test from
Removal of `virtual` keywords from ConstNeighborhoodIterator
On my Windows machine, I observed a reduction of runtime duration of more than 25%.
The patch includes unit tests (Core/Common/test/itkNeighborhoodRangeTest.cxx) which show various relevant use cases.
Your review and comments are appreciated: http://review.source.kitware.com/#/c/23326