19#include "owl/common/math/vec.h"
20#include "owl/common/parallel/parallel_for.h"
26 inline __both__ int64_t linear(
const vec3i &ID,
28 {
return ID.x + dims.x*(ID.y + dims.y*(int64_t)ID.z); }
30 template<
typename Lambda>
31 inline void for_each(
const vec3i &dims,
34 for (
int iz=0;iz<dims.z;iz++)
35 for (
int iy=0;iy<dims.y;iy++)
36 for (
int ix=0;ix<dims.x;ix++)
37 lambda(vec3i(ix,iy,iz));
40 template<
typename Lambda>
41 inline void for_each(
const vec3i &begin,
45 for (
int iz=begin.z;iz<end.z;iz++)
46 for (
int iy=begin.y;iy<end.y;iy++)
47 for (
int ix=begin.x;ix<end.x;ix++)
48 lambda(vec3i(ix,iy,iz));
51 template<
typename Lambda>
52 inline void parallel_for(
const vec3i &dims,
const Lambda &lambda)
54 owl::common::parallel_for
55 (dims.x*(
size_t)dims.y*dims.z,[&](
size_t index){
56 lambda(vec3i(index%dims.x,
57 (index/dims.x)%dims.y,
58 index/((size_t)dims.x*dims.y)));
61 template<
typename Lambda>
62 inline void serial_for(
const vec3i &dims,
const Lambda &lambda)
64 owl::common::serial_for(dims.x*
size_t(dims.y)*dims.z,
66 lambda(vec3i(index%dims.x,
67 (index/dims.x)%dims.y,
68 index/((size_t)dims.x*dims.y)));
72 inline __both__
bool validIndex(
const vec3i &idx,
75 if (idx.x < 0 || idx.x >= dims.x)
return false;
76 if (idx.y < 0 || idx.y >= dims.y)
return false;
77 if (idx.z < 0 || idx.z >= dims.z)
return false;