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 //////////////////////////////////////////////////////////////////////////////////
25 Room::Room(int view_width, int view_height, int nb_cameras, int nb_positions) {
26 _view_width = view_width;
27 _view_height = view_height;
28 _nb_cameras = nb_cameras;
29 _nb_positions = nb_positions;
30 _rectangles = new Rectangle[_nb_cameras * _nb_positions];
37 void Room::save_stochastic_view(char *name,
39 const ProbaView *view,
40 const Vector<scalar_t> *proba_presence) const {
42 RGBImage image(view->get_width(), view->get_height());
44 Array<scalar_t> proba_pixel_off(_view_width, _view_height);
46 for(int px = 0; px < _view_width; px++) for(int py = 0; py < _view_height; py++)
47 proba_pixel_off(px, py) = 1.0;
49 Array<bool> dots(_view_width, _view_height);
52 for(int n = 0; n < nb_positions(); n++) {
53 Rectangle *r = avatar(n_camera, n);
55 for(int py = r->ymin; py < r->ymax; py++)
56 for(int px = r->xmin; px < r->xmax; px++)
57 proba_pixel_off(px, py) *= (1 - (*proba_presence)[n]);
58 if(r->xmin > 0 && r->xmax < _view_width-1 && r->ymax < _view_height-1)
59 dots((r->xmax + r->xmin)/2, r->ymax) = true;
63 for(int py = 0; py < _view_height; py++) for(int px = 0; px < _view_width; px++) {
65 scalar_t a = proba_pixel_off(px, py);
67 if(dots(px, py)) { r = 0.0; g = 0.0; b = 0.0; }
69 if(a < 0.5) { r = 0; g = 0; b = 2*a; }
70 else { r = (a - 0.5) * 2; g = (a - 0.5) * 2; b = 1.0; }
73 scalar_t c = (*view)(px, py);
75 r = c * 0.0 + (1 - c) * r;
76 g = c * 0.8 + (1 - c) * g;
77 b = c * 0.6 + (1 - c) * b;
79 image.set_pixel(px, py, (unsigned char) (255 * r), (unsigned char) (255 * g), (unsigned char) (255 * b));
82 image.write_png(name);