PyPO User Manual
 
Loading...
Searching...
No Matches
RTRefls.h
Go to the documentation of this file.
1#include <cmath>
2#include "Utils.h"
3
4#ifndef __RTRefls_h
5#define __RTRefls_h
6
7/*! \file RTRefls.h
8 \brief Simple reflector definitions used for PyPO ray-tracer.
9
10 Simple, bare-bones definitions of reflectors for CPU/GPU ray-tracing.
11 Use only for raytracing; for PO, use the elaborate definitions.
12*/
13
14
15/**
16 * Simple representation of reflectors and implementations for the Newton-Rhapson method.
17 */
18template<class T>
20{
21public:
22 Utils<T> ut;
23
24 static T common1(T t, T xr, T yr, T dxr, T dyr, T a, T b);
25 static T common2(T t, T xr, T yr, T dxr, T dyr, T a, T b);
26 static T gp(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c);
27 static T gh(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c);
28 static T ge(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c);
29 static T gpl(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c);
30
31 static std::array<T, 3> np(T xr, T yr, T zr, int flip, T a, T b, T c);
32 static std::array<T, 3> nh(T xr, T yr, T zr, int flip, T a, T b, T c);
33 static std::array<T, 3> ne(T xr, T yr, T zr, int flip, T a, T b, T c);
34 static std::array<T, 3> npl(T xr, T yr, T zr, int flip, T a, T b, T c);
35};
36
37/**
38 * Common factor 1 for all reflectors.
39 *
40 * Calculate common factor 1. These calculations are done separately as these
41 * factors are common to all reflectors.
42 *
43 * @param t Scaling factor of ray, double/float.
44 * @param xr Current x co-ordinate of ray, double/float.
45 * @param yr Current y co-ordinate of ray, double/float.
46 * @param dxr Component of ray direction along x-axis, double/float.
47 * @param dyr Component of ray direction along y-axis, double/float.
48 * @param a Scale factor along x-axis, double/float.
49 * @param b Scale factor along y-axis, double/float.
50 * @returns z Co-ordinate along z-axis on reflector, corresponding to ray co-ordinate, direction and scaling. Double/float.
51 */
52template<class T>
53inline T RTRefls<T>::common1(T t, T xr, T yr, T dxr, T dyr, T a, T b)
54{
55 return (xr + t*dxr)*(xr + t*dxr)/(a*a) + (yr + t*dyr)*(yr + t*dyr)/(b*b);
56}
57
58/**
59 * Common factor 2 for all reflectors.
60 *
61 * Calculate common factor 2. These calculations are done separately as these
62 * factors are common to all reflectors.
63 *
64 * @param t Scaling factor of ray, double/float.
65 * @param xr Current x co-ordinate of ray, double/float.
66 * @param yr Current y co-ordinate of ray, double/float.
67 * @param dxr Component of ray direction along x-axis.
68 * @param dyr Component of ray direction along y-axis.
69 * @param a Scale factor along x-axis, double/float.
70 * @param b Scale factor along y-axis, double/float.
71 * @returns z Co-ordinate along z-axis on reflector, corresponding to ray co-ordinate, direction and scaling. Double/float.
72 */
73template<class T>
74inline T RTRefls<T>::common2(T t, T xr, T yr, T dxr, T dyr, T a, T b)
75{
76 return (xr + t*dxr)*2*dxr/(a*a) + (yr + t*dyr)*2*dyr/(b*b);
77}
78
79/**
80 * Grid paraboloid.
81 *
82 * Calculate difference between paraboloid z co-ordinate and ray z co-ordinate corresponding to x and y ray co-ordinates.
83 *
84 * @param t Scaling factor of ray, double/float.
85 * @param xr Current x co-ordinate of ray, double/float.
86 * @param yr Current y co-ordinate of ray, double/float.
87 * @param zr Current z co-ordinate of ray, double/float.
88 * @param dxr Component of ray direction along x-axis.
89 * @param dyr Component of ray direction along y-axis.
90 * @param dzr Component of ray direction along z-axis.
91 * @param a Scale factor along x-axis, double/float.
92 * @param b Scale factor along y-axis, double/float.
93 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
94 * @returns dz Difference between reflector and ray co-ordinate along z-axis.
95 */
96template<class T>
97inline T RTRefls<T>::gp(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
98{
99 return t - (zr + t*dzr - RTRefls::common1(t, xr, yr, dxr, dyr, a, b)) /
100 (dzr - RTRefls::common2(t, xr, yr, dxr, dyr, a, b));
101}
102
103/**
104 * Grid hyperboloid.
105 *
106 * Calculate difference between hyperboloid z co-ordinate and ray z co-ordinate corresponding to x and y ray co-ordinates.
107 *
108 * @param t Scaling factor of ray, double/float.
109 * @param xr Current x co-ordinate of ray, double/float.
110 * @param yr Current y co-ordinate of ray, double/float.
111 * @param zr Current z co-ordinate of ray, double/float.
112 * @param dxr Component of ray direction along x-axis.
113 * @param dyr Component of ray direction along y-axis.
114 * @param dzr Component of ray direction along z-axis.
115 * @param a Scale factor along x-axis, double/float.
116 * @param b Scale factor along y-axis, double/float.
117 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
118 * @returns dz Difference between reflector and ray co-ordinate along z-axis.
119 */
120template<class T>
121inline T RTRefls<T>::gh(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
122{
123 return t - (zr + t*dzr - c*sqrt(RTRefls::common1(t, xr, yr, dxr, dyr, a, b) + 1)) /
124 (dzr - c/(2*sqrt(RTRefls::common1(t, xr, yr, dxr, dyr, a, b) + 1)) *
125 RTRefls::common2(t, xr, yr, dxr, dyr, a, b));
126}
127
128/**
129 * Grid ellipsoid.
130 *
131 * Calculate difference between ellipsoid z co-ordinate and ray z co-ordinate corresponding to x and y ray co-ordinates.
132 *
133 * @param t Scaling factor of ray, double/float.
134 * @param xr Current x co-ordinate of ray, double/float.
135 * @param yr Current y co-ordinate of ray, double/float.
136 * @param zr Current z co-ordinate of ray, double/float.
137 * @param dxr Component of ray direction along x-axis.
138 * @param dyr Component of ray direction along y-axis.
139 * @param dzr Component of ray direction along z-axis.
140 * @param a Scale factor along x-axis, double/float.
141 * @param b Scale factor along y-axis, double/float.
142 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
143 * @returns dz Difference between reflector and ray co-ordinate along z-axis.
144 */
145template<class T>
146inline T RTRefls<T>::ge(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
147{
148 return t - (zr + t*dzr - c*sqrt(1 - RTRefls::common1(t, xr, yr, dxr, dyr, a, b))) /
149 (dzr + c/(2*sqrt(1 - RTRefls::common1(t, xr, yr, dxr, dyr, a, b))) *
150 RTRefls::common2(t, xr, yr, dxr, dyr, a, b));
151}
152
153/**
154 * Grid plane.
155 *
156 * Calculate difference between plane z co-ordinate and ray z co-ordinate corresponding to x and y ray co-ordinates.
157 *
158 * @param t Scaling factor of ray, double/float.
159 * @param xr Current x co-ordinate of ray, double/float.
160 * @param yr Current y co-ordinate of ray, double/float.
161 * @param zr Current z co-ordinate of ray, double/float.
162 * @param dxr Component of ray direction along x-axis.
163 * @param dyr Component of ray direction along y-axis.
164 * @param dzr Component of ray direction along z-axis.
165 * @param a Scale factor along x-axis, double/float.
166 * @param b Scale factor along y-axis, double/float.
167 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
168 * @returns dz Difference between reflector and ray co-ordinate along z-axis.
169 */
170template<class T>
171inline T RTRefls<T>::gpl(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
172{
173 return t - (zr + t*dzr) / dzr;
174}
175
176/**
177 * Paraboloid normal vectors.
178 *
179 * Calculate normal vectors to point on paraboloid.
180 *
181 * @param xr Current x co-ordinate of ray, double/float.
182 * @param yr Current y co-ordinate of ray, double/float.
183 * @param zr Current z co-ordinate of ray, double/float.
184 * @param flip Direction of normal vectors.
185 * @param a Scale factor along x-axis, double/float.
186 * @param b Scale factor along y-axis, double/float.
187 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
188 * @returns out Array of 3 double/float, containing components of normal vector.
189 */
190template<class T>
191inline std::array<T, 3> RTRefls<T>::np(T xr, T yr, T zr, int flip, T a, T b, T c)
192{
193 std::array<T, 3> out;
194
195 out[0] = -2 * xr / (a*a) * flip;
196 out[1] = -2 * yr / (b*b) * flip;
197 out[2] = flip;
198
199 T norm = sqrt(out[0]*out[0] + out[1]*out[1] + out[2]*out[2]);
200
201 out[0] = out[0] / norm;
202 out[1] = out[1] / norm;
203 out[2] = out[2] / norm;
204
205 return out;
206}
207
208/**
209 * Hyperboloid normal vectors.
210 *
211 * Calculate normal vectors to point on hyperboloid.
212 *
213 * @param xr Current x co-ordinate of ray, double/float.
214 * @param yr Current y co-ordinate of ray, double/float.
215 * @param zr Current z co-ordinate of ray, double/float.
216 * @param flip Direction of normal vectors.
217 * @param a Scale factor along x-axis, double/float.
218 * @param b Scale factor along y-axis, double/float.
219 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
220 * @returns out Array of 3 double/float, containing components of normal vector.
221 */
222template<class T>
223inline std::array<T, 3> RTRefls<T>::nh(T xr, T yr, T zr, int flip, T a, T b, T c)
224{
225 std::array<T, 3> out;
226
227 out[0] = -2 * xr / (a*a) * flip;
228 out[1] = -2 * yr / (b*b) * flip;
229 out[2] = 2 * zr / (c*c) * flip;
230
231 T norm = sqrt(out[0]*out[0] + out[1]*out[1] + out[2]*out[2]);
232
233 out[0] = out[0] / norm;
234 out[1] = out[1] / norm;
235 out[2] = out[2] / norm;
236
237 return out;
238}
239
240/**
241 * Ellipsoid normal vectors.
242 *
243 * Calculate normal vectors to point on ellipsoid.
244 *
245 * @param xr Current x co-ordinate of ray, double/float.
246 * @param yr Current y co-ordinate of ray, double/float.
247 * @param zr Current z co-ordinate of ray, double/float.
248 * @param flip Direction of normal vectors.
249 * @param a Scale factor along x-axis, double/float.
250 * @param b Scale factor along y-axis, double/float.
251 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
252 * @returns out Array of 3 double/float, containing components of normal vector.
253 */
254template<class T>
255inline std::array<T, 3> RTRefls<T>::ne(T xr, T yr, T zr, int flip, T a, T b, T c)
256{
257 std::array<T, 3> out;
258
259 out[0] = 2 * xr / (a*a) * flip;
260 out[1] = 2 * yr / (b*b) * flip;
261 out[2] = 2 * zr / (c*c) * flip;
262
263 T norm = sqrt(out[0]*out[0] + out[1]*out[1] + out[2]*out[2]);
264
265 out[0] = out[0] / norm;
266 out[1] = out[1] / norm;
267 out[2] = out[2] / norm;
268
269 return out;
270}
271
272/**
273 * Plane normal vectors.
274 *
275 * Calculate normal vectors to point on plane.
276 * Seems sort of redundant, but implement this way for consistency.
277 *
278 * @param xr Current x co-ordinate of ray, double/float.
279 * @param yr Current y co-ordinate of ray, double/float.
280 * @param zr Current z co-ordinate of ray, double/float.
281 * @param flip Direction of normal vectors.
282 * @param a Scale factor along x-axis, double/float.
283 * @param b Scale factor along y-axis, double/float.
284 * @param c Scale factor along z-axis, double/float (hyperboloid/ellipsoid only).
285 * @returns out Array of 3 double/float, containing components of normal vector.
286 */
287template<class T>
288inline std::array<T, 3> RTRefls<T>::npl(T xr, T yr, T zr, int flip, T a, T b, T c)
289{
290 std::array<T, 3> out;
291
292 out[0] = 0;
293 out[1] = 0;
294 out[2] = 1;
295
296 return out;
297}
298#endif
Linear algebra functions for the CPU version of PyPO.
Definition RTRefls.h:20
static std::array< T, 3 > npl(T xr, T yr, T zr, int flip, T a, T b, T c)
Definition RTRefls.h:288
static T gp(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
Definition RTRefls.h:97
static T ge(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
Definition RTRefls.h:146
static std::array< T, 3 > ne(T xr, T yr, T zr, int flip, T a, T b, T c)
Definition RTRefls.h:255
static T gh(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
Definition RTRefls.h:121
static T common1(T t, T xr, T yr, T dxr, T dyr, T a, T b)
Definition RTRefls.h:53
static std::array< T, 3 > np(T xr, T yr, T zr, int flip, T a, T b, T c)
Definition RTRefls.h:191
static std::array< T, 3 > nh(T xr, T yr, T zr, int flip, T a, T b, T c)
Definition RTRefls.h:223
static T common2(T t, T xr, T yr, T dxr, T dyr, T a, T b)
Definition RTRefls.h:74
static T gpl(T t, T xr, T yr, T zr, T dxr, T dyr, T dzr, T a, T b, T c)
Definition RTRefls.h:171
Definition Utils.h:23