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" |
17 |
|
#include "bsdfrep.h" |
18 |
|
|
20 |
– |
char *progname; |
21 |
– |
|
19 |
|
/* Read in a vector pair */ |
20 |
|
static int |
21 |
|
readIOdir(FVECT idir, FVECT odir, FILE *fp, int fmt) |
22 |
|
{ |
23 |
|
double dvec[6]; |
24 |
|
float fvec[6]; |
25 |
< |
|
25 |
> |
tryagain: |
26 |
|
switch (fmt) { |
27 |
|
case 'a': |
28 |
|
if (fscanf(fp, FVFORMAT, &idir[0], &idir[1], &idir[2]) != 3 || |
43 |
|
break; |
44 |
|
} |
45 |
|
if ((normalize(idir) == 0) | (normalize(odir) == 0)) { |
46 |
< |
fprintf(stderr, "%s: zero input vector!\n", progname); |
47 |
< |
return(0); |
46 |
> |
fflush(stdout); /* desired side-effect? */ |
47 |
> |
goto tryagain; |
48 |
|
} |
49 |
|
return(1); |
50 |
|
} |
53 |
|
int |
54 |
|
main(int argc, char *argv[]) |
55 |
|
{ |
56 |
+ |
int unbuffered = 0; |
57 |
|
int repXYZ = 0; |
58 |
|
int inpXML = -1; |
59 |
|
int inpfmt = 'a'; |
63 |
|
SDData myBSDF; |
64 |
|
FVECT idir, odir; |
65 |
|
int n; |
66 |
+ |
/* set global progname */ |
67 |
+ |
fixargv0(argv[0]); |
68 |
|
/* check arguments */ |
69 |
– |
progname = argv[0]; |
69 |
|
while (argc > 2 && argv[1][0] == '-') { |
70 |
|
switch (argv[1][1]) { |
71 |
+ |
case 'u': /* unbuffered output */ |
72 |
+ |
unbuffered = 1; |
73 |
+ |
break; |
74 |
|
case 'c': /* color output */ |
75 |
|
repXYZ = 1; |
76 |
|
break; |
137 |
|
if (SDreportError(eval_rbfcol(&sval, rbf, odir), stderr)) |
138 |
|
return(1); |
139 |
|
} |
138 |
– |
if (repXYZ) /* ensure we have CIE (x,y) */ |
139 |
– |
c_ccvt(&sval.spec, C_CSXY); |
140 |
|
|
141 |
|
switch (outfmt) { /* write to stdout */ |
142 |
|
case 'a': |
173 |
|
} |
174 |
|
break; |
175 |
|
} |
176 |
+ |
if (unbuffered) |
177 |
+ |
fflush(stdout); |
178 |
|
} |
179 |
|
/* if (rbf != NULL) free(rbf); */ |
180 |
|
return(0); |
181 |
|
userr: |
182 |
< |
fprintf(stderr, "Usage: %s [-c][-fio] bsdf.{sir|xml}\n", progname); |
182 |
> |
fprintf(stderr, "Usage: %s [-u][-c][-fio] bsdf.{sir|xml}\n", progname); |
183 |
|
return(1); |
184 |
|
} |