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.19 by schorsch, Sun Jul 27 22:12:02 2003 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 "holo.h"
9   #include "view.h"
13 #include "resolu.h"
10  
11   #ifndef BKBSIZE
12   #define BKBSIZE         256             /* beam clump size (kilobytes) */
13   #endif
14  
15 < int     checkdepth = 1;         /* check depth (!-f option)? */
16 < int     checkrepeats = 0;       /* check for repeats (-c option)? */
15 > int     checkdepth = 1;         /* check depth (!-d option)? */
16 > int     checkrepeats = 0;       /* check for repeats (-u option)? */
17   int     frompicz;               /* input from pictures & depth-buffers? */
18   int     noutsects;              /* number of output sections */
19   char    obstr, unobstr;         /* flag pointer values */
# Line 95 | Line 91 | int    *hf;
91          if (!strncmp(s, "OBSTRUCTIONS=", 13)) {
92                  s += 13;
93                  while (*s == ' ') s++;
94 <                if (*s == 't' | *s == 'T')
94 >                if ((*s == 't') | (*s == 'T'))
95                          *hf |= H_OBST;
96 <                else if (*s == 'f' | *s == 'F')
96 >                else if ((*s == 'f') | (*s == 'F'))
97                          *hf |= H_OBSF;
98                  else
99                          error(WARNING, "bad OBSTRUCTIONS value in holodeck");
# Line 111 | Line 107 | openholo(fname, append)                /* open existing holodeck fil
107   char    *fname;
108   int     append;
109   {
114        extern long     ftell();
110          FILE    *fp;
111          int     fd;
112          int     hflags = 0;
# Line 124 | Line 119 | int    append;
119                  error(SYSTEM, errmsg);
120          }
121                                          /* check header and magic number */
122 <        if (getheader(fp, holheadline, &hflags) < 0 ||
122 >        if (getheader(fp, holheadline, (char *)&hflags) < 0 ||
123                          hflags&H_BADF || getw(fp) != HOLOMAGIC) {
124                  sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
125                  error(USER, errmsg);
# Line 133 | 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, nextloc, 0);
131 >                lseek(fd, (off_t)nextloc, 0);
132                  read(fd, (char *)&nextloc, sizeof(nextloc));
133                  hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
134                                  hflags&H_OBSF ? &unobstr : (char *)NULL;
# Line 175 | Line 170 | COLR   cv;
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 &&
173 >                                if ((hp->priv != NULL || 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] &&
# Line 193 | Line 188 | COLR   cv;
188   }
189  
190  
191 < addbeam(bp, hb)                 /* add a beam to our output holodeck */
192 < register BEAM   *bp;
193 < register HDBEAMI        *hb;
191 > static BEAMI    *beamdir;
192 >
193 > static int
194 > bpcmp(b1p, b2p)                 /* compare beam positions on disk */
195 > int     *b1p, *b2p;
196   {
197 +        register off_t  pdif = beamdir[*b1p].fo - beamdir[*b2p].fo;
198 +
199 +        if (pdif > 0L) return(1);
200 +        if (pdif < 0L) return(-1);
201 +        return(0);
202 + }
203 +
204 + static int
205 + addclump(hp, bq, nb)            /* transfer the given clump and free */
206 + HOLO    *hp;
207 + int     *bq, nb;
208 + {
209          GCOORD  gc[2];
210          FVECT   ro, rd;
211          double  d;
212 +        int     i;
213          register int    k;
214 <                                        /* get beam coordinates */
215 <        hdbcoord(gc, hb->h, hb->b);
216 <                                        /* add each ray to output */
217 <        for (k = bp->nrm; k--; ) {
218 <                d = hdray(ro, rd, hb->h, gc, hdbray(bp)[k].r);
219 <                if (hb->h->priv == &unobstr)
220 <                        VSUM(ro, ro, rd, d);
221 <                else
222 <                        d = 0.;
223 <                d = hddepth(hb->h, hdbray(bp)[k].d) - d;
224 <                addray(ro, rd, d, hdbray(bp)[k].v);
214 >        register BEAM   *bp;
215 >                                        /* sort based on file position */
216 >        beamdir = hp->bi;
217 >        qsort((char *)bq, nb, sizeof(*bq), bpcmp);
218 >                                        /* transfer each beam */
219 >        for (i = 0; i < nb; i++) {
220 >                bp = hdgetbeam(hp, bq[i]);
221 >                hdbcoord(gc, hp, bq[i]);
222 >                                                /* add each ray to output */
223 >                for (k = bp->nrm; k--; ) {
224 >                        d = hdray(ro, rd, 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, bq[i]);          /* free the beam */
233          }
234 <        hdfreebeam(hb->h, hb->b);       /* free the beam */
234 >        return(0);
235   }
236  
219
237   addholo(hdf)                    /* add a holodeck file */
238   char    *hdf;
239   {
# Line 226 | Line 243 | char   *hdf;
243          fd = hdlist[noutsects]->fd;     /* remember the file handle */
244          while (hdlist[noutsects] != NULL) {     /* load each section */
245                                                          /* clump the beams */
246 <                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addbeam);
246 >                clumpbeams(hdlist[noutsects], 0, BKBSIZE*1024, addclump);
247                  hddone(hdlist[noutsects]);              /* free the section */
248          }
249          close(fd);                      /* close input file */
250 +        hdflush(NULL);                  /* flush output */
251   }
252  
253  
# Line 280 | Line 298 | char   *pcf, *zbf;
298          int     eshft;
299          double  emult;
300          RESOLU  prs;
301 <        FLOAT   vl[2];
301 >        RREAL   vl[2];
302          FVECT   ro, rd;
303          double  aftd;
304          COLOR   ctmp;
# Line 296 | Line 314 | char   *pcf, *zbf;
314                  error(SYSTEM, pcf);
315          }
316                                  /* load picture header */
317 <        copystruct(&phd.vw, &stdview);
317 >        phd.vw = stdview;
318          phd.expos = 1.0;
319          phd.badfmt = phd.gotview = phd.altprims = 0;
320 <        if (getheader(pfp, picheadline, &phd) < 0 ||
320 >        if (getheader(pfp, picheadline, (char *)&phd) < 0 ||
321                          phd.badfmt || !fgetsresolu(&prs, pfp)) {
322                  sprintf(errmsg, "bad format for picture file \"%s\"", pcf);
323                  error(USER, errmsg);
# Line 315 | Line 333 | char   *pcf, *zbf;
333                  error(WARNING, errmsg);
334          }
335                                  /* figure out what to do about exposure */
336 <        if (phd.expos < 0.99 | phd.expos > 1.01) {
336 >        if ((phd.expos < 0.99) | (phd.expos > 1.01)) {
337                  emult = -log(phd.expos)/log(2.);
338                  eshft = emult >= 0. ? emult+.5 : emult-.5;
339                  emult -= (double)eshft;
340 <                if (emult <= 0.01 & emult >= -0.01)
340 >                if ((emult <= 0.01) & (emult >= -0.01))
341                          emult = -1.;
342                  else {
343                          emult = 1./phd.expos;
# Line 332 | Line 350 | char   *pcf, *zbf;
350                                  /* allocate buffers */
351          cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR));
352          zscn = (float *)malloc(scanlen(&prs)*sizeof(float));
353 <        if (cscn == NULL | zscn == NULL)
353 >        if ((cscn == NULL) | (zscn == NULL))
354                  error(SYSTEM, "out of memory in addpicz");
355                                  /* read and process each scanline */
356          for (j = 0; j < numscans(&prs); j++) {
# Line 364 | Line 382 | char   *pcf, *zbf;
382                          addray(ro, rd, (double)zscn[i], cscn[i]);
383                  }
384          }
385 <                                /* write output */
386 <        hdsync(NULL, 1);
385 >                                /* write output and free beams */
386 >        hdflush(NULL);
387                                  /* clean up */
388 <        free((char *)cscn);
389 <        free((char *)zscn);
388 >        free((void *)cscn);
389 >        free((void *)zscn);
390          fclose(pfp);
391          close(zfd);
392   }
393  
394  
395 + void
396   eputs(s)                        /* put error message to stderr */
397   register char  *s;
398   {
# Line 393 | Line 412 | register char  *s;
412   }
413  
414  
415 + void
416   quit(code)                      /* exit the program gracefully */
417   int     code;
418   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines