Optimization possible in itk::Image::GetPixel
Mantis Issue 1021, reported by lhermitte, assigned to jmichel, created: 2015-04-02
itk::Image<>::GetPixel() calls itk::ImageBase<>::ComputeOffset() which in turn calls itk::ImageBase<>::GetBufferredRegion() which is ... a virtual function.
AFAIK, this function is overridden only in itk::ImageAdaptator<>, it's doesn't seem to be overridden anywhere else (like in otb::Image<>). So, unless the variation point needs to stay in case a child of itk::Image or otb::Image will require to specialize the behaviour of GetBufferredRegion(), it'll be best that itk::Image<>::GetPixel() relies on a non virtual version of GetBufferredRegion().
Attached, you'll find a quick and dirty implementation proposal, based on the ITK version shipped with OTB 3.16.0.
Why not calling a virtual function from a function which is already known as inefficient will matters ? Well, first the function will be less inefficient. Then, some algorithms (like BSplineInterpolateImageFunction) need to use this GetPixel function. Any improvement on GetPixel will benefit to these algorithms.
We have benchmarked, with callgrind, the number of cycles spent in the function BSplineInterpolateImageFunction::EvaluateAtContinousIndex. The function is called 117290070 times. Before the patch, the function took 212546 million cycles. After the patch, the function takes 133417 million cycles
1433248774 - Luc HermittePacth submitted over there: http://review.source.kitware.com/#/c/19857/
1447148250 - julienPatch submitted to gerrit.