1 // Copyright 2002 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
25 * Structure to describe a pixel
39 pixel(ale_real x0
, ale_real x1
, ale_real x2
) {
45 pixel(const pixel
&p
) {
51 pixel
&operator=(const pixel
&p
) {
60 // Due to automatic typecasts and automatic int <==> ale_real *
61 // conversions, this can cause some really weird bugs.
63 // pixel(ale_real *_x) {
69 const ale_real
&operator[](unsigned int i
) const {
72 * This may be expensive.
79 ale_real
&operator[](unsigned int i
) {
82 * This may be expensive.
89 pixel
operator+(pixel p
) const {
90 return pixel(p
[0] + x
[0], p
[1] + x
[1], p
[2] + x
[2]);
93 pixel
operator-(pixel p
) const {
94 return pixel(x
[0] - p
[0], x
[1] - p
[1], x
[2] - p
[2]);
97 pixel
operator-() const {
98 return pixel(-x
[0], -x
[1], -x
[2]);
101 pixel
operator/(pixel p
) const {
102 return pixel(x
[0] / p
[0], x
[1] / p
[1], x
[2] / p
[2]);
105 pixel
operator/(ale_real d
) const {
106 return pixel(x
[0] / d
, x
[1] / d
, x
[2] / d
);
109 pixel
mult(pixel p
) const {
110 return pixel(x
[0] * p
[0], x
[1] * p
[1], x
[2] * p
[2]);
113 pixel
mult(ale_real d
) const {
114 return pixel(x
[0] * d
, x
[1] * d
, x
[2] * d
);
117 pixel
operator+=(pixel p
) {
118 return pixel(x
[0] += p
[0], x
[1] += p
[1], x
[2] += p
[2]);
121 pixel
operator*=(pixel p
) {
122 return pixel(x
[0] *= p
[0], x
[1] *= p
[1], x
[2] *= p
[2]);
125 pixel
operator*=(ale_real d
) {
126 return pixel(x
[0] *= d
, x
[1] *= d
, x
[2] *= d
);
129 pixel
operator/=(pixel p
) {
130 return pixel(x
[0] /= p
[0], x
[1] /= p
[1], x
[2] /= p
[2]);
133 pixel
operator/=(ale_real d
) {
134 return pixel(x
[0] /= d
, x
[1] /= d
, x
[2] /= d
);
137 pixel
clamp() const {
140 for (int i
= 0; i
< 3; i
++)
153 return pixel(fabs(x
[0]), fabs(x
[1]), fabs(x
[2]));
157 return x
[0] * x
[0] + x
[1] * x
[1] + x
[2] * x
[2];
161 return sqrt(normsq());
165 return x
[0] + x
[1] + x
[2];
168 ale_real
maxabs_norm() {
169 ale_real m
= fabs(x
[0]);
178 ale_real
minabs_norm() {
179 ale_real m
= fabs(x
[0]);
188 ale_real
min_norm() const {
198 ale_real
max_norm() {
208 static pixel
zero() {
209 return pixel(0, 0, 0);
213 return pixel(1, 1, 1);
216 int operator==(const pixel
&p
) {
222 int operator!=(const pixel
&p
) {
223 return !operator==(p
);
227 return ::finite(x
[0]) && ::finite(x
[1]) && ::finite(x
[2]);
230 static pixel
undefined() {
232 return pixel(zero
/ zero
, zero
/ zero
, zero
/ zero
);
237 inline pixel
operator*(const pixel
&p
, const pixel
&q
) {
242 inline pixel
operator*(T d
, const pixel
&p
) {
246 inline pixel
operator*(const pixel
&p
, T d
) {
250 inline std::ostream
&operator<<(std::ostream
&o
, const pixel
&p
) {
251 o
<< "[" << (double) p
[0] << " " << (double) p
[1] << " " << (double) p
[2] << "]";
256 inline pixel
ppow(pixel p
, T d
) {
263 inline pixel
pexp(pixel p
) {
270 inline pixel
psqrt(pixel p
) {