2 //////////////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by Francois Fleuret //
16 // (C) Ecole Polytechnique Federale de Lausanne //
17 // Contact <pom@epfl.ch> for comments & bug reports //
18 //////////////////////////////////////////////////////////////////////////////////
20 #ifndef INTEGRAL_ARRAY_H
21 #define INTEGRAL_ARRAY_H
30 class IntegralArray: public Array<T> {
33 void compute(const Array<T> *m) {
34 T *v = Array<T>::content, *w = m->Array<T>::content;
35 for(int x = 0; x < Array<T>::height; x++) *(v++) = 0;
38 for(int y = 1; y < Array<T>::width; y++) {
40 for(int x = 0; x < Array<T>::height - 1; x++) {
42 *(v++) = sl + *(v - Array<T>::height);
47 IntegralArray(int w, int h) : Array<T>(w+1, h+1) { }
49 IntegralArray(const Array<T> &m) : Array<T>(m->get_width() + 1, m->get_height() + 1) {
53 // Integral on xmin <= x < xmax, ymin <= y < ymax
54 // Thus, xmax and ymax can go up to m->width+1 and m->height+1 respectively
56 inline T integral(int xmin, int ymin, int xmax, int ymax) const {
57 ASSERT(xmin <= xmax && ymin <= ymax, "Inconsistent bounds for integral");
58 ASSERT(xmin >= 0 && xmax < Array<T>::width &&
59 ymin >= 0 && ymax < Array<T>::height, "Index out of bounds in Array::operator () const");
60 return Array<T>::heads[xmax][ymax] + Array<T>::heads[xmin][ymin]
61 - Array<T>::heads[xmax][ymin] - Array<T>::heads[xmin][ymax];