ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo2.c
Revision: 3.5
Committed: Fri Dec 12 18:23:09 1997 UTC (26 years, 4 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 3.4: +88 -0 lines
Log Message:
moved a few routines from rholo.c to rholo2.c

File Contents

# Content
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 #include "paths.h"
13 #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 GCOORD gc[2];
22 int ila[2], hsh;
23 double d, sl[4];
24 register int i;
25
26 if (!hdbcoord(gc, hdlist[p->hd], p->bi))
27 error(CONSISTENCY, "bad beam index in packrays");
28 ila[0] = p->hd; ila[1] = p->bi;
29 hsh = ilhash(ila,2) + p->nc;
30 for (i = 0; i < p->nr; i++) {
31 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 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 p->nc += p->nr;
65 }
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 /* report activity */
76 wputs("closing rtrace process...\n");
77 /* flush beam queue */
78 done_packets(flush_queue());
79 /* close rtrace */
80 if ((status = end_rtrace()))
81 error(WARNING, "bad exit status from rtrace");
82 if (vdef(REPORT)) /* report time */
83 report(0);
84 return(status); /* return status */
85 }
86
87
88 new_rtrace() /* restart rtrace calculation */
89 {
90 char combuf[128];
91
92 if (nprocs > 0) /* already running? */
93 return;
94 wputs("restarting rtrace process...\n");
95 if (vdef(RIF)) { /* rerun rad to update octree */
96 sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF));
97 if (system(combuf))
98 error(WARNING, "error running rad");
99 }
100 if (start_rtrace() < 1) /* start rtrace */
101 error(WARNING, "cannot restart rtrace");
102 else if (vdef(REPORT))
103 report(0);
104 }
105
106
107 getradfile() /* run rad and get needed variables */
108 {
109 static short mvar[] = {OCTREE,-1};
110 static char tf1[] = TEMPLATE;
111 char tf2[64];
112 char combuf[256];
113 char *pippt;
114 register int i;
115 register char *cp;
116 /* check if rad file specified */
117 if (!vdef(RIF))
118 return;
119 /* create rad command */
120 mktemp(tf1);
121 sprintf(tf2, "%s.rif", tf1);
122 sprintf(combuf,
123 "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
124 vval(RIF), tf1);
125 cp = combuf;
126 while (*cp){
127 if (*cp == '|') pippt = cp;
128 cp++;
129 } /* match unset variables */
130 for (i = 0; mvar[i] >= 0; i++)
131 if (!vdef(mvar[i])) {
132 *cp++ = '|';
133 strcpy(cp, vnam(mvar[i]));
134 while (*cp) cp++;
135 pippt = NULL;
136 }
137 if (pippt != NULL)
138 strcpy(pippt, "> /dev/null"); /* nothing to match */
139 else
140 sprintf(cp, ")[ \t]*=' > %s", tf2);
141 if (system(combuf)) {
142 unlink(tf2); /* clean up */
143 unlink(tf1);
144 error(SYSTEM, "cannot execute rad command");
145 }
146 if (pippt == NULL) {
147 loadvars(tf2); /* load variables */
148 unlink(tf2);
149 }
150 rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */
151 unlink(tf1); /* clean up */
152 }