ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rpiece.c
(Generate patch)

Comparing ray/src/util/rpiece.c (file contents):
Revision 2.10 by greg, Sun Aug 9 18:09:46 1992 UTC vs.
Revision 2.18 by greg, Fri Apr 16 12:03:59 1993 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "standard.h"
12   #include <fcntl.h>
13 +
14 + #ifndef F_SETLKW
15 +
16 + main(argc, argv)
17 + int argc;
18 + char *argv[];
19 + {
20 +        fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]);
21 +        exit(1);
22 + }
23 +
24 + #else
25 +
26   #include <signal.h>
27   #include "color.h"
28   #include "view.h"
29   #include "resolu.h"
30  
31 + #ifndef NFS
32 + #define  NFS                    1
33 + #endif
34                                  /* set the following to 0 to forgo forking */
35   #ifndef MAXFORK
36 + #if NFS
37   #define  MAXFORK                3       /* allotment of duped processes */
38 + #else
39 + #define  MAXFORK                0
40   #endif
41 <
41 > #endif
42 >                                        /* protection from SYSV signals(!) */
43 > #if defined(sgi) || defined(hpux)
44 > #define guard_io()      sighold(SIGALRM)
45 > #define unguard()       sigrelse(SIGALRM)
46 > #endif
47 > #ifndef guard_io
48 > #define guard_io()      0
49 > #define unguard()       0
50 > #endif
51                                  /* rpict command */
52   char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"};
53   int  rpargc = 9;
# Line 102 | Line 130 | char  *argv[];
130                          case 'F':               /* syncronization file */
131                                  if (argv[i][2])
132                                          break;
133 <                                if ((syncfd = open(argv[++i], O_RDWR)) < 0) {
133 >                                if ((syncfd = open(argv[++i],
134 >                                                O_RDWR|O_CREAT, 0666)) < 0) {
135                                          fprintf(stderr, "%s: cannot open\n",
136                                                          argv[i]);
137                                          exit(1);
138                                  }
139                                  continue;
140 +                        case 'z':               /* z-file ist verbotten */
141 +                                fprintf(stderr, "%s: -z option not allowed\n",
142 +                                                argv[0]);
143 +                                exit(1);
144                          case 'o':               /* output file */
145                                  if (argv[i][2])
146                                          break;
# Line 123 | Line 156 | char  *argv[];
156          }
157          init(argc, argv);
158          rpiece();
159 <        rval = cleanup(0);
127 <        exit(rval);
159 >        exit(cleanup(0));
160   }
161  
162  
# Line 164 | Line 196 | char  **av;
196          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
197                  if ((fp = fdopen(dup(outfd), "r+")) == NULL)
198                          goto filerr;
199 <                getheader(fp, NULL);            /* skip header */
200 <                if (fscnresolu(&hr, &vr, fp) < 0 ||     /* check resolution */
199 >                getheader(fp, NULL, NULL);      /* skip header */
200 >                if (!fscnresolu(&hr, &vr, fp) ||        /* check resolution */
201                                  hr != hres*hmult || vr != vres*vmult) {
202                          fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n",
203                                          progname, outfile);
# Line 179 | Line 211 | char  **av;
211          scanorig = ftell(fp);           /* record position of first scanline */
212          if (fclose(fp) == -1)           /* done with stream i/o */
213                  goto filerr;
214 + #if NFS
215          sync();                         /* flush NFS buffers */
216 + #endif
217                                          /* start rpict process */
218          if (open_process(rpd, rpargv) <= 0) {
219                  fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
# Line 232 | Line 266 | int  *xp, *yp;
266                                  return(0);
267                          }
268                  }
269 <                sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp);
269 >                sprintf(buf, "%4d %4d\n%4d %4d\n", hmult, vmult, *xp, *yp);
270                  lseek(syncfd, 0L, 0);           /* write new position */
271                  write(syncfd, buf, strlen(buf));
272                  fls.l_type = F_UNLCK;           /* release sync file */
# Line 268 | Line 302 | rpiece()                       /* render picture piece by piece */
302   {
303          VIEW  pview;
304          int  xorg, yorg;
305 <        
305 >                                        /* compute view parameters */
306 >        copystruct(&pview, &ourview);
307 >        switch (ourview.type) {
308 >        case VT_PER:
309 >                pview.horiz = 2.*180./PI*atan(
310 >                                tan(PI/180./2.*ourview.horiz)/hmult );
311 >                pview.vert = 2.*180./PI*atan(
312 >                                tan(PI/180./2.*ourview.vert)/vmult );
313 >                break;
314 >        case VT_PAR:
315 >        case VT_ANG:
316 >                pview.horiz = ourview.horiz / hmult;
317 >                pview.vert = ourview.vert / vmult;
318 >                break;
319 >        case VT_HEM:
320 >                pview.horiz = 2.*180./PI*asin(
321 >                                sin(PI/180./2.*ourview.horiz)/hmult );
322 >                pview.vert = 2.*180./PI*asin(
323 >                                sin(PI/180./2.*ourview.vert)/vmult );
324 >                break;
325 >        default:
326 >                fprintf(stderr, "%s: unknown view type '-vt%c'\n",
327 >                                progname, ourview.type);
328 >                exit(cleanup(1));
329 >        }
330 >                                        /* render each piece */
331          while (nextpiece(&xorg, &yorg)) {
332 <                copystruct(&pview, &ourview);   /* compute view for piece */
333 <                switch (ourview.type) {
275 <                case VT_PER:
276 <                        pview.horiz = 2.*180./PI*atan(
277 <                                        tan(PI/180./2.*ourview.horiz)/hmult );
278 <                        pview.vert = 2.*180./PI*atan(
279 <                                        tan(PI/180./2.*ourview.vert)/vmult );
280 <                        break;
281 <                case VT_PAR:
282 <                case VT_ANG:
283 <                        pview.horiz = ourview.horiz / hmult;
284 <                        pview.vert = ourview.vert / vmult;
285 <                        break;
286 <                case VT_HEM:
287 <                        pview.horiz = 2.*180./PI*asin(
288 <                                        sin(PI/180./2.*ourview.horiz)/hmult );
289 <                        pview.vert = 2.*180./PI*asin(
290 <                                        sin(PI/180./2.*ourview.vert)/vmult );
291 <                        break;
292 <                default:
293 <                        fprintf(stderr, "%s: unknown view type '-vt%c'\n",
294 <                                        progname, ourview.type);
295 <                        exit(cleanup(1));
296 <                }
297 <                pview.hoff += xorg - 0.5*(hmult-1);
298 <                pview.voff += yorg - 0.5*(vmult-1);
332 >                pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1);
333 >                pview.voff = ourview.voff + yorg - 0.5*(vmult-1);
334                  fputs(VIEWSTR, torp);
335                  fprintview(&pview, torp);
336                  putc('\n', torp);
337 <                fflush(torp);                   /* assign piece to rpict */
337 >                fflush(torp);                   /* assigns piece to rpict */
338                  putpiece(xorg, yorg);           /* place piece in output */
339                  if (verbose) {                  /* notify caller */
340                          printf("%d %d done\n", xorg, yorg);
# Line 324 | Line 359 | int  xpos, ypos;
359                  exit(cleanup(1));
360          }
361                                  /* check header from rpict */
362 <        getheader(fromrp, NULL);
363 <        if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres || vr != vres) {
362 >        guard_io();
363 >        getheader(fromrp, NULL, NULL);
364 >        if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) {
365                  fprintf(stderr, "%s: resolution mismatch from %s\n",
366                                  progname, rpargv[0]);
367                  exit(cleanup(1));
368          }
369 +        unguard();
370                                  /* load new piece into buffer */
371 <        for (y = 0; y < vr; y++)
371 >        for (y = 0; y < vr; y++) {
372 >                guard_io();
373                  if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) {
374                          fprintf(stderr, "%s: read error from %s\n",
375                                          progname, rpargv[0]);
376                          exit(cleanup(1));
377                  }
378 +                unguard();
379 +        }
380   #if MAXFORK
381                                  /* fork so we don't slow rpict down */
382          if ((pid = fork()) > 0) {
# Line 351 | Line 391 | int  xpos, ypos;
391   #else
392          pid = -1;               /* no forking */
393   #endif
354                                /* lock file section so NFS doesn't mess up */
355        fls.l_whence = 0;
394          fls.l_len = (long)vres*hmult*hres*sizeof(COLR);
395          fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len;
396 + #if NFS
397 +                                /* lock file section so NFS doesn't mess up */
398 +        fls.l_whence = 0;
399          fls.l_type = F_WRLCK;
400          fcntl(outfd, F_SETLKW, &fls);
401 + #endif
402                                  /* write new piece to file */
403          if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1)
404                  goto seekerr;
# Line 375 | Line 417 | int  xpos, ypos;
417                                  goto seekerr;
418                  }
419          if (pid == -1) {        /* fork failed */
420 + #if NFS
421                  fls.l_type = F_UNLCK;           /* release lock */
422                  fcntl(outfd, F_SETLKW, &fls);
423 + #endif
424                  return(0);
425          }
426          _exit(0);               /* else exit child process (releasing lock) */
# Line 387 | Line 431 | writerr:
431          fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile);
432          _exit(1);
433   }
434 +
435 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines