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.7 by greg, Thu Feb 2 00:30:16 2017 UTC vs.
Revision 1.17 by greg, Tue Dec 7 23:49:50 2021 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines