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.2 by greg, Fri Jun 5 18:58:37 2015 UTC vs.
Revision 1.6 by greg, Thu Feb 2 00:27:55 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");
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 N theta phi\t\t\t Generate N ray directions at given incidence\n");
28          printf("  h theta phi\t\t\t Report hemispherical total at given incidence\n");
29          printf("  r theta phi\t\t\t Report hemispherical reflection at given incidence\n");
# 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   {
60 <        const char      *directory = "";
60 >        const char      *directory = NULL;
61          char            inp[512], path[512];
62          const SDData    *bsdf = NULL;
63  
# Line 56 | Line 68 | main(int argc, char *argv[])
68          if (argc == 2)
69                  directory = argv[1];
70          
71 <        SDretainSet = SDretainBSDFs;            /* keep BSDFs loaded */
71 >        SDretainSet = SDretainBSDFs;            /* keep BSDFs in memory */
72  
73                                                  /* loop on command */
74          while (fgets(inp, sizeof(inp), stdin) != NULL) {
# Line 70 | Line 82 | main(int argc, char *argv[])
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)
89                                  break;
90                          while (*cp) cp++;
91                          while (isspace(*--cp)) *cp = '\0';
92 <                        if (directory[0])
92 >                        if (directory)
93                                  sprintf(path, "%s/%s", directory, cp2);
94                          else
95                                  strcpy(path, cp2);
96 <                        if (bsdf != NULL)
96 >                        if (bsdf)
97                                  SDfreeCache(bsdf);
98                          bsdf = SDcacheFile(path);
99                          continue;
100 <                case 'q':
100 >                case 'I':                       /* report general info. */
101 >                        if (bsdf == NULL)
102 >                                goto noBSDFerr;
103 >                        printf("Material: '%s'\n", bsdf->matn);
104 >                        printf("Manufacturer: '%s'\n", bsdf->makr);
105 >                        printf("Has geometry: %s\n", bsdf->mgf!=NULL ? "yes" : "no");
106 >                        printf("Width, Height, Thickness (m): %.4e, %.4e, %.4e\n",
107 >                                        bsdf->dim[0], bsdf->dim[1], bsdf->dim[2]);
108 >                        continue;
109 >                case 'C':                       /* report constant values */
110 >                        if (bsdf == NULL)
111 >                                goto noBSDFerr;
112 >                        if (bsdf->rf != NULL)
113 >                                printf("Peak front hemispherical reflectance: %.3e\n",
114 >                                                bsdf->rLambFront.cieY +
115 >                                                bsdf->rf->maxHemi);
116 >                        if (bsdf->rb != NULL)
117 >                                printf("Peak back hemispherical reflectance: %.3e\n",
118 >                                                bsdf->rLambBack.cieY +
119 >                                                bsdf->rb->maxHemi);
120 >                        if (bsdf->tf != NULL)
121 >                                printf("Peak front hemispherical transmittance: %.3e\n",
122 >                                                bsdf->tLamb.cieY + bsdf->tf->maxHemi);
123 >                        if (bsdf->tb != NULL)
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)
132                                  goto noBSDFerr;
# Line 95 | Line 135 | main(int argc, char *argv[])
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)
142                                  goto noBSDFerr;
# Line 113 | Line 152 | main(int argc, char *argv[])
152                                  printf("%.8f %.8f %.8f\n", vin[0], vin[1], vin[2]);
153                          }
154                          continue;
116                case 'h':
155                  case 'H':                       /* hemispherical totals */
118                case 'r':
156                  case 'R':
120                case 't':
157                  case 'T':
158                          if (bsdf == NULL)
159                                  goto noBSDFerr;
160                          if (!*sskip2(cp,2))
161                                  break;
162                          if (tolower(*cp) == 'r')
163 <                                sflags ^= SDsampT;
163 >                                sflags &= ~SDsampT;
164                          else if (tolower(*cp) == 't')
165 <                                sflags ^= SDsampR;
165 >                                sflags &= ~SDsampR;
166                          vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2)));
167                          printf("%.4e\n", SDdirectHemi(vin, sflags, bsdf));
168                          continue;
169 <                case 'a':
134 <                case 'A':                       /* resolution in degrees */
169 >                case 'A':                       /* resolution in proj. steradians */
170                          if (bsdf == NULL)
171                                  goto noBSDFerr;
172                          if (!*sskip2(cp,2))
# Line 151 | Line 186 | main(int argc, char *argv[])
186                  Usage(argv[0]);
187                  continue;
188   noBSDFerr:
189 <                fprintf(stderr, "%s: need to use 'l' command to load BSDF\n", argv[0]);
189 >                fprintf(stderr, "%s: First, use 'L' command to load BSDF\n", argv[0]);
190          }
191          return 0;
192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines