ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo2.c
Revision: 3.7
Committed: Fri Dec 12 19:52:32 1997 UTC (26 years, 4 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.6: +2 -0 lines
Log Message:
modified hdsync() to optionally sync all unflushed beams

File Contents

# User Rev Content
1 gregl 3.1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Rtrace support routines for holodeck rendering
9     */
10    
11     #include "rholo.h"
12 gregl 3.5 #include "paths.h"
13 gregl 3.1 #include "random.h"
14    
15    
16     packrays(rod, p) /* pack ray origins and directions */
17     register float *rod;
18     register PACKET *p;
19     {
20     static FVECT ro, rd;
21 gregl 3.3 GCOORD gc[2];
22 gregl 3.4 int ila[2], hsh;
23     double d, sl[4];
24 gregl 3.1 register int i;
25    
26     if (!hdbcoord(gc, hdlist[p->hd], p->bi))
27     error(CONSISTENCY, "bad beam index in packrays");
28 gregl 3.4 ila[0] = p->hd; ila[1] = p->bi;
29     hsh = ilhash(ila,2) + p->nc;
30 gregl 3.1 for (i = 0; i < p->nr; i++) {
31 gregl 3.4 multisamp(sl, 4, urand(hsh+i));
32     p->ra[i].r[0][0] = sl[0] * 256.;
33     p->ra[i].r[0][1] = sl[1] * 256.;
34     p->ra[i].r[1][0] = sl[2] * 256.;
35     p->ra[i].r[1][1] = sl[3] * 256.;
36 gregl 3.1 d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r);
37     if (p->offset != NULL) {
38     VSUM(ro, ro, rd, d); /* exterior only */
39     p->offset[i] = d;
40     }
41     VCOPY(rod, ro);
42     rod += 3;
43     VCOPY(rod, rd);
44     rod += 3;
45     }
46     }
47    
48    
49     donerays(p, rvl) /* encode finished ray computations */
50     register PACKET *p;
51     register float *rvl;
52     {
53     double d;
54     register int i;
55    
56     for (i = 0; i < p->nr; i++) {
57     setcolr(p->ra[i].v, rvl[0], rvl[1], rvl[2]);
58     d = rvl[3];
59     if (p->offset != NULL)
60     d += p->offset[i];
61     p->ra[i].d = hdcode(hdlist[p->hd], d);
62     rvl += 4;
63     }
64 gregl 3.4 p->nc += p->nr;
65 gregl 3.5 }
66    
67    
68     int
69     done_rtrace() /* clean up and close rtrace calculation */
70     {
71     int status;
72     /* already closed? */
73     if (!nprocs)
74     return;
75     wputs("closing rtrace process...\n");
76     /* flush beam queue */
77     done_packets(flush_queue());
78 gregl 3.7 /* sync holodeck */
79     hdsync(NULL, 1);
80 gregl 3.5 /* close rtrace */
81     if ((status = end_rtrace()))
82     error(WARNING, "bad exit status from rtrace");
83     if (vdef(REPORT)) /* report time */
84     report(0);
85     return(status); /* return status */
86     }
87    
88    
89     new_rtrace() /* restart rtrace calculation */
90     {
91     char combuf[128];
92    
93     if (nprocs > 0) /* already running? */
94     return;
95     wputs("restarting rtrace process...\n");
96 gregl 3.6 starttime = time(NULL); /* reset start time and counts */
97     npacksdone = nraysdone = 0L;
98     if (vdef(TIME)) /* reset end time */
99     endtime = starttime + vflt(TIME)*3600. + .5;
100 gregl 3.5 if (vdef(RIF)) { /* rerun rad to update octree */
101     sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
102     if (system(combuf))
103     error(WARNING, "error running rad");
104     }
105     if (start_rtrace() < 1) /* start rtrace */
106     error(WARNING, "cannot restart rtrace");
107     else if (vdef(REPORT))
108     report(0);
109     }
110    
111    
112     getradfile() /* run rad and get needed variables */
113     {
114     static short mvar[] = {OCTREE,-1};
115     static char tf1[] = TEMPLATE;
116     char tf2[64];
117     char combuf[256];
118     char *pippt;
119     register int i;
120     register char *cp;
121     /* check if rad file specified */
122     if (!vdef(RIF))
123     return;
124     /* create rad command */
125     mktemp(tf1);
126     sprintf(tf2, "%s.rif", tf1);
127     sprintf(combuf,
128     "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
129     vval(RIF), tf1);
130     cp = combuf;
131     while (*cp){
132     if (*cp == '|') pippt = cp;
133     cp++;
134     } /* match unset variables */
135     for (i = 0; mvar[i] >= 0; i++)
136     if (!vdef(mvar[i])) {
137     *cp++ = '|';
138     strcpy(cp, vnam(mvar[i]));
139     while (*cp) cp++;
140     pippt = NULL;
141     }
142     if (pippt != NULL)
143     strcpy(pippt, "> /dev/null"); /* nothing to match */
144     else
145     sprintf(cp, ")[ \t]*=' > %s", tf2);
146     if (system(combuf)) {
147     unlink(tf2); /* clean up */
148     unlink(tf1);
149     error(SYSTEM, "cannot execute rad command");
150     }
151     if (pippt == NULL) {
152     loadvars(tf2); /* load variables */
153     unlink(tf2);
154     }
155     rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
156     unlink(tf1); /* clean up */
157 gregl 3.6 }
158    
159    
160     report(t) /* report progress so far */
161     time_t t;
162     {
163     static time_t seconds2go = 1000000;
164    
165     if (t == 0L)
166     t = time(NULL);
167     sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n",
168     npacksdone, nraysdone, (t-starttime)/3600.);
169     eputs(errmsg);
170     if (seconds2go == 1000000)
171     seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L;
172     if (seconds2go)
173     reporttime = t + seconds2go;
174 gregl 3.1 }