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.23 by schorsch, Fri Jan 2 11:42:01 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 gethfunc holheadline;
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 gethfunc picheadline;
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 78 | Line 95 | userr:
95   #define H_OBST  02
96   #define H_OBSF  04
97  
98 < int
99 < holheadline(s, hf)              /* check holodeck header line */
100 < register char   *s;
101 < int     *hf;
98 > static int
99 > holheadline(            /* check holodeck header line */
100 >        register char   *s,
101 >        void    *vhf
102 > )
103   {
104          char    fmt[32];
105 +        int     *hf = vhf;
106  
107          if (formatval(fmt, s)) {
108                  if (strcmp(fmt, HOLOFMT))
# Line 95 | Line 114 | int    *hf;
114          if (!strncmp(s, "OBSTRUCTIONS=", 13)) {
115                  s += 13;
116                  while (*s == ' ') s++;
117 <                if (*s == 't' | *s == 'T')
117 >                if ((*s == 't') | (*s == 'T'))
118                          *hf |= H_OBST;
119 <                else if (*s == 'f' | *s == 'F')
119 >                else if ((*s == 'f') | (*s == 'F'))
120                          *hf |= H_OBSF;
121                  else
122                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
# Line 107 | Line 126 | int    *hf;
126   }
127  
128   int
129 < openholo(fname, append)         /* open existing holodeck file for i/o */
130 < char    *fname;
131 < int     append;
129 > openholo(               /* open existing holodeck file for i/o */
130 >        char    *fname,
131 >        int     append
132 > )
133   {
114        extern long     ftell();
134          FILE    *fp;
135          int     fd;
136          int     hflags = 0;
# Line 133 | Line 152 | int    append;
152          nextloc = ftell(fp);                    /* get stdio position */
153          fclose(fp);                             /* done with stdio */
154          for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
155 <                lseek(fd, nextloc, 0);
155 >                lseek(fd, (off_t)nextloc, SEEK_SET);
156                  read(fd, (char *)&nextloc, sizeof(nextloc));
157                  hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
158                                  hflags&H_OBSF ? &unobstr : (char *)NULL;
# Line 146 | Line 165 | int    append;
165   #undef H_OBSF
166  
167  
168 < addray(ro, rd, d, cv)           /* add a ray to our output holodeck */
169 < FVECT   ro, rd;
170 < double  d;
171 < COLR    cv;
168 > void
169 > addray(         /* add a ray to our output holodeck */
170 >        FVECT   ro,
171 >        FVECT   rd,
172 >        double  d,
173 >        COLR    cv
174 > )
175   {
176          int     sn, bi, n;
177          register HOLO   *hp;
# Line 175 | Line 197 | COLR   cv;
197                  bi = hdbindex(hp, gc);          /* check for duplicates */
198                  if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
199                          for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
200 <                                if (rv->d == dc &&
200 >                                if ((hp->priv != NULL || rv->d == dc) &&
201                                                  rv->r[0][0] == rr[0][0] &&
202                                                  rv->r[0][1] == rr[0][1] &&
203                                                  rv->r[1][0] == rr[1][0] &&
# Line 193 | Line 215 | COLR   cv;
215   }
216  
217  
218 < addbeam(bp, hb)                 /* add a beam to our output holodeck */
219 < register BEAM   *bp;
220 < register HDBEAMI        *hb;
218 > static BEAMI    *beamdir;
219 >
220 > static int
221 > bpcmp(                  /* compare beam positions on disk */
222 >        const void      *b1p,
223 >        const void      *b2p
224 > )
225   {
226 +        register off_t  pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo;
227 +
228 +        if (pdif > 0L) return(1);
229 +        if (pdif < 0L) return(-1);
230 +        return(0);
231 + }
232 +
233 + static int
234 + addclump(               /* transfer the given clump and free */
235 +        HOLO    *hp,
236 +        int     *bq,
237 +        int     nb
238 + )
239 + {
240          GCOORD  gc[2];
241          FVECT   ro, rd;
242          double  d;
243 +        int     i;
244          register int    k;
245 <                                        /* get beam coordinates */
246 <        hdbcoord(gc, hb->h, hb->b);
247 <                                        /* add each ray to output */
248 <        for (k = bp->nrm; k--; ) {
249 <                d = hdray(ro, rd, hb->h, gc, hdbray(bp)[k].r);
250 <                if (hb->h->priv == &unobstr)
251 <                        VSUM(ro, ro, rd, d);
252 <                else
253 <                        d = 0.;
254 <                d = hddepth(hb->h, hdbray(bp)[k].d) - d;
255 <                addray(ro, rd, d, hdbray(bp)[k].v);
245 >        register BEAM   *bp;
246 >                                        /* sort based on file position */
247 >        beamdir = hp->bi;
248 >        qsort((char *)bq, nb, sizeof(*bq), bpcmp);
249 >                                        /* transfer each beam */
250 >        for (i = 0; i < nb; i++) {
251 >                bp = hdgetbeam(hp, bq[i]);
252 >                hdbcoord(gc, hp, bq[i]);
253 >                                                /* add each ray to output */
254 >                for (k = bp->nrm; k--; ) {
255 >                        d = hdray(ro, rd, hp, gc, hdbray(bp)[k].r);
256 >                        if (hp->priv == &unobstr)
257 >                                VSUM(ro, ro, rd, d);
258 >                        else
259 >                                d = 0.;
260 >                        d = hddepth(hp, hdbray(bp)[k].d) - d;
261 >                        addray(ro, rd, d, hdbray(bp)[k].v);
262 >                }
263 >                hdfreebeam(hp, bq[i]);          /* free the beam */
264          }
265 <        hdfreebeam(hb->h, hb->b);       /* free the beam */
265 >        return(0);
266   }
267  
268  
269 < addholo(hdf)                    /* add a holodeck file */
270 < char    *hdf;
269 > void
270 > addholo(                        /* add a holodeck file */
271 >        char    *hdf
272 > )
273   {
274          int     fd;
275                                          /* open the holodeck for reading */
# Line 226 | Line 277 | char   *hdf;
277          fd = hdlist[noutsects]->fd;     /* remember the file handle */
278          while (hdlist[noutsects] != NULL) {     /* load each section */
279                                                          /* clump the beams */
280 <                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addbeam);
280 >                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump);
281                  hddone(hdlist[noutsects]);              /* free the section */
282          }
283          close(fd);                      /* close input file */
284 +        hdflush(NULL);                  /* flush output */
285   }
286  
287  
236 struct phead {
237        VIEW    vw;
238        double  expos;
239        short   gotview;
240        short   badfmt;
241        short   altprims;
242 };
288  
289 <
290 < int
291 < picheadline(s, ph)              /* process picture header line */
292 < char    *s;
293 < struct phead    *ph;
289 > static int
290 > picheadline(            /* process picture header line */
291 >        char    *s,
292 >        void    *vph
293 > )
294   {
295          char    fmt[32];
296 +        struct phead *ph = vph;
297  
298          if (formatval(fmt, s)) {
299                  ph->badfmt = strcmp(fmt, COLRFMT);
# Line 269 | Line 315 | struct phead   *ph;
315   }
316  
317  
318 < addpicz(pcf, zbf)               /* add a picture + depth-buffer */
319 < char    *pcf, *zbf;
318 > void
319 > addpicz(                /* add a picture + depth-buffer */
320 >        char    *pcf,
321 >        char    *zbf
322 > )
323   {
324          FILE    *pfp;
325          int     zfd;
# Line 280 | Line 329 | char   *pcf, *zbf;
329          int     eshft;
330          double  emult;
331          RESOLU  prs;
332 <        FLOAT   vl[2];
332 >        RREAL   vl[2];
333          FVECT   ro, rd;
334          double  aftd;
335          COLOR   ctmp;
# Line 296 | Line 345 | char   *pcf, *zbf;
345                  error(SYSTEM, pcf);
346          }
347                                  /* load picture header */
348 <        copystruct(&phd.vw, &stdview);
348 >        phd.vw = stdview;
349          phd.expos = 1.0;
350          phd.badfmt = phd.gotview = phd.altprims = 0;
351          if (getheader(pfp, picheadline, &phd) < 0 ||
# Line 315 | Line 364 | char   *pcf, *zbf;
364                  error(WARNING, errmsg);
365          }
366                                  /* figure out what to do about exposure */
367 <        if (phd.expos < 0.99 | phd.expos > 1.01) {
367 >        if ((phd.expos < 0.99) | (phd.expos > 1.01)) {
368                  emult = -log(phd.expos)/log(2.);
369                  eshft = emult >= 0. ? emult+.5 : emult-.5;
370                  emult -= (double)eshft;
371 <                if (emult <= 0.01 & emult >= -0.01)
371 >                if ((emult <= 0.01) & (emult >= -0.01))
372                          emult = -1.;
373                  else {
374                          emult = 1./phd.expos;
# Line 332 | Line 381 | char   *pcf, *zbf;
381                                  /* allocate buffers */
382          cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR));
383          zscn = (float *)malloc(scanlen(&prs)*sizeof(float));
384 <        if (cscn == NULL | zscn == NULL)
384 >        if ((cscn == NULL) | (zscn == NULL))
385                  error(SYSTEM, "out of memory in addpicz");
386                                  /* read and process each scanline */
387          for (j = 0; j < numscans(&prs); j++) {
# Line 364 | Line 413 | char   *pcf, *zbf;
413                          addray(ro, rd, (double)zscn[i], cscn[i]);
414                  }
415          }
416 <                                /* write output */
417 <        hdsync(NULL, 1);
416 >                                /* write output and free beams */
417 >        hdflush(NULL);
418                                  /* clean up */
419 <        free((char *)cscn);
420 <        free((char *)zscn);
419 >        free((void *)cscn);
420 >        free((void *)zscn);
421          fclose(pfp);
422          close(zfd);
423   }
424  
425  
426 < eputs(s)                        /* put error message to stderr */
427 < register char  *s;
426 > void
427 > eputs(                  /* put error message to stderr */
428 >        register char  *s
429 > )
430   {
431          static int  midline = 0;
432  
# Line 393 | Line 444 | register char  *s;
444   }
445  
446  
447 < quit(code)                      /* exit the program gracefully */
448 < int     code;
447 > void
448 > quit(                   /* exit the program gracefully */
449 >        int     code
450 > )
451   {
452          hdsync(NULL, 1);        /* write out any buffered data */
453          exit(code);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines