22 #ifndef CRNSummedAreaTable_HEADER
23 #define CRNSummedAreaTable_HEADER
45 inline SummedAreaTable(
size_t w,
size_t h):width(w),height(h),data(w * h, T(0)) { }
53 inline T
GetValue(
size_t x,
size_t y)
const {
return data[x + y * width]; }
55 inline void SetValue(
size_t x,
size_t y, T val) { data[x + y * width] = val; }
77 inline T
GetSum(
size_t x1,
size_t y1,
size_t x2,
size_t y2)
const
79 if ((x1 == 0) && (y1 == 0))
80 return data[x2 + y2 * width];
82 return T(data[x2 + y2 * width] - data[x2 + (y1 - 1) * width]);
84 return T(data[x2 + y2 * width] - data[x1 - 1 + y2 * width]);
86 return T(data[x2 + y2 * width] + data[x1 - 1 + (y1 - 1) * width] - data[(x1 - 1) + y2 * width] - data[x2 + (y1 - 1) * width]);
int GetBottom() const
Returns the bottommost coordinate.
T GetValue(size_t x, size_t y) const
Gets the value of a bin.
int GetTop() const
Returns the topmost coordinate.
int GetLeft() const
Returns the leftmost coordinate.
SummedAreaTable(size_t w, size_t h)
Constructor.
void SetValue(size_t x, size_t y, T val)
Alters the value of a bin.
T GetSum(const crn::Rect &r) const
Gets the sum of the original pixels in a rectangle.
T GetSum(size_t x1, size_t y1, size_t x2, size_t y2) const
Gets the sum of the original pixels in a rectangle.
int GetRight() const
Returns the rightmost coordinate.
SummedAreaTable & operator=(const SummedAreaTable &)=default