ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo2.c
Revision: 3.6
Committed: Fri Dec 12 18:33:50 1997 UTC (26 years, 4 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.5: +21 -1 lines
Log Message:
reset start time and ray counts in new_rtrace()

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     /* close rtrace */
79     if ((status = end_rtrace()))
80     error(WARNING, "bad exit status from rtrace");
81     if (vdef(REPORT)) /* report time */
82     report(0);
83     return(status); /* return status */
84     }
85    
86    
87     new_rtrace() /* restart rtrace calculation */
88     {
89     char combuf[128];
90    
91     if (nprocs > 0) /* already running? */
92     return;
93     wputs("restarting rtrace process...\n");
94 gregl 3.6 starttime = time(NULL); /* reset start time and counts */
95     npacksdone = nraysdone = 0L;
96     if (vdef(TIME)) /* reset end time */
97     endtime = starttime + vflt(TIME)*3600. + .5;
98 gregl 3.5 if (vdef(RIF)) { /* rerun rad to update octree */
99     sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
100     if (system(combuf))
101     error(WARNING, "error running rad");
102     }
103     if (start_rtrace() < 1) /* start rtrace */
104     error(WARNING, "cannot restart rtrace");
105     else if (vdef(REPORT))
106     report(0);
107     }
108    
109    
110     getradfile() /* run rad and get needed variables */
111     {
112     static short mvar[] = {OCTREE,-1};
113     static char tf1[] = TEMPLATE;
114     char tf2[64];
115     char combuf[256];
116     char *pippt;
117     register int i;
118     register char *cp;
119     /* check if rad file specified */
120     if (!vdef(RIF))
121     return;
122     /* create rad command */
123     mktemp(tf1);
124     sprintf(tf2, "%s.rif", tf1);
125     sprintf(combuf,
126     "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
127     vval(RIF), tf1);
128     cp = combuf;
129     while (*cp){
130     if (*cp == '|') pippt = cp;
131     cp++;
132     } /* match unset variables */
133     for (i = 0; mvar[i] >= 0; i++)
134     if (!vdef(mvar[i])) {
135     *cp++ = '|';
136     strcpy(cp, vnam(mvar[i]));
137     while (*cp) cp++;
138     pippt = NULL;
139     }
140     if (pippt != NULL)
141     strcpy(pippt, "> /dev/null"); /* nothing to match */
142     else
143     sprintf(cp, ")[ \t]*=' > %s", tf2);
144     if (system(combuf)) {
145     unlink(tf2); /* clean up */
146     unlink(tf1);
147     error(SYSTEM, "cannot execute rad command");
148     }
149     if (pippt == NULL) {
150     loadvars(tf2); /* load variables */
151     unlink(tf2);
152     }
153     rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
154     unlink(tf1); /* clean up */
155 gregl 3.6 }
156    
157    
158     report(t) /* report progress so far */
159     time_t t;
160     {
161     static time_t seconds2go = 1000000;
162    
163     if (t == 0L)
164     t = time(NULL);
165     sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n",
166     npacksdone, nraysdone, (t-starttime)/3600.);
167     eputs(errmsg);
168     if (seconds2go == 1000000)
169     seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L;
170     if (seconds2go)
171     reporttime = t + seconds2go;
172 gregl 3.1 }