All pastes #770047 Raw Edit

Something

public text v1 · immutable
·published 2007-11-11 21:23 UTC
rendered paste body
template <typename T>
void Matrix<T>::sinc(T amplitude, float freq, unsigned int zeroX, unsigned int zeroY) {
    unsigned int pgmMaxValueBak = _pgmMaxValue;

    for (unsigned int y = 0; y < _size[1]; y++) {
        for (unsigned int x = 0; x < _size[0]; x++) {
            double radius = sqrt(pow((double) ((int) x - (int) zeroX), 2)
                    + pow((double) ((int) y - (int) zeroY), 2));

            if (radius == 0) {
                setValue(x, y, 0, amplitude);
            } else {
                /* this produces negative values, which will be normalized later */
                setValue(x, y, 0, amplitude * (T) (sin(radius) / radius));
            }
        }
    }

    _pgmMaxValue = (unsigned int) amplitude;
    normalize();
    _pgmMaxValue = pgmMaxValueBak;
}