Computes the disparity SAD score efficiently for a single rectangular region while minimizing CPU cache misses. After the score has been computed for an entire row it is passed onto another algorithm to compute the actual disparity. Provides support for fast right to left validation. First the sad score is computed horizontally then summed up vertically while minimizing redundant calculations that naive implementation would have.
Memory usage is minimized by only saving disparity scores for the row being considered. The more straight forward implementation is to compute the disparity score for the whole image at once, which can be quite expensive.
Score Format: The index of score for column i minDisparity at disparity d is:
index = imgWidth*(d-minDisparity) + i - minDisparity
This ordering is a bit unnatural when searching for the best disparity, but reduces cache misses when writing. Performance boost is about 20%-30% depending on max disparity and image size.
This implementation is not based off of any individual paper but ideas commonly expressed in several different
sources. A good study and summary of similar algorithms can be found in:
 Wannes van der Mark and Dariu M. Gavrila, "Real-Time Dense Stereo for Intelligent Vehicles" IEEE TRANSACTIONS ON INTELLIGENT TRANSPORTATION SYSTEMS, VOL. 7, NO. 1, MARCH 2006