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.10 by gwlarson, Mon Nov 9 17:11:40 1998 UTC vs.
Revision 3.22 by schorsch, Thu Jan 1 11:21:55 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Copy data into a holodeck file
6   */
7  
8 + #include "platform.h"
9 + #include "rterror.h"
10   #include "holo.h"
11   #include "view.h"
13 #include "resolu.h"
12  
13   #ifndef BKBSIZE
14   #define BKBSIZE         256             /* beam clump size (kilobytes) */
15   #endif
16  
17 < int     checkdepth = 1;         /* check depth (!-f option)? */
18 < int     checkrepeats = 0;       /* check for repeats (-c option)? */
17 > int     checkdepth = 1;         /* check depth (!-d option)? */
18 > int     checkrepeats = 0;       /* check for repeats (-u option)? */
19   int     frompicz;               /* input from pictures & depth-buffers? */
20   int     noutsects;              /* number of output sections */
21   char    obstr, unobstr;         /* flag pointer values */
22  
23   char    *progname;              /* global argv[0] */
24  
25 + struct phead {
26 +        VIEW    vw;
27 +        double  expos;
28 +        short   gotview;
29 +        short   badfmt;
30 +        short   altprims;
31 + };
32 + static int openholo(char *fname, int append);
33 + static void addray(FVECT ro, FVECT rd, double d, COLR cv);
34 + static int holheadline(char *s, int *hf);
35 + static int bpcmp(const void *b1p, const void *b2p);
36 + static int addclump(HOLO *hp, int *bq, int nb);
37 + static void addholo(char *hdf);
38 + static int picheadline(char *s, struct phead *ph);
39 + static void addpicz(char *pcf, char *zbf);
40  
41 < main(argc, argv)
42 < int     argc;
43 < char    *argv[];
41 >
42 >
43 > int
44 > main(
45 >        int     argc,
46 >        char    *argv[]
47 > )
48   {
49          int     i;
50  
# Line 79 | Line 96 | userr:
96   #define H_OBSF  04
97  
98   int
99 < holheadline(s, hf)              /* check holodeck header line */
100 < register char   *s;
101 < int     *hf;
99 > holheadline(            /* check holodeck header line */
100 >        register char   *s,
101 >        int     *hf
102 > )
103   {
104          char    fmt[32];
105  
# Line 95 | Line 113 | int    *hf;
113          if (!strncmp(s, "OBSTRUCTIONS=", 13)) {
114                  s += 13;
115                  while (*s == ' ') s++;
116 <                if (*s == 't' | *s == 'T')
116 >                if ((*s == 't') | (*s == 'T'))
117                          *hf |= H_OBST;
118 <                else if (*s == 'f' | *s == 'F')
118 >                else if ((*s == 'f') | (*s == 'F'))
119                          *hf |= H_OBSF;
120                  else
121                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
# Line 107 | Line 125 | int    *hf;
125   }
126  
127   int
128 < openholo(fname, append)         /* open existing holodeck file for i/o */
129 < char    *fname;
130 < int     append;
128 > openholo(               /* open existing holodeck file for i/o */
129 >        char    *fname,
130 >        int     append
131 > )
132   {
114        extern long     ftell();
133          FILE    *fp;
134          int     fd;
135          int     hflags = 0;
# Line 124 | Line 142 | int    append;
142                  error(SYSTEM, errmsg);
143          }
144                                          /* check header and magic number */
145 <        if (getheader(fp, holheadline, &hflags) < 0 ||
145 >        if (getheader(fp, holheadline, (char *)&hflags) < 0 ||
146                          hflags&H_BADF || getw(fp) != HOLOMAGIC) {
147                  sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
148                  error(USER, errmsg);
# Line 133 | Line 151 | int    append;
151          nextloc = ftell(fp);                    /* get stdio position */
152          fclose(fp);                             /* done with stdio */
153          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
154 <                lseek(fd, nextloc, 0);
154 >                lseek(fd, (off_t)nextloc, SEEK_SET);
155                  read(fd, (char *)&nextloc, sizeof(nextloc));
156                  hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
157                                  hflags&H_OBSF ? &unobstr : (char *)NULL;
# Line 146 | Line 164 | int    append;
164   #undef H_OBSF
165  
166  
167 < addray(ro, rd, d, cv)           /* add a ray to our output holodeck */
168 < FVECT   ro, rd;
169 < double  d;
170 < COLR    cv;
167 > void
168 > addray(         /* add a ray to our output holodeck */
169 >        FVECT   ro,
170 >        FVECT   rd,
171 >        double  d,
172 >        COLR    cv
173 > )
174   {
175          int     sn, bi, n;
176          register HOLO   *hp;
# Line 175 | Line 196 | COLR   cv;
196                  bi = hdbindex(hp, gc);          /* check for duplicates */
197                  if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
198                          for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
199 <                                if (rv->d == dc &&
199 >                                if ((hp->priv != NULL || rv->d == dc) &&
200                                                  rv->r[0][0] == rr[0][0] &&
201                                                  rv->r[0][1] == rr[0][1] &&
202                                                  rv->r[1][0] == rr[1][0] &&
# Line 193 | Line 214 | COLR   cv;
214   }
215  
216  
217 < addbeam(bp, hb)                 /* add a beam to our output holodeck */
218 < register BEAM   *bp;
219 < register HDBEAMI        *hb;
217 > static BEAMI    *beamdir;
218 >
219 > static int
220 > bpcmp(                  /* compare beam positions on disk */
221 >        const void      *b1p,
222 >        const void      *b2p
223 > )
224   {
225 +        register off_t  pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo;
226 +
227 +        if (pdif > 0L) return(1);
228 +        if (pdif < 0L) return(-1);
229 +        return(0);
230 + }
231 +
232 + static int
233 + addclump(               /* transfer the given clump and free */
234 +        HOLO    *hp,
235 +        int     *bq,
236 +        int     nb
237 + )
238 + {
239          GCOORD  gc[2];
240          FVECT   ro, rd;
241          double  d;
242 +        int     i;
243          register int    k;
244 <                                        /* get beam coordinates */
245 <        hdbcoord(gc, hb->h, hb->b);
246 <                                        /* add each ray to output */
247 <        for (k = bp->nrm; k--; ) {
248 <                d = hdray(ro, rd, hb->h, gc, hdbray(bp)[k].r);
249 <                if (hb->h->priv == &unobstr)
250 <                        VSUM(ro, ro, rd, d);
251 <                else
252 <                        d = 0.;
253 <                d = hddepth(hb->h, hdbray(bp)[k].d) - d;
254 <                addray(ro, rd, d, hdbray(bp)[k].v);
244 >        register BEAM   *bp;
245 >                                        /* sort based on file position */
246 >        beamdir = hp->bi;
247 >        qsort((char *)bq, nb, sizeof(*bq), bpcmp);
248 >                                        /* transfer each beam */
249 >        for (i = 0; i < nb; i++) {
250 >                bp = hdgetbeam(hp, bq[i]);
251 >                hdbcoord(gc, hp, bq[i]);
252 >                                                /* add each ray to output */
253 >                for (k = bp->nrm; k--; ) {
254 >                        d = hdray(ro, rd, hp, gc, hdbray(bp)[k].r);
255 >                        if (hp->priv == &unobstr)
256 >                                VSUM(ro, ro, rd, d);
257 >                        else
258 >                                d = 0.;
259 >                        d = hddepth(hp, hdbray(bp)[k].d) - d;
260 >                        addray(ro, rd, d, hdbray(bp)[k].v);
261 >                }
262 >                hdfreebeam(hp, bq[i]);          /* free the beam */
263          }
264 <        hdfreebeam(hb->h, hb->b);       /* free the beam */
264 >        return(0);
265   }
266  
267  
268 < addholo(hdf)                    /* add a holodeck file */
269 < char    *hdf;
268 > void
269 > addholo(                        /* add a holodeck file */
270 >        char    *hdf
271 > )
272   {
273          int     fd;
274                                          /* open the holodeck for reading */
# Line 226 | Line 276 | char   *hdf;
276          fd = hdlist[noutsects]->fd;     /* remember the file handle */
277          while (hdlist[noutsects] != NULL) {     /* load each section */
278                                                          /* clump the beams */
279 <                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addbeam);
279 >                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump);
280                  hddone(hdlist[noutsects]);              /* free the section */
281          }
282          close(fd);                      /* close input file */
283 +        hdflush(NULL);                  /* flush output */
284   }
285  
286  
236 struct phead {
237        VIEW    vw;
238        double  expos;
239        short   gotview;
240        short   badfmt;
241        short   altprims;
242 };
287  
244
288   int
289 < picheadline(s, ph)              /* process picture header line */
290 < char    *s;
291 < struct phead    *ph;
289 > picheadline(            /* process picture header line */
290 >        char    *s,
291 >        struct phead    *ph
292 > )
293   {
294          char    fmt[32];
295  
# Line 269 | Line 313 | struct phead   *ph;
313   }
314  
315  
316 < addpicz(pcf, zbf)               /* add a picture + depth-buffer */
317 < char    *pcf, *zbf;
316 > void
317 > addpicz(                /* add a picture + depth-buffer */
318 >        char    *pcf,
319 >        char    *zbf
320 > )
321   {
322          FILE    *pfp;
323          int     zfd;
# Line 280 | Line 327 | char   *pcf, *zbf;
327          int     eshft;
328          double  emult;
329          RESOLU  prs;
330 <        FLOAT   vl[2];
330 >        RREAL   vl[2];
331          FVECT   ro, rd;
332          double  aftd;
333          COLOR   ctmp;
# Line 296 | Line 343 | char   *pcf, *zbf;
343                  error(SYSTEM, pcf);
344          }
345                                  /* load picture header */
346 <        copystruct(&phd.vw, &stdview);
346 >        phd.vw = stdview;
347          phd.expos = 1.0;
348          phd.badfmt = phd.gotview = phd.altprims = 0;
349 <        if (getheader(pfp, picheadline, &phd) < 0 ||
349 >        if (getheader(pfp, picheadline, (char *)&phd) < 0 ||
350                          phd.badfmt || !fgetsresolu(&prs, pfp)) {
351                  sprintf(errmsg, "bad format for picture file \"%s\"", pcf);
352                  error(USER, errmsg);
# Line 315 | Line 362 | char   *pcf, *zbf;
362                  error(WARNING, errmsg);
363          }
364                                  /* figure out what to do about exposure */
365 <        if (phd.expos < 0.99 | phd.expos > 1.01) {
365 >        if ((phd.expos < 0.99) | (phd.expos > 1.01)) {
366                  emult = -log(phd.expos)/log(2.);
367                  eshft = emult >= 0. ? emult+.5 : emult-.5;
368                  emult -= (double)eshft;
369 <                if (emult <= 0.01 & emult >= -0.01)
369 >                if ((emult <= 0.01) & (emult >= -0.01))
370                          emult = -1.;
371                  else {
372                          emult = 1./phd.expos;
# Line 332 | Line 379 | char   *pcf, *zbf;
379                                  /* allocate buffers */
380          cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR));
381          zscn = (float *)malloc(scanlen(&prs)*sizeof(float));
382 <        if (cscn == NULL | zscn == NULL)
382 >        if ((cscn == NULL) | (zscn == NULL))
383                  error(SYSTEM, "out of memory in addpicz");
384                                  /* read and process each scanline */
385          for (j = 0; j < numscans(&prs); j++) {
# Line 364 | Line 411 | char   *pcf, *zbf;
411                          addray(ro, rd, (double)zscn[i], cscn[i]);
412                  }
413          }
414 <                                /* write output */
415 <        hdsync(NULL, 1);
414 >                                /* write output and free beams */
415 >        hdflush(NULL);
416                                  /* clean up */
417 <        free((char *)cscn);
418 <        free((char *)zscn);
417 >        free((void *)cscn);
418 >        free((void *)zscn);
419          fclose(pfp);
420          close(zfd);
421   }
422  
423  
424 < eputs(s)                        /* put error message to stderr */
425 < register char  *s;
424 > void
425 > eputs(                  /* put error message to stderr */
426 >        register char  *s
427 > )
428   {
429          static int  midline = 0;
430  
# Line 393 | Line 442 | register char  *s;
442   }
443  
444  
445 < quit(code)                      /* exit the program gracefully */
446 < int     code;
445 > void
446 > quit(                   /* exit the program gracefully */
447 >        int     code
448 > )
449   {
450          hdsync(NULL, 1);        /* write out any buffered data */
451          exit(code);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines