4 flatland is a simple 2d physical simulator
6 Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
7 Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 This file is part of flatland
11 flatland 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.
15 flatland 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.
20 You should have received a copy of the GNU General Public License
21 along with flatland. If not, see <http://www.gnu.org/licenses/>.
27 #include "sequence_generator.h"
29 THByteTensor *generate_sequence(int pulling,
32 long image_height, long image_width,
34 int random_shape_size, int random_colors) {
38 long s, c, k, i, j, st0, st1, st2, st3, st4;
40 THLongStorage *size = THLongStorage_newWithSize(5);
41 size->data[0] = nb_sequences;
42 size->data[1] = nb_images;
43 size->data[2] = nb_channels;
44 size->data[3] = image_height;
45 size->data[4] = image_width;
46 THByteTensor *result = THByteTensor_newWithSize(size, NULL);
47 THLongStorage_free(size);
49 st0 = THByteTensor_stride(result, 0);
50 st1 = THByteTensor_stride(result, 1);
51 st2 = THByteTensor_stride(result, 2);
52 st3 = THByteTensor_stride(result, 3);
53 st4 = THByteTensor_stride(result, 4);
55 unsigned char tmp_buffer[nb_images * nb_channels * image_width * image_height];
57 for(s = 0; s < nb_sequences; s++) {
58 a = THByteTensor_storage(result)->data + THByteTensor_storageOffset(result) + s * st0;
59 fl_generate_sequence(nb_images, image_width, image_height, nb_shapes,
60 random_shape_size, random_colors,
63 unsigned char *r = tmp_buffer;
64 for(k = 0; k < nb_images; k++) {
65 for(c = 0; c < nb_channels; c++) {
66 for(i = 0; i < image_height; i++) {
67 b = a + k * st1 + c * st2 + i * st3;
68 for(j = 0; j < image_width; j++) {
69 *b = (unsigned char) (*r);