00fdec39bbfe2fcf91d6534f2bc4a0ace3acd4ef
2 ////////////////////////////////////////////////////////////////////
4 //                                                                //
5 // Written by Francois Fleuret                                    //
6 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
7 //                                                                //
9 ////////////////////////////////////////////////////////////////////
11 #include "vision_problem_10.h"
12 #include "shape.h"
14 VisionProblem_10::VisionProblem_10() { }
16 void VisionProblem_10::generate(int label, Vignette *vignette) {
17   int nb_shapes = 4;
18   int xs[nb_shapes], ys[nb_shapes];
20   int error;
21   do {
22     do {
23       if(label == 1) {
24         scalar_t alpha = drand48() * 2 * M_PI;
25         scalar_t radius = drand48() * Vignette::width / 2;
26         scalar_t xc = drand48() * Vignette::width;
27         scalar_t yc = drand48() * Vignette::height;
28         for(int n = 0; n < nb_shapes; n++) {
29           xs[n] = int(xc + part_size/2 +
30                       radius * sin(alpha + n * 2 * M_PI / scalar_t(nb_shapes)));
31           ys[n] = int(yc + part_size/2 +
32                       radius * cos(alpha + n * 2 * M_PI / scalar_t(nb_shapes)));
33         }
34       } else {
35         for(int n = 0; n < nb_shapes; n++) {
36           xs[n] = int(drand48() * Vignette::width);
37           ys[n] = int(drand48() * Vignette::height);
38         }
39       }
40     } while(cluttered_shapes(part_size, nb_shapes, xs, ys));
42     vignette->clear();
44     Shape shape;
45     error = 0;
46     for(int n = 0; n < nb_shapes; n++) {
47       if(n == 0) {
48         shape.randomize(part_size / 2, part_hole_size / 2);
49       }
50       error |= shape.overwrites(vignette, xs[n], ys[n]);
51       shape.draw(vignette, xs[n], ys[n]);
52     }
53   } while(error);
54 }