Update license to GNU GPL version 3.
[Ale.git] / d2 / render / psf / circle.h
blob508031f9c462d65486a15a3ff8e09fb7d8065ce3
1 // Copyright 2003, 2004 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@ugcs.caltech.edu>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __psf_circle_h__
22 #define __psf_circle_h__
24 #include "../../point.h"
25 #include "psf.h"
28 * Point-spread function module.
30 * This module implements a circular filter.
33 class circle : public psf {
34 ale_pos _radius;
35 public:
38 * The following four functions indicate filter boundaries. Filter
39 * support may include everything up to and including the boundaries
40 * specified here.
42 float min_i() const { return -_radius; }
43 float max_i() const { return _radius; }
44 float min_j() const { return -_radius; }
45 float max_j() const { return _radius; }
48 * Response function
50 * Get the response to the rectangle bounded by (top, bot, lef, rig).
51 * This function must correctly handle points which fall outside of the
52 * filter support. The variety of the responding pixel is provided, in
53 * case response is not uniform for all pixels (e.g. some sensor arrays
54 * stagger red, green, and blue sensors).
56 psf_result operator()(float top, float bot, float lef, float rig,
57 unsigned int variety) const {
59 psf_result result;
61 for (int k = 0; k < 3; k++)
62 result.matrix(k, k) = 0;
64 ale_pos total = (bot - top) * (rig - lef) / (M_PI * _radius * _radius);
66 for (int i = 0; i < 10; i++)
67 for (int j = 0; j < 10; j++) {
68 ale_pos r = pow(top + (bot - top) * ((i + 0.5) / (double) 10), 2)
69 + pow(lef + (rig - lef) * ((j + 0.5) / (double) 10), 2);
70 if (r < _radius * _radius)
71 for (int k = 0; k < 3; k++)
72 result.matrix(k, k) += (total / 100);
76 return result;
79 circle(ale_pos radius) {
80 _radius = radius;
84 #endif