5 |
|
* Query values from the given BSDF (scattering interpolant or XML repres.) |
6 |
|
* Input query is incident and exiting vectors directed away from surface. |
7 |
|
* We normalize. Output is a BSDF value for the vector pair. |
8 |
+ |
* A zero length in or out vector is ignored, causing output to be flushed. |
9 |
|
* It is wise to sort the input directions to keep identical ones together |
10 |
|
* when using a scattering interpolant representation. |
11 |
|
*/ |
12 |
|
|
13 |
|
#define _USE_MATH_DEFINES |
13 |
– |
#include <stdio.h> |
14 |
– |
#include <string.h> |
14 |
|
#include <stdlib.h> |
15 |
|
#include "rtmath.h" |
16 |
|
#include "rtio.h" |
24 |
|
{ |
25 |
|
double dvec[6]; |
26 |
|
float fvec[6]; |
27 |
< |
|
27 |
> |
tryagain: |
28 |
|
switch (fmt) { |
29 |
|
case 'a': |
30 |
|
if (fscanf(fp, FVFORMAT, &idir[0], &idir[1], &idir[2]) != 3 || |
45 |
|
break; |
46 |
|
} |
47 |
|
if ((normalize(idir) == 0) | (normalize(odir) == 0)) { |
48 |
< |
fprintf(stderr, "%s: zero input vector!\n", progname); |
49 |
< |
return(0); |
48 |
> |
fflush(stdout); /* desired side-effect? */ |
49 |
> |
goto tryagain; |
50 |
|
} |
51 |
|
return(1); |
52 |
|
} |
55 |
|
int |
56 |
|
main(int argc, char *argv[]) |
57 |
|
{ |
58 |
+ |
int unbuffered = 0; |
59 |
|
int repXYZ = 0; |
60 |
|
int inpXML = -1; |
61 |
|
int inpfmt = 'a'; |
69 |
|
progname = argv[0]; |
70 |
|
while (argc > 2 && argv[1][0] == '-') { |
71 |
|
switch (argv[1][1]) { |
72 |
+ |
case 'u': /* unbuffered output */\ |
73 |
+ |
unbuffered = 1; |
74 |
+ |
break; |
75 |
|
case 'c': /* color output */ |
76 |
|
repXYZ = 1; |
77 |
|
break; |
174 |
|
} |
175 |
|
break; |
176 |
|
} |
177 |
+ |
if (unbuffered) |
178 |
+ |
fflush(stdout); |
179 |
|
} |
180 |
|
/* if (rbf != NULL) free(rbf); */ |
181 |
|
return(0); |
182 |
|
userr: |
183 |
< |
fprintf(stderr, "Usage: %s [-c][-fio] bsdf.{sir|xml}\n", progname); |
183 |
> |
fprintf(stderr, "Usage: %s [-u][-c][-fio] bsdf.{sir|xml}\n", progname); |
184 |
|
return(1); |
185 |
|
} |