ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum4.c
Revision: 2.1
Committed: Tue Sep 18 19:51:07 2007 UTC (17 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Partway addition of BSDF data in mkillum

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2     static const char RCSid[] = "$Id$";
3     #endif
4     /*
5     * Routines for handling BSDF data within mkillum
6     */
7    
8     #include "mkillum.h"
9     #include "paths.h"
10    
11    
12     struct BSDF_data *
13     load_BSDF( /* load BSDF data from file */
14     char *fname
15     )
16     {
17     char *path;
18     FILE *fp;
19     struct BSDF_data *dp;
20    
21     path = getpath(fname, getrlibpath(), R_OK);
22     if (path == NULL) {
23     sprintf(errmsg, "cannot find BSDF file \"%s\"", fname);
24     error(WARNING, errmsg);
25     return(NULL);
26     }
27     if ((fp = fopen(path, "r")) == NULL) {
28     sprintf(errmsg, "cannot open BSDF \"%s\"", path);
29     error(WARNING, errmsg);
30     return(NULL);
31     }
32     dp = (struct BSDF_data *)malloc(sizeof(struct BSDF_data));
33     if (dp == NULL)
34     goto memerr;
35     /* etc... */
36     fclose(fp);
37     return(dp);
38     memerr:
39     error(SYSTEM, "out of memory in load_BSDF");
40     return NULL; /* pro forma return */
41     }
42    
43    
44     void
45     free_BSDF( /* free BSDF data structure */
46     struct BSDF_data *b
47     )
48     {
49     if (b == NULL)
50     return;
51     free(b->inc_dir);
52     free(b->inc_rad);
53     free(b->out_dir);
54     free(b->out_rad);
55     free(b->bsdf);
56     free(b);
57     }
58    
59    
60     void
61     r_BSDF_incvec( /* compute random input vector at given location */
62     FVECT v,
63     struct BSDF_data *b,
64     int i,
65     double rv,
66     MAT4 xm
67     )
68     {
69     FVECT pert;
70     double rad;
71     int j;
72    
73     getBSDF_incvec(v, b, i);
74     rad = getBSDF_incrad(b, i);
75     multisamp(pert, 3, rv);
76     for (j = 0; j < 3; j++)
77     v[j] += rad*(2.*pert[j] - 1.);
78     if (xm != NULL)
79     multv3(v, v, xm);
80     normalize(v);
81     }
82    
83    
84     void
85     r_BSDF_outvec( /* compute random output vector at given location */
86     FVECT v,
87     struct BSDF_data *b,
88     int o,
89     double rv,
90     MAT4 xm
91     )
92     {
93     FVECT pert;
94     double rad;
95     int j;
96    
97     getBSDF_outvec(v, b, o);
98     rad = getBSDF_outrad(b, o);
99     multisamp(pert, 3, rv);
100     for (j = 0; j < 3; j++)
101     v[j] += rad*(2.*pert[j] - 1.);
102     if (xm != NULL)
103     multv3(v, v, xm);
104     normalize(v);
105     }