ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/testBSDF.c
(Generate patch)

Comparing ray/src/common/testBSDF.c (file contents):
Revision 1.3 by greg, Sat Jun 6 16:30:26 2015 UTC vs.
Revision 1.9 by greg, Thu Feb 2 04:46:38 2017 UTC

# Line 20 | Line 20 | Usage(const char *prog)
20   {
21          printf("Usage: %s [bsdf_directory]\n", prog);
22          printf("Input commands:\n");
23 <        printf("  l bsdf.xml\t\t\t Load (make active) given BSDF input file\n");
24 <        printf("  q theta_i phi_i theta_o phi_o\t Query BSDF for given path\n");
25 <        printf("  s N theta phi\t\t\t Generate N ray directions at given incidence\n");
26 <        printf("  h theta phi\t\t\t Report hemispherical total at given incidence\n");
27 <        printf("  r theta phi\t\t\t Report hemispherical reflection at given incidence\n");
28 <        printf("  t theta phi\t\t\t Report hemispherical transmission at given incidence\n");
23 >        printf("  L bsdf.xml\t\t\t Load (make active) given BSDF input file\n");
24 >        printf("  i\t\t\t\t Report general information (metadata)\n");
25 >        printf("  c\t\t\t\t Report diffuse and specular components\n");
26 >        printf("  q theta_i phi_i theta_o phi_o\t Query BSDF for given path (CIE-XYZ)\n");
27 >        printf("  s[r|t][s|d] N theta phi\t\t\t Generate N ray directions & colors at given incidence\n");
28 >        printf("  h[s|d] theta phi\t\t\t Report hemispherical scatteromg at given incidence\n");
29 >        printf("  r[s|d] theta phi\t\t\t Report hemispherical reflection at given incidence\n");
30 >        printf("  t[s|d] theta phi\t\t\t Report hemispherical transmission at given incidence\n");
31          printf("  a theta phi [t2 p2]\t\t Report resolution (in proj. steradians) for given direction(s)\n");
32          printf("  ^D\t\t\t\t Quit program\n");
33   }
# Line 42 | Line 44 | vec_from_deg(FVECT v, double theta, double phi)
44          v[2] = cos(theta);
45   }
46  
47 + static void
48 + printXYZ(const char *intro, const SDValue *vp)
49 + {
50 +        printf("%s%.3e %.3e %.3e\n", intro,
51 +                        vp->spec.cx/vp->spec.cy*vp->cieY,
52 +                        vp->cieY,
53 +                        (1.-vp->spec.cx-vp->spec.cy)/
54 +                        vp->spec.cy*vp->cieY);
55 + }
56 +
57   int
58   main(int argc, char *argv[])
59   {
# Line 59 | Line 71 | main(int argc, char *argv[])
71          SDretainSet = SDretainBSDFs;            /* keep BSDFs in memory */
72  
73                                                  /* loop on command */
74 <        while (fgets(inp, sizeof(inp), stdin) != NULL) {
74 >        while (fgets(inp, sizeof(inp), stdin)) {
75                  int     sflags = SDsampAll;
76                  char    *cp = inp;
77                  char    *cp2;
78                  FVECT   vin, vout;
79                  double  proja[2];
80 <                int     n;
80 >                int     n, i;
81                  SDValue val;
82                  
83                  while (isspace(*cp)) cp++;
84  
85 <                switch (*cp) {
74 <                case 'l':
85 >                switch (toupper(*cp)) {
86                  case 'L':                       /* load/activate BSDF input */
87                          cp2 = cp = sskip2(cp, 1);
88                          if (!*cp)
# Line 86 | Line 97 | main(int argc, char *argv[])
97                                  SDfreeCache(bsdf);
98                          bsdf = SDcacheFile(path);
99                          continue;
100 <                case 'q':
100 >                case 'I':                       /* report general info. */
101 >                        if (!bsdf)
102 >                                goto noBSDFerr;
103 >                        printf("Material: '%s'\n", bsdf->matn);
104 >                        printf("Manufacturer: '%s'\n", bsdf->makr);
105 >                        printf("Width, Height, Thickness (m): %.4e, %.4e, %.4e\n",
106 >                                        bsdf->dim[0], bsdf->dim[1], bsdf->dim[2]);
107 >                        printf("Has geometry: %s\n", bsdf->mgf ? "yes" : "no");
108 >                        continue;
109 >                case 'C':                       /* report constant values */
110 >                        if (!bsdf)
111 >                                goto noBSDFerr;
112 >                        if (bsdf->rf)
113 >                                printf("Peak front hemispherical reflectance: %.3e\n",
114 >                                                bsdf->rLambFront.cieY +
115 >                                                bsdf->rf->maxHemi);
116 >                        if (bsdf->rb)
117 >                                printf("Peak back hemispherical reflectance: %.3e\n",
118 >                                                bsdf->rLambBack.cieY +
119 >                                                bsdf->rb->maxHemi);
120 >                        if (bsdf->tf)
121 >                                printf("Peak front hemispherical transmittance: %.3e\n",
122 >                                                bsdf->tLamb.cieY + bsdf->tf->maxHemi);
123 >                        if (bsdf->tb)
124 >                                printf("Peak back hemispherical transmittance: %.3e\n",
125 >                                                bsdf->tLamb.cieY + bsdf->tb->maxHemi);
126 >                        printXYZ("Diffuse Front Reflectance: ", &bsdf->rLambFront);
127 >                        printXYZ("Diffuse Back Reflectance: ", &bsdf->rLambBack);
128 >                        printXYZ("Diffuse Transmittance: ", &bsdf->tLamb);
129 >                        continue;
130                  case 'Q':                       /* query BSDF value */
131 <                        if (bsdf == NULL)
131 >                        if (!bsdf)
132                                  goto noBSDFerr;
133                          if (!*sskip2(cp,4))
134                                  break;
135                          vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2)));
136                          vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4)));
137                          if (!SDreportError(SDevalBSDF(&val, vout, vin, bsdf), stderr))
138 <                                printf("%.3e\n", val.cieY);
138 >                                printXYZ("", &val);
139                          continue;
100                case 's':
140                  case 'S':                       /* sample BSDF */
141 <                        if (bsdf == NULL)
141 >                        if (!bsdf)
142                                  goto noBSDFerr;
143                          if (!*sskip2(cp,3))
144                                  break;
145 <                        n = atoi(sskip2(cp,1));
145 >                        if (toupper(cp[1]) == 'R') {
146 >                                sflags &= ~SDsampT;
147 >                                ++cp;
148 >                        } else if (toupper(cp[1]) == 'T') {
149 >                                sflags &= ~SDsampR;
150 >                                ++cp;
151 >                        }
152 >                        if (toupper(cp[1]) == 'S')
153 >                                sflags &= ~SDsampDf;
154 >                        else if (toupper(cp[1]) == 'D')
155 >                                sflags &= ~SDsampSp;
156 >                        i = n = atoi(sskip2(cp,1));
157                          vec_from_deg(vin, atof(sskip2(cp,2)), atof(sskip2(cp,3)));
158 <                        while (n-- > 0) {
159 <                                if (SDreportError(SDsampBSDF(&val, vin,
160 <                                                rand()*(1./(RAND_MAX+.5)),
158 >                        while (i-- > 0) {
159 >                                VCOPY(vout, vin);
160 >                                if (SDreportError(SDsampBSDF(&val, vout,
161 >                                                (i+rand()*(1./(RAND_MAX+.5)))/(double)n,
162                                                  sflags, bsdf), stderr))
163                                          break;
164 <                                printf("%.8f %.8f %.8f\n", vin[0], vin[1], vin[2]);
164 >                                printf("%.8f %.8f %.8f ", vout[0], vout[1], vout[2]);
165 >                                printXYZ("", &val);
166                          }
167                          continue;
168 <                case 'h':
117 <                case 'H':                       /* hemispherical totals */
118 <                case 'r':
168 >                case 'H':                       /* hemispherical values */
169                  case 'R':
120                case 't':
170                  case 'T':
171 <                        if (bsdf == NULL)
171 >                        if (!bsdf)
172                                  goto noBSDFerr;
173                          if (!*sskip2(cp,2))
174                                  break;
175 <                        if (tolower(*cp) == 'r')
175 >                        if (toupper(cp[0]) == 'R')
176                                  sflags &= ~SDsampT;
177 <                        else if (tolower(*cp) == 't')
177 >                        else if (toupper(cp[0]) == 'T')
178                                  sflags &= ~SDsampR;
179 +                        if (toupper(cp[1]) == 'S')
180 +                                sflags &= ~SDsampDf;
181 +                        else if (toupper(cp[1]) == 'D')
182 +                                sflags &= ~SDsampSp;
183                          vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2)));
184                          printf("%.4e\n", SDdirectHemi(vin, sflags, bsdf));
185                          continue;
133                case 'a':
186                  case 'A':                       /* resolution in proj. steradians */
187 <                        if (bsdf == NULL)
187 >                        if (!bsdf)
188                                  goto noBSDFerr;
189                          if (!*sskip2(cp,2))
190                                  break;
# Line 151 | Line 203 | main(int argc, char *argv[])
203                  Usage(argv[0]);
204                  continue;
205   noBSDFerr:
206 <                fprintf(stderr, "%s: need to use 'l' command to load BSDF\n", argv[0]);
206 >                fprintf(stderr, "%s: First, use 'L' command to load BSDF\n", argv[0]);
207          }
208          return 0;
209   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines