Update license to GNU GPL version 3.
[Ale.git] / d2 / render / combine.h
blob40a4d4c633334369838ca6605c4cb1d62cf99914
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
22 * combine.h: A renderer that combines two renderings.
25 #ifndef __combine_h__
26 #define __combine_h__
28 #include "../transformation.h"
29 #include "../image.h"
30 #include "../point.h"
33 * Combine two renderings.
35 * Available data is taken from the PARTIAL rendering. When no data from
36 * the PARTIAL rendering is available, data from the DEFAULT rendering
37 * is substituted.
40 class combine : public render {
41 private:
42 render *_default;
43 render *partial;
44 image *output_image;
45 image *defined_image;
46 public:
49 * Constructor
51 combine(render *_default, render *partial) {
52 this->_default = _default;
53 this->partial = partial;
54 this->output_image = NULL;
55 this->defined_image = NULL;
58 virtual ~combine() {
59 if (output_image)
60 delete output_image;
61 if (defined_image)
62 delete defined_image;
66 * Result of rendering.
69 virtual const image *get_image() {
70 const image *default_image = _default->get_image();
71 const image *partial_image = partial->get_image();
73 assert (default_image->width() == partial_image->width());
74 assert (default_image->height() == partial_image->height());
76 if (output_image)
77 return output_image;
79 output_image = new image_ale_real(default_image->height(),
80 default_image->width(), 3, NULL);
82 output_image->set_offset(default_image->offset());
84 const image *partial_weight = partial->get_defined();
86 for (unsigned int i = 0; i < default_image->height(); i++)
87 for (unsigned int j = 0; j < default_image->width(); j++)
88 output_image->set_pixel(i, j,
89 (partial_weight->get_pixel(i, j).min_norm() >= render::get_wt())
90 ? partial_image->get_pixel(i, j)
91 : default_image->get_pixel(i, j));
93 return output_image;
97 * Definition map. Unit-depth image whose pixels are nonzero where
98 * the image is defined.
101 virtual const image *get_defined() {
102 unsigned int i, j, k;
104 if (defined_image)
105 return defined_image;
107 const image *partial_weight = partial->get_defined();
108 const image *default_weight = _default->get_defined();
110 assert (default_weight->width() == partial_weight->width());
111 assert (default_weight->height() == partial_weight->height());
113 defined_image = new image_ale_real(default_weight->height(),
114 default_weight->width(), 3, NULL);
116 defined_image->set_offset(default_weight->offset());
118 for (i = 0; i < default_weight->height(); i++)
119 for (j = 0; j < default_weight->width(); j++)
120 for (k = 0; k < default_weight->depth(); k++)
121 defined_image->set_pixel(i, j,
122 (partial_weight->get_pixel(i, j).min_norm() >= render::get_wt())
123 ? partial_weight->get_pixel(i, j)
124 : default_weight->get_pixel(i, j));
126 return defined_image;
130 * Perform rendering steps requiring no frames beyond frame N.
133 virtual void sync(int n) {
134 render::sync(n);
135 if (output_image) {
136 delete output_image;
137 output_image = NULL;
139 if (defined_image) {
140 delete defined_image;
141 defined_image = NULL;
143 _default->sync(n);
144 partial->sync(n);
147 virtual void step() {
150 virtual void init_point_renderer(unsigned int h, unsigned int w, unsigned int d) {
151 _default->init_point_renderer(h, w, d);
152 partial->init_point_renderer(h, w, d);
153 output_image = new image_zero(h, w, d);
154 defined_image = new image_zero(h, w, d);
157 virtual void point_render(unsigned int i, unsigned int j, unsigned int f, transformation t) {
158 _default->point_render(i, j, f, t);
159 partial->point_render(i, j, f, t);
162 virtual void finish_point_rendering() {
163 _default->finish_point_rendering();
164 partial->finish_point_rendering();
165 delete defined_image;
166 delete output_image;
169 * These will be generated upon a call to get_image() or
170 * get_defined().
173 defined_image = NULL;
174 output_image = NULL;
177 const render *get_default() const {
178 return _default;
181 const render *get_partial() const {
182 return partial;
185 void free_memory() {
186 delete output_image;
187 delete defined_image;
188 output_image = NULL;
189 defined_image = NULL;
193 #endif