12 #define _USE_MATH_DEFINES
31 template<
class T,
class U,
class V>
46 RayTracer(
int numThreads,
int nTot, V epsilon,
bool verbose =
false);
48 void transfRays(T ctp, U *fr,
bool inv =
false);
51 T ctp, U *fr_in, U *fr_out, V t0, std::vector<V> errors);
66 template<
class T,
class U,
class V>
69 this->numThreads = numThreads;
70 this->step = ceil(nTot / numThreads);
72 this->threadPool.resize(numThreads);
73 this->epsilon = epsilon;
90 template<
class T,
class U,
class V>
94 std::array<V, 3> inp, out;
95 for (
int i=0; i<fr->size; i++)
101 if (inv) {ut.invmatVec4(ctp.transf, inp, out);}
102 else {ut.matVec4(ctp.transf, inp, out);}
112 if (inv) {ut.invmatVec4(ctp.transf, inp, out, vec);}
113 else {ut.matVec4(ctp.transf, inp, out, vec);}
139 template<
class T,
class U,
class V>
147 std::vector<V> errors)
156 V (*refl_func_ptr)(V, V, V, V, V, V, V, V, V, V);
157 std::array<V, 3> (*refl_norm_ptr)(V, V, V, int, V, V, V);
171 else if (ctp.type == 2)
177 else if (ctp.type == 3)
183 std::array<V, 3> direct;
184 std::array<V, 3> out;
186 for (
int i=start; i<stop; i++)
191 V check = fabs(t1 - _t);
192 std::array<V, 3> norms;
202 direct = {dx, dy, dz};
204 while (check > epsilon)
206 t1 = refl_func_ptr(_t, x, y, z, dx, dy, dz, ctp.coeffs[0], ctp.coeffs[1], ctp.coeffs[2]);
208 check = fabs(t1 - _t);
213 if ((
abs(round(dx)) == 0 &&
abs(round(dy)) == 0 &&
abs(round(dz)) == 0) || std::isnan(_t))
226 fr_out->x[i] = x + _t*dx;
227 fr_out->y[i] = y + _t*dy;
228 fr_out->z[i] = z + _t*dz;
230 norms = refl_norm_ptr(fr_out->x[i], fr_out->y[i], fr_out->z[i], flip, ctp.coeffs[0], ctp.coeffs[1], ctp.coeffs[2]);
231 check = (dx*norms[0] + dy*norms[1] + dz*norms[2]);
233 ut.snell(direct, norms, out);
235 fr_out->dx[i] = out[0];
236 fr_out->dy[i] = out[1];
237 fr_out->dz[i] = out[2];
240 fr_out->x[i] += errors[i] * norms[0];
241 fr_out->y[i] += errors[i] * norms[1];
242 fr_out->z[i] += errors[i] * norms[2];
262 template <
class T,
class U,
class V>
271 std::vector<V> errors(nTot, 0.);
283 for(
int n=0; n<numThreads; n++)
285 if(n == (numThreads-1)) {final_step = nTot;}
286 else {final_step = (n+1) * step;}
288 threadPool[n] = std::thread(
307 template <
class T,
class U,
class V>
310 for (std::thread &t : threadPool) {
if (t.joinable()) {t.join();}}
__device__ __inline__ void abs(float(&v)[3], float &out)
Definition: GUtils.h:195
__device__ __inline__ void transfRays(float *x, float *y, float *z, float *dx, float *dy, float *dz, int i, bool inv=false)
Definition: KernelsRTf.cu:209
Simple reflector definitions used for PyPO ray-tracer.
Class for generating random numbers.
Structs used within PyPO.
Linear algebra functions for the CPU version of PyPO.
T generateNormal(T stdev, T mean=0.0)
Definition: Random.h:112
Definition: RayTrace.h:33
std::vector< std::thread > threadPool
Definition: RayTrace.h:44
Utils< V > ut
Definition: RayTrace.h:43
void propagateRaysToTarget(int start, int stop, T ctp, U *fr_in, U *fr_out, V t0, std::vector< V > errors)
Definition: RayTrace.h:140
void parallelRays(T ctp, U *fr_in, U *fr_out, V t0)
Definition: RayTrace.h:263
void transfRays(T ctp, U *fr, bool inv=false)
Definition: RayTrace.h:91
RayTracer(int numThreads, int nTot, V epsilon, bool verbose=false)
Definition: RayTrace.h:67