ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhcopy.c
(Generate patch)

Comparing ray/src/hd/rhcopy.c (file contents):
Revision 3.1 by gregl, Thu Dec 18 09:33:42 1997 UTC vs.
Revision 3.10 by gwlarson, Mon Nov 9 17:11:40 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1997 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "view.h"
13   #include "resolu.h"
14  
15 + #ifndef BKBSIZE
16 + #define BKBSIZE         256             /* beam clump size (kilobytes) */
17 + #endif
18 +
19 + int     checkdepth = 1;         /* check depth (!-f option)? */
20 + int     checkrepeats = 0;       /* check for repeats (-c option)? */
21   int     frompicz;               /* input from pictures & depth-buffers? */
22   int     noutsects;              /* number of output sections */
23 < int     obstructions = -1;      /* interior obstructions allowed? */
23 > char    obstr, unobstr;         /* flag pointer values */
24  
25   char    *progname;              /* global argv[0] */
26  
# Line 26 | Line 32 | char   *argv[];
32          int     i;
33  
34          progname = argv[0];
35 <        if (argc < 4)
35 >        frompicz = -1;
36 >        for (i = 2; i < argc && argv[i][0] == '-'; i++)
37 >                switch (argv[i][1]) {
38 >                case 'u':
39 >                        checkrepeats = 1;
40 >                        break;
41 >                case 'd':
42 >                        checkdepth = 0;
43 >                        break;
44 >                case 'h':
45 >                        frompicz = 0;
46 >                        break;
47 >                case 'p':
48 >                        frompicz = 1;
49 >                        break;
50 >                default:
51 >                        goto userr;
52 >                }
53 >        if (i >= argc || frompicz < 0)
54                  goto userr;
55 <        if (!strcmp(argv[2], "-h"))
32 <                frompicz = 0;
33 <        else if (!strcmp(argv[2], "-pz"))
34 <                frompicz = 1;
35 <        else
55 >        if (frompicz && (argc-i)%2)
56                  goto userr;
37        if (frompicz && (argc-3)%2)
38                goto userr;
57          noutsects = openholo(argv[1], 1);
58 <        if (frompicz)
59 <                for (i = 3; i < argc; i += 2)
58 >        if (frompicz) {
59 >                for ( ; i < argc; i += 2)
60                          addpicz(argv[i], argv[i+1]);
61 <        else
62 <                for (i = 3; i < argc; i++)
61 >        } else {
62 >                if (BKBSIZE*1024*1.5 > hdcachesize)
63 >                        hdcachesize = BKBSIZE*1024*1.5;
64 >                for ( ; i < argc; i++)
65                          addholo(argv[i]);
66 +        }
67          quit(0);
68   userr:
69 <        fprintf(stderr, "Usage: %s output.hdk -h inp1.hdk ..\n", progname);
49 <        fprintf(stderr, "   Or: %s output.hdk -pz inp1.pic inp1.zbf ..\n",
69 >        fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n",
70                          progname);
71 +        fprintf(stderr, "   Or: %s output.hdk [-u][-d] -p inp1.pic inp1.zbf ..\n",
72 +                        progname);
73          exit(1);
74   }
75  
76  
77 < holheadline(s, bf)              /* check holodeck header line */
77 > #define H_BADF  01
78 > #define H_OBST  02
79 > #define H_OBSF  04
80 >
81 > int
82 > holheadline(s, hf)              /* check holodeck header line */
83   register char   *s;
84 < int     *bf;
84 > int     *hf;
85   {
86          char    fmt[32];
87  
88          if (formatval(fmt, s)) {
89 <                *bf = strcmp(fmt, HOLOFMT);
90 <                return;
89 >                if (strcmp(fmt, HOLOFMT))
90 >                        *hf |= H_BADF;
91 >                else
92 >                        *hf &= ~H_BADF;
93 >                return(0);
94          }
95          if (!strncmp(s, "OBSTRUCTIONS=", 13)) {
96                  s += 13;
97                  while (*s == ' ') s++;
98                  if (*s == 't' | *s == 'T')
99 <                        obstructions = 1;
99 >                        *hf |= H_OBST;
100                  else if (*s == 'f' | *s == 'F')
101 <                        obstructions = 0;
101 >                        *hf |= H_OBSF;
102                  else
103                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
104 <                return;
104 >                return(0);
105          }
106 +        return(0);
107   }
108  
78
109   int
110   openholo(fname, append)         /* open existing holodeck file for i/o */
111   char    *fname;
# Line 84 | Line 114 | int    append;
114          extern long     ftell();
115          FILE    *fp;
116          int     fd;
117 <        int     badfmt = 0;
118 <        int4    nextloc;
117 >        int     hflags = 0;
118 >        long    nextloc;
119          int     n;
120                                          /* open holodeck file */
121          if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) {
# Line 94 | Line 124 | int    append;
124                  error(SYSTEM, errmsg);
125          }
126                                          /* check header and magic number */
127 <        if (append)
128 <                badfmt |= getheader(fp, holheadline, &badfmt) < 0;
99 <        else
100 <                badfmt = checkheader(fp, HOLOFMT, NULL) < 0;
101 <        if (badfmt || getw(fp) != HOLOMAGIC) {
127 >        if (getheader(fp, holheadline, &hflags) < 0 ||
128 >                        hflags&H_BADF || getw(fp) != HOLOMAGIC) {
129                  sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
130                  error(USER, errmsg);
131          }
# Line 106 | Line 133 | int    append;
133          nextloc = ftell(fp);                    /* get stdio position */
134          fclose(fp);                             /* done with stdio */
135          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
136 <                lseek(fd, (long)nextloc, 0);
136 >                lseek(fd, nextloc, 0);
137                  read(fd, (char *)&nextloc, sizeof(nextloc));
138 <                hdinit(fd, NULL);
138 >                hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
139 >                                hflags&H_OBSF ? &unobstr : (char *)NULL;
140          }
141          return(n);
142   }
143  
144 + #undef H_BADF
145 + #undef H_OBST
146 + #undef H_OBSF
147  
148 +
149   addray(ro, rd, d, cv)           /* add a ray to our output holodeck */
150   FVECT   ro, rd;
151   double  d;
152   COLR    cv;
153   {
154 <        int     sn;
154 >        int     sn, bi, n;
155          register HOLO   *hp;
156          GCOORD  gc[2];
157          BYTE    rr[2][2];
158 +        BEAM    *bp;
159          double  d0, d1;
160 +        unsigned        dc;
161          register RAYVAL *rv;
162                                  /* check each output section */
163          for (sn = noutsects; sn--; ) {
# Line 131 | Line 165 | COLR   cv;
165                  d0 = hdinter(gc, rr, &d1, hp, ro, rd);
166                  if (d <= d0 || d1 < -0.001)
167                          continue;       /* missed section */
168 <                if (obstructions > 0 && d0 < -0.001)
169 <                        continue;       /* ray starts too late */
170 <                if (!obstructions && d < 0.999*d1)
171 <                        continue;       /* ray ends too soon */
172 <                                        /* should we check for duplicates? */
173 <                rv = hdnewrays(hp, hdbindex(hp, gc), 1);
168 >                if (checkdepth) {               /* check depth */
169 >                        if (hp->priv == &obstr && d0 < -0.001)
170 >                                continue;       /* ray starts too late */
171 >                        if (hp->priv == &unobstr && d < 0.999*d1)
172 >                                continue;       /* ray ends too soon */
173 >                }
174 >                dc = hdcode(hp, d-d0);
175 >                bi = hdbindex(hp, gc);          /* check for duplicates */
176 >                if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
177 >                        for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
178 >                                if (rv->d == dc &&
179 >                                                rv->r[0][0] == rr[0][0] &&
180 >                                                rv->r[0][1] == rr[0][1] &&
181 >                                                rv->r[1][0] == rr[1][0] &&
182 >                                                rv->r[1][1] == rr[1][1])
183 >                                        break;
184 >                        if (n >= 0)
185 >                                continue;       /* found a matching ray */
186 >                }
187 >                rv = hdnewrays(hp, bi, 1);
188 >                rv->d = dc;
189                  rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1];
190                  rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1];
191                  copycolr(rv->v, cv);
143                rv->d = hdcode(hp, d-d0);
192          }
193   }
194  
195  
196 < addholo(hdf)                    /* add a holodeck file */
197 < char    *hdf;
196 > addbeam(bp, hb)                 /* add a beam to our output holodeck */
197 > register BEAM   *bp;
198 > register HDBEAMI        *hb;
199   {
151        int     fd;
152        register HOLO   *hp;
153        register BEAM   *bp;
200          GCOORD  gc[2];
201          FVECT   ro, rd;
202          double  d;
157        int     i, j;
203          register int    k;
204 +                                        /* get beam coordinates */
205 +        hdbcoord(gc, hb->h, hb->b);
206 +                                        /* add each ray to output */
207 +        for (k = bp->nrm; k--; ) {
208 +                d = hdray(ro, rd, hb->h, gc, hdbray(bp)[k].r);
209 +                if (hb->h->priv == &unobstr)
210 +                        VSUM(ro, ro, rd, d);
211 +                else
212 +                        d = 0.;
213 +                d = hddepth(hb->h, hdbray(bp)[k].d) - d;
214 +                addray(ro, rd, d, hdbray(bp)[k].v);
215 +        }
216 +        hdfreebeam(hb->h, hb->b);       /* free the beam */
217 + }
218  
219 <        openholo(hdf, 0);               /* open the holodeck for reading */
219 >
220 > addholo(hdf)                    /* add a holodeck file */
221 > char    *hdf;
222 > {
223 >        int     fd;
224 >                                        /* open the holodeck for reading */
225 >        openholo(hdf, 0);
226          fd = hdlist[noutsects]->fd;     /* remember the file handle */
227 <        while ((hp = hdlist[noutsects]) != NULL) {      /* load each section */
228 <                for (j = nbeams(hp); j > 0; j--)        /* load each beam */
229 <                        if ((bp = hdgetbeam(hp, j)) != NULL) {
230 <                                hdbcoord(gc, hp, j);
166 <                                for (k = bp->nrm; k--; ) {
167 <                                        hdray(ro, rd, hp, gc, hdbray(bp)[k].r);
168 <                                        d = hddepth(hp, hdbray(bp)[k].d);
169 <                                        addray(ro, rd, d, hdbray(bp)[k].v);
170 <                                }
171 <                                hdfreebeam(hp, j);      /* free the beam */
172 <                        }
173 <                hddone(hp);                             /* free the section */
227 >        while (hdlist[noutsects] != NULL) {     /* load each section */
228 >                                                        /* clump the beams */
229 >                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addbeam);
230 >                hddone(hdlist[noutsects]);              /* free the section */
231          }
232 <        close(fd);                      /* close the file */
232 >        close(fd);                      /* close input file */
233   }
234  
235  
# Line 185 | Line 242 | struct phead {
242   };
243  
244  
245 + int
246   picheadline(s, ph)              /* process picture header line */
247   char    *s;
248   struct phead    *ph;
# Line 193 | Line 251 | struct phead   *ph;
251  
252          if (formatval(fmt, s)) {
253                  ph->badfmt = strcmp(fmt, COLRFMT);
254 <                return;
254 >                return(0);
255          }
256          if (isprims(s)) {
257                  ph->altprims++;         /* don't want to deal with this */
258 <                return;
258 >                return(0);
259          }
260          if (isexpos(s)) {
261                  ph->expos *= exposval(s);
262 <                return;
262 >                return(0);
263          }
264          if (isview(s)) {
265                  ph->gotview += sscanview(&ph->vw, s);
266 <                return;
266 >                return(0);
267          }
268 +        return(0);
269   }
270  
271  
# Line 305 | Line 364 | char   *pcf, *zbf;
364                          addray(ro, rd, (double)zscn[i], cscn[i]);
365                  }
366          }
367 +                                /* write output */
368 +        hdsync(NULL, 1);
369                                  /* clean up */
370          free((char *)cscn);
371          free((char *)zscn);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines