| 8 | 
  | 
 */ | 
| 9 | 
  | 
 | 
| 10 | 
  | 
#define _USE_MATH_DEFINES | 
| 11 | 
– | 
#include <stdio.h> | 
| 11 | 
  | 
#include <stdlib.h> | 
| 12 | 
  | 
#include <math.h> | 
| 13 | 
  | 
#include <ctype.h> | 
| 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 | 
  | 
} | 
| 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, | 
| 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++; | 
| 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 ? "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) | 
| 118 | 
  | 
                                goto noBSDFerr; | 
| 133 | 
  | 
                        printXYZ("Diffuse Front Reflectance: ", &bsdf->rLambFront); | 
| 134 | 
  | 
                        printXYZ("Diffuse Back Reflectance: ", &bsdf->rLambBack); | 
| 135 | 
  | 
                        printXYZ("Diffuse Transmittance: ", &bsdf->tLamb); | 
| 136 | 
< | 
                        continue; | 
| 136 | 
> | 
                        break; | 
| 137 | 
  | 
                case 'Q':                       /* query BSDF value */ | 
| 138 | 
  | 
                        if (!bsdf) | 
| 139 | 
  | 
                                goto noBSDFerr; | 
| 143 | 
  | 
                        vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4))); | 
| 144 | 
  | 
                        if (!SDreportError(SDevalBSDF(&val, vout, vin, bsdf), stderr)) | 
| 145 | 
  | 
                                printXYZ("", &val); | 
| 146 | 
< | 
                        continue; | 
| 146 | 
> | 
                        break; | 
| 147 | 
  | 
                case 'S':                       /* sample BSDF */ | 
| 148 | 
  | 
                        if (!bsdf) | 
| 149 | 
  | 
                                goto noBSDFerr; | 
| 150 | 
  | 
                        if (!*sskip2(cp,3)) | 
| 151 | 
  | 
                                break; | 
| 152 | 
< | 
                        n = atoi(sskip2(cp,1)); | 
| 152 | 
> | 
                        if (toupper(cp[1]) == 'R') { | 
| 153 | 
> | 
                                sflags &= ~SDsampT; | 
| 154 | 
> | 
                                ++cp; | 
| 155 | 
> | 
                        } else if (toupper(cp[1]) == 'T') { | 
| 156 | 
> | 
                                sflags &= ~SDsampR; | 
| 157 | 
> | 
                                ++cp; | 
| 158 | 
> | 
                        } | 
| 159 | 
> | 
                        if (toupper(cp[1]) == 'S') | 
| 160 | 
> | 
                                sflags &= ~SDsampDf; | 
| 161 | 
> | 
                        else if (toupper(cp[1]) == 'D') | 
| 162 | 
> | 
                                sflags &= ~SDsampSp; | 
| 163 | 
> | 
                        i = n = atoi(sskip2(cp,1)); | 
| 164 | 
  | 
                        vec_from_deg(vin, atof(sskip2(cp,2)), atof(sskip2(cp,3))); | 
| 165 | 
< | 
                        while (n-- > 0) { | 
| 166 | 
< | 
                                if (SDreportError(SDsampBSDF(&val, vin, | 
| 167 | 
< | 
                                                rand()*(1./(RAND_MAX+.5)), | 
| 165 | 
> | 
                        while (i-- > 0) { | 
| 166 | 
> | 
                                VCOPY(vout, vin); | 
| 167 | 
> | 
                                if (SDreportError(SDsampBSDF(&val, vout, | 
| 168 | 
> | 
                                                (i+rand()*(1./(RAND_MAX+.5)))/(double)n, | 
| 169 | 
  | 
                                                sflags, bsdf), stderr)) | 
| 170 | 
  | 
                                        break; | 
| 171 | 
< | 
                                printf("%.8f %.8f %.8f\n", vin[0], vin[1], vin[2]); | 
| 171 | 
> | 
                                printf("%.8f %.8f %.8f ", vout[0], vout[1], vout[2]); | 
| 172 | 
> | 
                                printXYZ("", &val); | 
| 173 | 
  | 
                        } | 
| 174 | 
< | 
                        continue; | 
| 175 | 
< | 
                case 'H':                       /* hemispherical totals */ | 
| 174 | 
> | 
                        break; | 
| 175 | 
> | 
                case 'H':                       /* hemispherical values */ | 
| 176 | 
  | 
                case 'R': | 
| 177 | 
  | 
                case 'T': | 
| 178 | 
  | 
                        if (!bsdf) | 
| 179 | 
  | 
                                goto noBSDFerr; | 
| 180 | 
  | 
                        if (!*sskip2(cp,2)) | 
| 181 | 
  | 
                                break; | 
| 182 | 
< | 
                        if (tolower(*cp) == 'r') | 
| 182 | 
> | 
                        if (toupper(cp[0]) == 'R') | 
| 183 | 
  | 
                                sflags &= ~SDsampT; | 
| 184 | 
< | 
                        else if (tolower(*cp) == 't') | 
| 184 | 
> | 
                        else if (toupper(cp[0]) == 'T') | 
| 185 | 
  | 
                                sflags &= ~SDsampR; | 
| 186 | 
+ | 
                        if (toupper(cp[1]) == 'S') | 
| 187 | 
+ | 
                                sflags &= ~SDsampDf; | 
| 188 | 
+ | 
                        else if (toupper(cp[1]) == 'D') | 
| 189 | 
+ | 
                                sflags &= ~SDsampSp; | 
| 190 | 
  | 
                        vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); | 
| 191 | 
  | 
                        printf("%.4e\n", SDdirectHemi(vin, sflags, bsdf)); | 
| 192 | 
< | 
                        continue; | 
| 192 | 
> | 
                        break; | 
| 193 | 
  | 
                case 'A':                       /* resolution in proj. steradians */ | 
| 194 | 
  | 
                        if (!bsdf) | 
| 195 | 
  | 
                                goto noBSDFerr; | 
| 198 | 
  | 
                        vec_from_deg(vin, atof(sskip2(cp,1)), atof(sskip2(cp,2))); | 
| 199 | 
  | 
                        if (*sskip2(cp,4)) { | 
| 200 | 
  | 
                                vec_from_deg(vout, atof(sskip2(cp,3)), atof(sskip2(cp,4))); | 
| 201 | 
< | 
                                if (SDreportError(SDsizeBSDF(proja, vin, vout, | 
| 201 | 
> | 
                                if (SDreportError(SDsizeBSDF(proja, vout, vin, | 
| 202 | 
  | 
                                                SDqueryMin+SDqueryMax, bsdf), stderr)) | 
| 203 | 
  | 
                                        continue; | 
| 204 | 
  | 
                        } else if (SDreportError(SDsizeBSDF(proja, vin, NULL, | 
| 205 | 
  | 
                                                SDqueryMin+SDqueryMax, bsdf), stderr)) | 
| 206 | 
  | 
                                        continue; | 
| 207 | 
  | 
                        printf("%.4e %.4e\n", proja[0], proja[1]); | 
| 208 | 
< | 
                        continue; | 
| 208 | 
> | 
                        break; | 
| 209 | 
> | 
                default: | 
| 210 | 
> | 
                        Usage(argv[0]); | 
| 211 | 
> | 
                        break; | 
| 212 | 
  | 
                } | 
| 213 | 
< | 
                Usage(argv[0]); | 
| 213 | 
> | 
                fflush(stdout);                 /* in case we're on remote */ | 
| 214 | 
  | 
                continue; | 
| 215 | 
  | 
noBSDFerr: | 
| 216 | 
  | 
                fprintf(stderr, "%s: First, use 'L' command to load BSDF\n", argv[0]); |