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.9 by gwlarson, Tue Oct 27 08:49:50 1998 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ SGI";
12   #include "view.h"
13   #include "resolu.h"
14  
15 + #ifndef BLOADSIZE
16 + #define BLOADSIZE       1024    /* number of input beams to load at a time */
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)
59 >                for ( ; i < argc; i += 2)
60                          addpicz(argv[i], argv[i+1]);
61          else
62 <                for (i = 3; i < argc; i++)
62 >                for ( ; i < argc; i++)
63                          addholo(argv[i]);
64          quit(0);
65   userr:
66 <        fprintf(stderr, "Usage: %s output.hdk -h inp1.hdk ..\n", progname);
49 <        fprintf(stderr, "   Or: %s output.hdk -pz inp1.pic inp1.zbf ..\n",
66 >        fprintf(stderr, "Usage: %s output.hdk [-u][-d] -h inp1.hdk ..\n",
67                          progname);
68 +        fprintf(stderr, "   Or: %s output.hdk [-u][-d] -pz inp1.pic inp1.zbf ..\n",
69 +                        progname);
70          exit(1);
71   }
72  
73  
74 < holheadline(s, bf)              /* check holodeck header line */
74 > #define H_BADF  01
75 > #define H_OBST  02
76 > #define H_OBSF  04
77 >
78 > int
79 > holheadline(s, hf)              /* check holodeck header line */
80   register char   *s;
81 < int     *bf;
81 > int     *hf;
82   {
83          char    fmt[32];
84  
85          if (formatval(fmt, s)) {
86 <                *bf = strcmp(fmt, HOLOFMT);
87 <                return;
86 >                if (strcmp(fmt, HOLOFMT))
87 >                        *hf |= H_BADF;
88 >                else
89 >                        *hf &= ~H_BADF;
90 >                return(0);
91          }
92          if (!strncmp(s, "OBSTRUCTIONS=", 13)) {
93                  s += 13;
94                  while (*s == ' ') s++;
95                  if (*s == 't' | *s == 'T')
96 <                        obstructions = 1;
96 >                        *hf |= H_OBST;
97                  else if (*s == 'f' | *s == 'F')
98 <                        obstructions = 0;
98 >                        *hf |= H_OBSF;
99                  else
100                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
101 <                return;
101 >                return(0);
102          }
103 +        return(0);
104   }
105  
78
106   int
107   openholo(fname, append)         /* open existing holodeck file for i/o */
108   char    *fname;
# Line 84 | Line 111 | int    append;
111          extern long     ftell();
112          FILE    *fp;
113          int     fd;
114 <        int     badfmt = 0;
115 <        int4    nextloc;
114 >        int     hflags = 0;
115 >        long    nextloc;
116          int     n;
117                                          /* open holodeck file */
118          if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) {
# Line 94 | Line 121 | int    append;
121                  error(SYSTEM, errmsg);
122          }
123                                          /* check header and magic number */
124 <        if (append)
125 <                badfmt |= getheader(fp, holheadline, &badfmt) < 0;
99 <        else
100 <                badfmt = checkheader(fp, HOLOFMT, NULL) < 0;
101 <        if (badfmt || getw(fp) != HOLOMAGIC) {
124 >        if (getheader(fp, holheadline, &hflags) < 0 ||
125 >                        hflags&H_BADF || getw(fp) != HOLOMAGIC) {
126                  sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
127                  error(USER, errmsg);
128          }
# Line 106 | Line 130 | int    append;
130          nextloc = ftell(fp);                    /* get stdio position */
131          fclose(fp);                             /* done with stdio */
132          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
133 <                lseek(fd, (long)nextloc, 0);
133 >                lseek(fd, nextloc, 0);
134                  read(fd, (char *)&nextloc, sizeof(nextloc));
135 <                hdinit(fd, NULL);
135 >                hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
136 >                                hflags&H_OBSF ? &unobstr : (char *)NULL;
137          }
138          return(n);
139   }
140  
141 + #undef H_BADF
142 + #undef H_OBST
143 + #undef H_OBSF
144  
145 +
146   addray(ro, rd, d, cv)           /* add a ray to our output holodeck */
147   FVECT   ro, rd;
148   double  d;
149   COLR    cv;
150   {
151 <        int     sn;
151 >        int     sn, bi, n;
152          register HOLO   *hp;
153          GCOORD  gc[2];
154          BYTE    rr[2][2];
155 +        BEAM    *bp;
156          double  d0, d1;
157 +        unsigned        dc;
158          register RAYVAL *rv;
159                                  /* check each output section */
160          for (sn = noutsects; sn--; ) {
# Line 131 | Line 162 | COLR   cv;
162                  d0 = hdinter(gc, rr, &d1, hp, ro, rd);
163                  if (d <= d0 || d1 < -0.001)
164                          continue;       /* missed section */
165 <                if (obstructions > 0 && d0 < -0.001)
166 <                        continue;       /* ray starts too late */
167 <                if (!obstructions && d < 0.999*d1)
168 <                        continue;       /* ray ends too soon */
169 <                                        /* should we check for duplicates? */
170 <                rv = hdnewrays(hp, hdbindex(hp, gc), 1);
165 >                if (checkdepth) {               /* check depth */
166 >                        if (hp->priv == &obstr && d0 < -0.001)
167 >                                continue;       /* ray starts too late */
168 >                        if (hp->priv == &unobstr && d < 0.999*d1)
169 >                                continue;       /* ray ends too soon */
170 >                }
171 >                dc = hdcode(hp, d-d0);
172 >                bi = hdbindex(hp, gc);          /* check for duplicates */
173 >                if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
174 >                        for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
175 >                                if (rv->d == dc &&
176 >                                                rv->r[0][0] == rr[0][0] &&
177 >                                                rv->r[0][1] == rr[0][1] &&
178 >                                                rv->r[1][0] == rr[1][0] &&
179 >                                                rv->r[1][1] == rr[1][1])
180 >                                        break;
181 >                        if (n >= 0)
182 >                                continue;       /* found a matching ray */
183 >                }
184 >                rv = hdnewrays(hp, bi, 1);
185 >                rv->d = dc;
186                  rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1];
187                  rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1];
188                  copycolr(rv->v, cv);
143                rv->d = hdcode(hp, d-d0);
189          }
190   }
191  
# Line 148 | Line 193 | COLR   cv;
193   addholo(hdf)                    /* add a holodeck file */
194   char    *hdf;
195   {
196 +        HDBEAMI hbl[BLOADSIZE];
197          int     fd;
198          register HOLO   *hp;
199          register BEAM   *bp;
200          GCOORD  gc[2];
201          FVECT   ro, rd;
202          double  d;
203 <        int     i, j;
203 >        int     i, j, n, li;
204          register int    k;
205 <
206 <        openholo(hdf, 0);               /* open the holodeck for reading */
205 >                                        /* open the holodeck for reading */
206 >        openholo(hdf, 0);
207          fd = hdlist[noutsects]->fd;     /* remember the file handle */
208          while ((hp = hdlist[noutsects]) != NULL) {      /* load each section */
209 <                for (j = nbeams(hp); j > 0; j--)        /* load each beam */
210 <                        if ((bp = hdgetbeam(hp, j)) != NULL) {
211 <                                hdbcoord(gc, hp, j);
209 >                for (j = 0; j < nbeams(hp); j++) {      /* load each beam */
210 >                        if (!(li = j % BLOADSIZE)) {    /* optimize order */
211 >                                if (j+BLOADSIZE > nbeams(hp))
212 >                                        k = n = nbeams(hp) - j;
213 >                                else
214 >                                        k = n = BLOADSIZE;
215 >                                while (k--) {
216 >                                        hbl[k].h = hp;
217 >                                        hbl[k].b = j+k+1;
218 >                                }
219 >                                qsort((char *)hbl, n,
220 >                                                sizeof(HDBEAMI), hdfilord);
221 >                        }
222 >                        if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) {
223 >                                hdbcoord(gc, hp, hbl[li].b);
224                                  for (k = bp->nrm; k--; ) {
225 <                                        hdray(ro, rd, hp, gc, hdbray(bp)[k].r);
226 <                                        d = hddepth(hp, hdbray(bp)[k].d);
225 >                                        d = hdray(ro, rd,
226 >                                                hp, gc, hdbray(bp)[k].r);
227 >                                        if (hp->priv == &unobstr)
228 >                                                VSUM(ro, ro, rd, d);
229 >                                        else
230 >                                                d = 0.;
231 >                                        d = hddepth(hp, hdbray(bp)[k].d) - d;
232                                          addray(ro, rd, d, hdbray(bp)[k].v);
233                                  }
234 <                                hdfreebeam(hp, j);      /* free the beam */
234 >                                hdfreebeam(hp, hbl[li].b);      /* free beam */
235                          }
236 +                }
237                  hddone(hp);                             /* free the section */
238          }
239          close(fd);                      /* close the file */
# Line 185 | Line 249 | struct phead {
249   };
250  
251  
252 + int
253   picheadline(s, ph)              /* process picture header line */
254   char    *s;
255   struct phead    *ph;
# Line 193 | Line 258 | struct phead   *ph;
258  
259          if (formatval(fmt, s)) {
260                  ph->badfmt = strcmp(fmt, COLRFMT);
261 <                return;
261 >                return(0);
262          }
263          if (isprims(s)) {
264                  ph->altprims++;         /* don't want to deal with this */
265 <                return;
265 >                return(0);
266          }
267          if (isexpos(s)) {
268                  ph->expos *= exposval(s);
269 <                return;
269 >                return(0);
270          }
271          if (isview(s)) {
272                  ph->gotview += sscanview(&ph->vw, s);
273 <                return;
273 >                return(0);
274          }
275 +        return(0);
276   }
277  
278  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines