Minor update.
[pysvrt.git] / vision_problem_12.cc
1 /*
2  *  svrt is the ``Synthetic Visual Reasoning Test'', an image
3  *  generator for evaluating classification performance of machine
4  *  learning systems, humans and primates.
5  *
6  *  Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of svrt.
10  *
11  *  svrt is free software: you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  svrt is distributed in the hope that it will be useful, but
16  *  WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  *  General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with svrt.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include "vision_problem_12.h"
26 #include "shape.h"
27
28 VisionProblem_12::VisionProblem_12() { }
29
30 void VisionProblem_12::generate(int label, Vignette *vignette) {
31   int nb_shapes = 3;
32   scalar_t alpha, beta, gamma;
33   int xs, ys;
34   Shape shape;
35
36   int error;
37
38   do {
39     scalar_t xc, yc, radius;
40     xc = (random_uniform_0_1() * 0.5 + 0.25) * Vignette::width;
41     yc = (random_uniform_0_1() * 0.5 + 0.25) * Vignette::height;
42     radius = (random_uniform_0_1() * 0.5 + 0.1) * Vignette::width;
43     alpha = random_uniform_0_1() * 2 * M_PI;
44     beta = (random_uniform_0_1() * 0.4 + 0.1) * M_PI;
45
46     vignette->clear();
47     error = 0;
48
49     for(int n = 0; n < nb_shapes; n++) {
50       if(label) {
51         if(n == 0)
52           gamma = alpha + M_PI - beta/2;
53         else if(n == 1)
54           gamma = alpha + M_PI + beta/2;
55         else
56           gamma = alpha;
57       } else {
58         if(n == 0)
59           gamma = alpha + M_PI - beta/2;
60         else if(n == 1)
61           gamma = alpha;
62         else
63           gamma = alpha + M_PI + beta/2;
64       }
65
66       if(n < 2) {
67         shape.randomize(small_part_size, small_part_hole_size);
68       } else {
69         shape.randomize(big_part_size, big_part_hole_size);
70       }
71
72       xs = int(xc + radius * cos(gamma));
73       ys = int(yc + radius * sin(gamma));
74
75       error |= shape.overwrites(vignette, xs, ys);
76       if(!error) {
77         shape.draw(n, vignette, xs, ys);
78       }
79     }
80   } while(error);
81 }