ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/mkillum2.c
Revision: 1.2
Committed: Wed Jul 24 12:22:05 1991 UTC (32 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +124 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Routines to do the actual calcultion and output for mkillum
9     */
10    
11     #include "mkillum.h"
12    
13     #include "face.h"
14    
15     #include "cone.h"
16    
17 greg 1.2 #include "random.h"
18 greg 1.1
19 greg 1.2
20 greg 1.1 printobj(mod, obj) /* print out an object */
21     char *mod;
22     register OBJREC *obj;
23     {
24     register int i;
25    
26     printf("\n%s %s %s", mod, ofun[obj->otype].funame, obj->oname);
27     printf("\n%d", obj->oargs.nsargs);
28     for (i = 0; i < obj->oargs.nsargs; i++)
29     printf(" %s", obj->oargs.sarg[i]);
30     #ifdef IARGS
31     printf("\n%d", obj->oargs.niargs);
32     for (i = 0; i < obj->oargs.niargs; i++)
33     printf(" %d", obj->oargs.iarg[i]);
34     #else
35     printf("\n0");
36     #endif
37     printf("\n%d", obj->oargs.nfargs);
38     for (i = 0; i < obj->oargs.nfargs; i++) {
39     if (i%3 == 0)
40     putchar('\n');
41     printf(" %18.12g", obj->oargs.farg[i]);
42     }
43     putchar('\n');
44     }
45    
46    
47 greg 1.2 o_default(ob, il, rt, nm) /* default illum action */
48 greg 1.1 OBJREC *ob;
49     struct illum_args *il;
50     struct rtproc *rt;
51 greg 1.2 char *nm;
52 greg 1.1 {
53 greg 1.2 sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"",
54     nm, ofun[ob->otype].funame, ob->oname);
55     error(WARNING, errmsg);
56     if (!(il->flags & IL_LIGHT))
57     printobj(il->altname, ob);
58     }
59    
60    
61     o_face(ob, il, rt, nm) /* make an illum face */
62     OBJREC *ob;
63     struct illum_args *il;
64     struct rtproc *rt;
65     char *nm;
66     {
67     }
68    
69    
70     o_sphere(ob, il, rt, nm) /* make an illum sphere */
71     OBJREC *ob;
72     struct illum_args *il;
73     struct rtproc *rt;
74     char *nm;
75     {
76     int dim[4];
77     int n, nalt, nazi;
78     float *distarr;
79     double r1, r2;
80     FVECT pos, dir;
81     FVECT u, v;
82     register int i, j;
83     /* check arguments */
84     if (ob->oargs.nfargs != 4)
85     objerror(ob, USER, "bad # of arguments");
86     /* set up sampling */
87     n = 4.*PI * il->sampdens;
88     nalt = sqrt(n/PI) + .5;
89     nazi = PI*nalt + .5;
90     n = nalt*nazi;
91     distarr = (float *)calloc(n, 3*sizeof(float));
92     if (distarr == NULL)
93     error(SYSTEM, "out of memory in o_sphere");
94     dim[0] = random();
95     /* sample sphere */
96     for (dim[1] = 0; dim[1] < nalt; dim[1]++)
97     for (dim[2] = 0; dim[2] < nazi; dim[2]++)
98     for (i = 0; i < il->nsamps; i++) {
99     /* random direction */
100     dim[3] = 1;
101     r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt;
102     dim[3] = 2;
103     r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt;
104     rounddir(dir, r1, r2);
105     /* random location */
106     mkaxes(u, v, dir); /* yuck! */
107     dim[3] = 3;
108     r1 = sqrt(urand(urind(ilhash(dim,4),i)));
109     dim[3] = 4;
110     r2 = 2.*PI*urand(urind(ilhash(dim,4),i));
111     for (j = 0; j < 3; j++)
112     org[j] = obj->oargs.farg[j] + obj->oargs.farg[3] *
113     ( r1*cos(r2)*u[j] + r1*sin(r2)*v[j]
114     - sqrt(1.01-r1*r1)*dir[j] );
115    
116     /* send sample */
117     raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt);
118     }
119     rayflush(rt);
120     /* write out distribution */
121     rounddist(distarr, nalt, nazi, il, ob);
122     /* clean up */
123     free((char *)distarr);
124     }
125    
126    
127     o_ring(ob, il, rt, nm) /* make an illum ring */
128     OBJREC *ob;
129     struct illum_args *il;
130     struct rtproc *rt;
131     char *nm;
132     {
133     }
134    
135    
136     raysamp(res, org, dir, rt) /* compute a ray sample */
137     float res[3];
138     FVECT org, dir;
139     register struct rtproc *rt;
140     {
141     register float *fp;
142    
143     if (rt->nrays == rt->bsiz)
144     rayflush(rt);
145     rt->dest[rt->nrays] = res;
146     fp = rt->buf + 6*rt->nrays++;
147     *fp++ = org[0]; *fp++ = org[1]; *fp++ = org[2];
148     *fp++ = dir[0]; *fp++ = dir[1]; *fp = dir[2];
149     }
150    
151    
152     rayflush(rt) /* flush buffered rays */
153     register struct rtproc *rt;
154     {
155     register int i;
156    
157     if (rt->nrays <= 0)
158     return;
159     i = 6*rt->nrays + 3;
160     rt->buf[i++] = 0.; rt->buf[i++] = 0.; rt->buf[i] = 0.;
161     if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf,
162     3*sizeof(float)*rt->nrays,
163     6*sizeof(float)*(rt->nrays+1)) <
164     3*sizeof(float)*rt->nrays )
165     error(SYSTEM, "error reading from rtrace process");
166     i = rt->nrays;
167     while (i--) {
168     rt->dest[i][0] += rt->buf[3*i];
169     rt->dest[i][1] += rt->buf[3*i+1];
170     rt->dest[i][2] += rt->buf[3*i+2];
171     }
172     rt->nrays = 0;
173 greg 1.1 }