32 #include <cugar/basic/numbers.h> 46 return rand() / float(RAND_MAX);
54 return cugar::min(uint32(r * N), N - 1);
60 FERMAT_HOST_DEVICE
strided_vec(
float* _ptr,
const uint32 _off,
const uint32 _stride) : base(_ptr), off(_off), stride(_stride) {}
62 FERMAT_HOST_DEVICE
const float& operator[] (
const uint32 i)
const {
return base[off + i*stride]; }
63 FERMAT_HOST_DEVICE
float& operator[] (
const uint32 i) {
return base[off + i*stride]; }
77 sample_set_3d(
const uint32 _x,
const uint32 _y,
float* _samples) :
78 X(_x), Y(_y), samples(_samples) {}
80 uint32 size()
const {
return X*Y; }
82 strided_vec operator() (
const uint32 x,
const uint32 y,
const uint32 z) {
return strided_vec(samples, z*X*Y * 3 + X*y + x, X*Y); }
95 for (uint32 k = 0; k < Z; ++k)
97 for (uint32 j = 0; j < Y; ++j)
99 for (uint32 i = 0; i < X; ++i)
101 p(i, j, k)[slice + 0] = (i + (j + (k +
random()) / Z) / Y) / X;
102 p(i, j, k)[slice + 1] = (j + (k + (i +
random()) / X) / Z) / Y;
103 p(i, j, k)[slice + 2] = (k + (i + (j +
random()) / Y) / X) / Z;
112 for (uint32 k = 0; k < Z; ++k)
114 for (uint32 j = 0; j < Y; ++j)
116 for (uint32 i = 0; i < X; ++i)
118 const uint32 r = k +
irandom(Z - k);
120 std::swap(p(i, j, k)[slice+0], p(i, j, r)[slice+0]);
121 std::swap(p(i, j, k)[slice+1], p(i, j, r)[slice+1]);
122 std::swap(p(i, j, k)[slice+2], p(i, j, r)[slice+2]);
129 for (uint32 k = 0; k < Z; ++k)
134 for (uint32 j = 0; j < Y; ++j)
136 const uint32 r = j +
irandom(Y - j);
138 for (uint32 i = 0; i < X; ++i)
141 std::swap(p(i, j, k)[slice],
149 for (uint32 i = 0; i < X; ++i)
151 const uint32 r = i +
irandom(X - i);
153 for (uint32 j = 0; j < Y; ++j)
156 std::swap(p(i, j, k)[slice+1],
157 p(r, j, k)[slice+1]);
165 for (uint32 k = 0; k < Z; ++k)
167 const uint32 r = k +
irandom(Z - k);
169 for (uint32 j = 0; j < Y; ++j)
173 for (uint32 i = 0; i < X; ++i)
176 std::swap(p(i, j, k)[slice],
184 for (uint32 i = 0; i < X; ++i)
186 const uint32 r = i +
irandom(X - i);
188 for (uint32 k = 0; k < Z; ++k)
192 for (uint32 j = 0; j < Y; ++j)
195 std::swap(p(i, j, k)[slice + 1],
196 p(r, j, k)[slice + 1]);
203 for (uint32 j = 0; j < Y; ++j)
205 const uint32 r = j +
irandom(Y - j);
207 for (uint32 i = 0; i < X; ++i)
211 for (uint32 k = 0; k < Z; ++k)
214 std::swap(p(i, j, k)[slice + 2],
215 p(i, r, k)[slice + 2]);
225 for (uint32 k = 0; k < Z; ++k)
227 for (uint32 j = 0; j < Y; ++j)
229 for (uint32 i = 0; i < X; ++i)
231 p(i, j, k)[slice + 0] = (i + (j +
random()) / Y) / X;
232 p(i, j, k)[slice + 1] = (j + (i +
random()) / X) / Y;
233 p(i, j, k)[slice + 2] = (i + (j +
random()) / Y) / X;
240 for (uint32 k = 0; k < Z; ++k)
245 for (uint32 j = 0; j < Y; ++j)
247 const uint32 r = j +
irandom(Y - j);
249 for (uint32 i = 0; i < X; ++i)
252 std::swap(p(i, j, k)[slice],
259 for (uint32 i = 0; i < X; ++i)
261 const uint r = i +
irandom(X - i);
263 for (uint32 j = 0; j < Y; ++j)
266 std::swap(p(i, j, k)[slice + 1],
267 p(r, j, k)[slice + 1]);
271 for (uint32 n = 0; n < X*Y; ++n)
273 const uint r = n +
irandom(X*Y - n);
275 std::swap(p(n % X, n / X, k)[slice + 2],
276 p(r % X, r / X, k)[slice + 2]);
292 mj_3d( X, Y, Z,
set, 0);
295 const uint32 SLICE_SIZE = X*Y;
297 for (uint32 z = 0; z < Z; ++z)
299 for (uint32 i = 0; i < SLICE_SIZE; ++i)
301 const uint32 r = i +
irandom(SLICE_SIZE - i);
303 std::swap(samples[z * SLICE_SIZE * 3 + i + 0 * SLICE_SIZE], samples[z * SLICE_SIZE * 3 + r + 0 * SLICE_SIZE]);
304 std::swap(samples[z * SLICE_SIZE * 3 + i + 1 * SLICE_SIZE], samples[z * SLICE_SIZE * 3 + r + 1 * SLICE_SIZE]);
305 std::swap(samples[z * SLICE_SIZE * 3 + i + 2 * SLICE_SIZE], samples[z * SLICE_SIZE * 3 + r + 2 * SLICE_SIZE]);
312 inline void load_samples(
const char* nameradix,
const uint32 X,
const uint32 Y,
const uint32 Z,
float* samples)
314 for (uint32 z = 0; z < Z; ++z)
317 sprintf(slicename,
"%s-%u.dat", nameradix, z);
319 FILE* file = fopen(slicename,
"rb");
323 std::vector<float3> slice(X*Y);
324 if (fread(&slice[0],
sizeof(float3), X*Y, file) != X*Y)
329 for (uint32 i = 0; i < X*Y; ++i)
331 samples[z * X*Y * 3 + i + 0 * X*Y] = slice[i].x;
332 samples[z * X*Y * 3 + i + 1 * X*Y] = slice[i].y;
333 samples[z * X*Y * 3 + i + 2 * X*Y] = slice[i].z;
335 fprintf(stderr,
" loaded sample slice %u (%u x %u)\n", z, X, Y);
Definition: tiled_sampling.h:57
void build_tiled_samples_3d(const uint32 X, const uint32 Y, const uint32 Z, float *samples)
Definition: tiled_sampling.h:287
float random()
Definition: tiled_sampling.h:44
Definition: tiled_sampling.h:75
void load_samples(const char *nameradix, const uint32 X, const uint32 Y, const uint32 Z, float *samples)
Definition: tiled_sampling.h:312
void mj_3d(uint32 X, uint32 Y, uint32 Z, sample_set_3d p, const uint32 slice)
Definition: tiled_sampling.h:92
uint32 irandom(const uint32 N)
Definition: tiled_sampling.h:51