25 |
|
/* sampling order */ |
26 |
|
static int samp_order = 6; |
27 |
|
/* super-sampling threshold */ |
28 |
< |
const double ssamp_thresh = 0.25; |
28 |
> |
static double ssamp_thresh = 0.35; |
29 |
|
/* number of super-samples */ |
30 |
|
#ifndef NSSAMP |
31 |
|
#define NSSAMP 256 |
129 |
|
{ |
130 |
|
const int sqres = 1<<samp_order; |
131 |
|
const double sqfact = 1./(double)sqres; |
132 |
+ |
float *ryval = NULL; |
133 |
+ |
char *rtrip = NULL; |
134 |
|
FILE *ofp, *uvfp[2]; |
135 |
|
int assignD = 0; |
136 |
|
char cmd[128]; |
191 |
|
} |
192 |
|
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
193 |
|
assignD = (fundefined(funame) < 6); |
194 |
+ |
#if (NSSAMP > 0) |
195 |
+ |
rtrip = (char *)malloc(sqres); /* track sample triggerings */ |
196 |
+ |
ryval = (float *)calloc(sqres, sizeof(float)); |
197 |
+ |
#endif |
198 |
|
/* run through directions */ |
199 |
|
for (ix = 0; ix < sqres/2; ix++) { |
200 |
|
const int zipsgn = (ix & 1)*2 - 1; |
206 |
|
if (funame == NULL) |
207 |
|
rbf = advect_rbf(iovec, lobe_lim); |
208 |
|
for (ox = 0; ox < sqres; ox++) { |
209 |
< |
float last_bsdf = -1; |
209 |
> |
SDValue sdv_next; |
210 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact); |
211 |
> |
iovec[5] = output_orient * |
212 |
> |
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
213 |
> |
if (funame == NULL) { |
214 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
215 |
> |
} else { |
216 |
> |
sdv_next.spec = c_dfcolor; |
217 |
> |
if (assignD) { |
218 |
> |
varset("Dx", '=', -iovec[3]); |
219 |
> |
varset("Dy", '=', -iovec[4]); |
220 |
> |
varset("Dz", '=', -iovec[5]); |
221 |
> |
++eclock; |
222 |
> |
} |
223 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
224 |
> |
} |
225 |
> |
/* |
226 |
> |
* Super-sample when we detect a difference from before |
227 |
> |
* or after in this row, or the previous row in this column. |
228 |
> |
* Also super-sample if the previous neighbors performed |
229 |
> |
* super-sampling, regardless of any differences. |
230 |
> |
*/ |
231 |
> |
memset(rtrip, 0, sqres); |
232 |
|
for (oy = 0; oy < sqres; oy++) { |
233 |
< |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+.5)*sqfact); |
234 |
< |
iovec[5] = output_orient * |
233 |
> |
int trip; |
234 |
> |
bsdf = sdv_next.cieY; /* keeping one step ahead... */ |
235 |
> |
if (oy < sqres-1) { |
236 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact); |
237 |
> |
iovec[5] = output_orient * |
238 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
239 |
+ |
} |
240 |
|
if (funame == NULL) { |
241 |
< |
SDValue sdv; |
242 |
< |
eval_rbfcol(&sdv, rbf, iovec+3); |
243 |
< |
bsdf = sdv.cieY; |
241 |
> |
SDValue sdv = sdv_next; |
242 |
> |
if (oy < sqres-1) |
243 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
244 |
|
#if (NSSAMP > 0) |
245 |
< |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
245 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
246 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
247 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
248 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
249 |
|
int ssi; |
250 |
|
double ssa[2], sum = 0, usum = 0, vsum = 0; |
251 |
|
/* super-sample voxel */ |
279 |
|
uv[1] *= 9.*sdv.spec.cy; |
280 |
|
} |
281 |
|
} else { |
282 |
< |
if (assignD) { |
283 |
< |
varset("Dx", '=', -iovec[3]); |
284 |
< |
varset("Dy", '=', -iovec[4]); |
285 |
< |
varset("Dz", '=', -iovec[5]); |
286 |
< |
++eclock; |
282 |
> |
if (oy < sqres-1) { |
283 |
> |
if (assignD) { |
284 |
> |
varset("Dx", '=', -iovec[3]); |
285 |
> |
varset("Dy", '=', -iovec[4]); |
286 |
> |
varset("Dz", '=', -iovec[5]); |
287 |
> |
++eclock; |
288 |
> |
} |
289 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
290 |
|
} |
253 |
– |
bsdf = funvalue(funame, 6, iovec); |
291 |
|
#if (NSSAMP > 0) |
292 |
< |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
292 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
293 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
294 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
295 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
296 |
|
int ssi; |
297 |
|
double ssa[4], ssvec[6], sum = 0; |
298 |
|
/* super-sample voxel */ |
339 |
|
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
340 |
|
} |
341 |
|
} |
342 |
< |
last_bsdf = bsdf; |
342 |
> |
if (ryval != NULL) { |
343 |
> |
rtrip[oy] = trip; |
344 |
> |
ryval[oy] = bsdf; |
345 |
> |
} |
346 |
|
} |
347 |
|
} |
348 |
|
if (rbf != NULL) |
350 |
|
prog_show((ix+1.)*(2.*sqfact)); |
351 |
|
} |
352 |
|
prog_done(); |
353 |
+ |
if (ryval != NULL) { |
354 |
+ |
free(rtrip); |
355 |
+ |
free(ryval); |
356 |
+ |
} |
357 |
|
if (pctcull >= 0) { /* finish output */ |
358 |
|
if (pclose(ofp)) { |
359 |
|
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
397 |
|
{ |
398 |
|
const int sqres = 1<<samp_order; |
399 |
|
const double sqfact = 1./(double)sqres; |
400 |
+ |
float *ryval = NULL; |
401 |
+ |
char *rtrip = NULL; |
402 |
|
FILE *ofp, *uvfp[2]; |
403 |
|
int assignD = 0; |
404 |
|
char cmd[128]; |
464 |
|
} |
465 |
|
if (funame != NULL) /* need to assign Dx, Dy, Dz? */ |
466 |
|
assignD = (fundefined(funame) < 6); |
467 |
+ |
#if (NSSAMP > 0) |
468 |
+ |
rtrip = (char *)malloc(sqres); /* track sample triggerings */ |
469 |
+ |
ryval = (float *)calloc(sqres, sizeof(float)); |
470 |
+ |
#endif |
471 |
|
/* run through directions */ |
472 |
|
for (ix = 0; ix < sqres; ix++) |
473 |
|
for (iy = 0; iy < sqres; iy++) { |
478 |
|
if (funame == NULL) |
479 |
|
rbf = advect_rbf(iovec, lobe_lim); |
480 |
|
for (ox = 0; ox < sqres; ox++) { |
481 |
< |
float last_bsdf = -1; |
481 |
> |
SDValue sdv_next; |
482 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, .5*sqfact); |
483 |
> |
iovec[5] = output_orient * |
484 |
> |
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
485 |
> |
if (funame == NULL) { |
486 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
487 |
> |
} else { |
488 |
> |
sdv_next.spec = c_dfcolor; |
489 |
> |
if (assignD) { |
490 |
> |
varset("Dx", '=', -iovec[3]); |
491 |
> |
varset("Dy", '=', -iovec[4]); |
492 |
> |
varset("Dz", '=', -iovec[5]); |
493 |
> |
++eclock; |
494 |
> |
} |
495 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
496 |
> |
} |
497 |
> |
/* |
498 |
> |
* Super-sample when we detect a difference from before |
499 |
> |
* or after in this row, or the previous row in this column. |
500 |
> |
* Also super-sample if the previous neighbors performed |
501 |
> |
* super-sampling, regardless of any differences. |
502 |
> |
*/ |
503 |
> |
memset(rtrip, 0, sqres); |
504 |
|
for (oy = 0; oy < sqres; oy++) { |
505 |
< |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+.5)*sqfact); |
506 |
< |
iovec[5] = output_orient * |
505 |
> |
int trip; |
506 |
> |
bsdf = sdv_next.cieY; /* keeping one step ahead... */ |
507 |
> |
if (oy < sqres-1) { |
508 |
> |
SDsquare2disk(iovec+3, (ox+.5)*sqfact, (oy+1.5)*sqfact); |
509 |
> |
iovec[5] = output_orient * |
510 |
|
sqrt(1. - iovec[3]*iovec[3] - iovec[4]*iovec[4]); |
511 |
+ |
} |
512 |
|
if (funame == NULL) { |
513 |
< |
SDValue sdv; |
514 |
< |
eval_rbfcol(&sdv, rbf, iovec+3); |
515 |
< |
bsdf = sdv.cieY; |
513 |
> |
SDValue sdv = sdv_next; |
514 |
> |
if (oy < sqres-1) |
515 |
> |
eval_rbfcol(&sdv_next, rbf, iovec+3); |
516 |
|
#if (NSSAMP > 0) |
517 |
< |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
517 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
518 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
519 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
520 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
521 |
|
int ssi; |
522 |
|
double ssa[2], sum = 0, usum = 0, vsum = 0; |
523 |
|
/* super-sample voxel */ |
551 |
|
uv[1] *= 9.*sdv.spec.cy; |
552 |
|
} |
553 |
|
} else { |
554 |
< |
if (assignD) { |
555 |
< |
varset("Dx", '=', -iovec[3]); |
556 |
< |
varset("Dy", '=', -iovec[4]); |
557 |
< |
varset("Dz", '=', -iovec[5]); |
558 |
< |
++eclock; |
554 |
> |
if (oy < sqres-1) { |
555 |
> |
if (assignD) { |
556 |
> |
varset("Dx", '=', -iovec[3]); |
557 |
> |
varset("Dy", '=', -iovec[4]); |
558 |
> |
varset("Dz", '=', -iovec[5]); |
559 |
> |
++eclock; |
560 |
> |
} |
561 |
> |
sdv_next.cieY = funvalue(funame, 6, iovec); |
562 |
|
} |
478 |
– |
bsdf = funvalue(funame, 6, iovec); |
563 |
|
#if (NSSAMP > 0) |
564 |
< |
if (abs_diff(bsdf, last_bsdf) > ssamp_thresh) { |
564 |
> |
trip = (abs_diff(bsdf, sdv_next.cieY) > ssamp_thresh || |
565 |
> |
(ox && abs_diff(bsdf, ryval[oy]) > ssamp_thresh) || |
566 |
> |
(oy && abs_diff(bsdf, ryval[oy-1]) > ssamp_thresh)); |
567 |
> |
if (trip | rtrip[oy] || (oy && rtrip[oy-1])) { |
568 |
|
int ssi; |
569 |
|
double ssa[4], ssvec[6], sum = 0; |
570 |
|
/* super-sample voxel */ |
607 |
|
fprintf(uvfp[1], "\t%.3e\n", uv[1]); |
608 |
|
} |
609 |
|
} |
610 |
< |
last_bsdf = bsdf; |
610 |
> |
if (ryval != NULL) { |
611 |
> |
rtrip[oy] = trip; |
612 |
> |
ryval[oy] = bsdf; |
613 |
> |
} |
614 |
|
} |
525 |
– |
} |
615 |
|
if (rbf != NULL) |
616 |
|
free(rbf); |
617 |
|
prog_show((ix*sqres+iy+1.)/(sqres*sqres)); |
618 |
|
} |
619 |
+ |
} |
620 |
|
prog_done(); |
621 |
+ |
if (ryval != NULL) { |
622 |
+ |
free(rtrip); |
623 |
+ |
free(ryval); |
624 |
+ |
} |
625 |
|
if (pctcull >= 0) { /* finish output */ |
626 |
|
if (pclose(ofp)) { |
627 |
|
fprintf(stderr, "%s: error running rttree_reduce on Y\n", |
807 |
|
goto userr; |
808 |
|
} |
809 |
|
++eclock; |
810 |
+ |
ssamp_thresh *= 0.5; /* lower sampling threshold */ |
811 |
|
add_wbsdf("-a", 1); |
812 |
|
add_wbsdf(tfmt[single_plane_incident], 1); |
813 |
|
if (dofwd) { |