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.16 by greg, Fri Jan 29 11:56:09 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 + #endif
42  
43                                  /* rpict command */
44   char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"};
# Line 102 | Line 122 | char  *argv[];
122                          case 'F':               /* syncronization file */
123                                  if (argv[i][2])
124                                          break;
125 <                                if ((syncfd = open(argv[++i], O_RDWR)) < 0) {
125 >                                if ((syncfd = open(argv[++i],
126 >                                                O_RDWR|O_CREAT, 0666)) < 0) {
127                                          fprintf(stderr, "%s: cannot open\n",
128                                                          argv[i]);
129                                          exit(1);
130                                  }
131                                  continue;
132 +                        case 'z':               /* z-file ist verbotten */
133 +                                fprintf(stderr, "%s: -z option not allowed\n",
134 +                                                argv[0]);
135 +                                exit(1);
136                          case 'o':               /* output file */
137                                  if (argv[i][2])
138                                          break;
# Line 123 | Line 148 | char  *argv[];
148          }
149          init(argc, argv);
150          rpiece();
151 <        rval = cleanup(0);
127 <        exit(rval);
151 >        exit(cleanup(0));
152   }
153  
154  
# Line 164 | Line 188 | char  **av;
188          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
189                  if ((fp = fdopen(dup(outfd), "r+")) == NULL)
190                          goto filerr;
191 <                getheader(fp, NULL);            /* skip header */
192 <                if (fscnresolu(&hr, &vr, fp) < 0 ||     /* check resolution */
191 >                getheader(fp, NULL, NULL);      /* skip header */
192 >                if (!fscnresolu(&hr, &vr, fp) ||        /* check resolution */
193                                  hr != hres*hmult || vr != vres*vmult) {
194                          fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n",
195                                          progname, outfile);
# Line 179 | Line 203 | char  **av;
203          scanorig = ftell(fp);           /* record position of first scanline */
204          if (fclose(fp) == -1)           /* done with stream i/o */
205                  goto filerr;
206 + #if NFS
207          sync();                         /* flush NFS buffers */
208 + #endif
209                                          /* start rpict process */
210          if (open_process(rpd, rpargv) <= 0) {
211                  fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
# Line 268 | Line 294 | rpiece()                       /* render picture piece by piece */
294   {
295          VIEW  pview;
296          int  xorg, yorg;
297 <        
297 >                                        /* compute view parameters */
298 >        copystruct(&pview, &ourview);
299 >        switch (ourview.type) {
300 >        case VT_PER:
301 >                pview.horiz = 2.*180./PI*atan(
302 >                                tan(PI/180./2.*ourview.horiz)/hmult );
303 >                pview.vert = 2.*180./PI*atan(
304 >                                tan(PI/180./2.*ourview.vert)/vmult );
305 >                break;
306 >        case VT_PAR:
307 >        case VT_ANG:
308 >                pview.horiz = ourview.horiz / hmult;
309 >                pview.vert = ourview.vert / vmult;
310 >                break;
311 >        case VT_HEM:
312 >                pview.horiz = 2.*180./PI*asin(
313 >                                sin(PI/180./2.*ourview.horiz)/hmult );
314 >                pview.vert = 2.*180./PI*asin(
315 >                                sin(PI/180./2.*ourview.vert)/vmult );
316 >                break;
317 >        default:
318 >                fprintf(stderr, "%s: unknown view type '-vt%c'\n",
319 >                                progname, ourview.type);
320 >                exit(cleanup(1));
321 >        }
322 >                                        /* render each piece */
323          while (nextpiece(&xorg, &yorg)) {
324 <                copystruct(&pview, &ourview);   /* compute view for piece */
325 <                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);
324 >                pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1);
325 >                pview.voff = ourview.voff + yorg - 0.5*(vmult-1);
326                  fputs(VIEWSTR, torp);
327                  fprintview(&pview, torp);
328                  putc('\n', torp);
329 <                fflush(torp);                   /* assign piece to rpict */
329 >                fflush(torp);                   /* assigns piece to rpict */
330                  putpiece(xorg, yorg);           /* place piece in output */
331                  if (verbose) {                  /* notify caller */
332                          printf("%d %d done\n", xorg, yorg);
# Line 324 | Line 351 | int  xpos, ypos;
351                  exit(cleanup(1));
352          }
353                                  /* check header from rpict */
354 <        getheader(fromrp, NULL);
355 <        if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres || vr != vres) {
354 >        getheader(fromrp, NULL, NULL);
355 >        if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) {
356                  fprintf(stderr, "%s: resolution mismatch from %s\n",
357                                  progname, rpargv[0]);
358                  exit(cleanup(1));
# Line 351 | Line 378 | int  xpos, ypos;
378   #else
379          pid = -1;               /* no forking */
380   #endif
354                                /* lock file section so NFS doesn't mess up */
355        fls.l_whence = 0;
381          fls.l_len = (long)vres*hmult*hres*sizeof(COLR);
382          fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len;
383 + #if NFS
384 +                                /* lock file section so NFS doesn't mess up */
385 +        fls.l_whence = 0;
386          fls.l_type = F_WRLCK;
387          fcntl(outfd, F_SETLKW, &fls);
388 + #endif
389                                  /* write new piece to file */
390          if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1)
391                  goto seekerr;
# Line 375 | Line 404 | int  xpos, ypos;
404                                  goto seekerr;
405                  }
406          if (pid == -1) {        /* fork failed */
407 + #if NFS
408                  fls.l_type = F_UNLCK;           /* release lock */
409                  fcntl(outfd, F_SETLKW, &fls);
410 + #endif
411                  return(0);
412          }
413          _exit(0);               /* else exit child process (releasing lock) */
# Line 387 | Line 418 | writerr:
418          fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile);
419          _exit(1);
420   }
421 +
422 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines