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.8 by gregl, Fri Jan 23 09:05:14 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 > holheadline(s, hf)              /* check holodeck header line */
79   register char   *s;
80 < int     *bf;
80 > int     *hf;
81   {
82          char    fmt[32];
83  
84          if (formatval(fmt, s)) {
85 <                *bf = strcmp(fmt, HOLOFMT);
85 >                if (strcmp(fmt, HOLOFMT))
86 >                        *hf |= H_BADF;
87 >                else
88 >                        *hf &= ~H_BADF;
89                  return;
90          }
91          if (!strncmp(s, "OBSTRUCTIONS=", 13)) {
92                  s += 13;
93                  while (*s == ' ') s++;
94                  if (*s == 't' | *s == 'T')
95 <                        obstructions = 1;
95 >                        *hf |= H_OBST;
96                  else if (*s == 'f' | *s == 'F')
97 <                        obstructions = 0;
97 >                        *hf |= H_OBSF;
98                  else
99                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
100                  return;
101          }
102   }
103  
78
104   int
105   openholo(fname, append)         /* open existing holodeck file for i/o */
106   char    *fname;
# Line 84 | Line 109 | int    append;
109          extern long     ftell();
110          FILE    *fp;
111          int     fd;
112 <        int     badfmt = 0;
113 <        int4    nextloc;
112 >        int     hflags = 0;
113 >        long    nextloc;
114          int     n;
115                                          /* open holodeck file */
116          if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) {
# Line 94 | Line 119 | int    append;
119                  error(SYSTEM, errmsg);
120          }
121                                          /* check header and magic number */
122 <        if (append)
123 <                badfmt |= getheader(fp, holheadline, &badfmt) < 0;
99 <        else
100 <                badfmt = checkheader(fp, HOLOFMT, NULL) < 0;
101 <        if (badfmt || getw(fp) != HOLOMAGIC) {
122 >        if (getheader(fp, holheadline, &hflags) < 0 ||
123 >                        hflags&H_BADF || getw(fp) != HOLOMAGIC) {
124                  sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
125                  error(USER, errmsg);
126          }
# Line 106 | Line 128 | int    append;
128          nextloc = ftell(fp);                    /* get stdio position */
129          fclose(fp);                             /* done with stdio */
130          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
131 <                lseek(fd, (long)nextloc, 0);
131 >                lseek(fd, nextloc, 0);
132                  read(fd, (char *)&nextloc, sizeof(nextloc));
133 <                hdinit(fd, NULL);
133 >                hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
134 >                                hflags&H_OBSF ? &unobstr : (char *)NULL;
135          }
136          return(n);
137   }
138  
139 + #undef H_BADF
140 + #undef H_OBST
141 + #undef H_OBSF
142  
143 +
144   addray(ro, rd, d, cv)           /* add a ray to our output holodeck */
145   FVECT   ro, rd;
146   double  d;
147   COLR    cv;
148   {
149 <        int     sn;
149 >        int     sn, bi, n;
150          register HOLO   *hp;
151          GCOORD  gc[2];
152          BYTE    rr[2][2];
153 +        BEAM    *bp;
154          double  d0, d1;
155 +        unsigned        dc;
156          register RAYVAL *rv;
157                                  /* check each output section */
158          for (sn = noutsects; sn--; ) {
# Line 131 | Line 160 | COLR   cv;
160                  d0 = hdinter(gc, rr, &d1, hp, ro, rd);
161                  if (d <= d0 || d1 < -0.001)
162                          continue;       /* missed section */
163 <                if (obstructions > 0 && d0 < -0.001)
164 <                        continue;       /* ray starts too late */
165 <                if (!obstructions && d < 0.999*d1)
166 <                        continue;       /* ray ends too soon */
167 <                                        /* should we check for duplicates? */
168 <                rv = hdnewrays(hp, hdbindex(hp, gc), 1);
163 >                if (checkdepth) {               /* check depth */
164 >                        if (hp->priv == &obstr && d0 < -0.001)
165 >                                continue;       /* ray starts too late */
166 >                        if (hp->priv == &unobstr && d < 0.999*d1)
167 >                                continue;       /* ray ends too soon */
168 >                }
169 >                dc = hdcode(hp, d-d0);
170 >                bi = hdbindex(hp, gc);          /* check for duplicates */
171 >                if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
172 >                        for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
173 >                                if (rv->d == dc &&
174 >                                                rv->r[0][0] == rr[0][0] &&
175 >                                                rv->r[0][1] == rr[0][1] &&
176 >                                                rv->r[1][0] == rr[1][0] &&
177 >                                                rv->r[1][1] == rr[1][1])
178 >                                        break;
179 >                        if (n >= 0)
180 >                                continue;       /* found a matching ray */
181 >                }
182 >                rv = hdnewrays(hp, bi, 1);
183 >                rv->d = dc;
184                  rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1];
185                  rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1];
186                  copycolr(rv->v, cv);
143                rv->d = hdcode(hp, d-d0);
187          }
188   }
189  
# Line 148 | Line 191 | COLR   cv;
191   addholo(hdf)                    /* add a holodeck file */
192   char    *hdf;
193   {
194 +        HDBEAMI hbl[BLOADSIZE];
195          int     fd;
196          register HOLO   *hp;
197          register BEAM   *bp;
198          GCOORD  gc[2];
199          FVECT   ro, rd;
200          double  d;
201 <        int     i, j;
201 >        int     i, j, n, li;
202          register int    k;
203 <
204 <        openholo(hdf, 0);               /* open the holodeck for reading */
203 >                                        /* open the holodeck for reading */
204 >        openholo(hdf, 0);
205          fd = hdlist[noutsects]->fd;     /* remember the file handle */
206          while ((hp = hdlist[noutsects]) != NULL) {      /* load each section */
207 <                for (j = nbeams(hp); j > 0; j--)        /* load each beam */
208 <                        if ((bp = hdgetbeam(hp, j)) != NULL) {
209 <                                hdbcoord(gc, hp, j);
207 >                for (j = 0; j < nbeams(hp); j++) {      /* load each beam */
208 >                        if (!(li = j % BLOADSIZE)) {    /* optimize order */
209 >                                if (j+BLOADSIZE > nbeams(hp))
210 >                                        k = n = nbeams(hp) - j;
211 >                                else
212 >                                        k = n = BLOADSIZE;
213 >                                while (k--) {
214 >                                        hbl[k].h = hp;
215 >                                        hbl[k].b = j+k+1;
216 >                                }
217 >                                qsort((char *)hbl, n,
218 >                                                sizeof(HDBEAMI), hdfilord);
219 >                        }
220 >                        if ((bp = hdgetbeam(hp, hbl[li].b)) != NULL) {
221 >                                hdbcoord(gc, hp, hbl[li].b);
222                                  for (k = bp->nrm; k--; ) {
223 <                                        hdray(ro, rd, hp, gc, hdbray(bp)[k].r);
224 <                                        d = hddepth(hp, hdbray(bp)[k].d);
223 >                                        d = hdray(ro, rd,
224 >                                                hp, gc, hdbray(bp)[k].r);
225 >                                        if (hp->priv == &unobstr)
226 >                                                VSUM(ro, ro, rd, d);
227 >                                        else
228 >                                                d = 0.;
229 >                                        d = hddepth(hp, hdbray(bp)[k].d) - d;
230                                          addray(ro, rd, d, hdbray(bp)[k].v);
231                                  }
232 <                                hdfreebeam(hp, j);      /* free the beam */
232 >                                hdfreebeam(hp, hbl[li].b);      /* free beam */
233                          }
234 +                }
235                  hddone(hp);                             /* free the section */
236          }
237          close(fd);                      /* close the file */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines