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.2 by greg, Thu Aug 6 17:16:29 1992 UTC vs.
Revision 2.6 by greg, Fri Aug 7 11:34:27 1992 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "standard.h"
12   #include <fcntl.h>
13 + #include <signal.h>
14   #include "color.h"
15   #include "view.h"
16   #include "resolu.h"
17  
18                                  /* rpict command */
19 < char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", };
20 < int  rpargc = 7;
19 > char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"};
20 > int  rpargc = 9;
21   int  rpd[3];
22   FILE  *torp, *fromrp;
23   COLR  *scanline;
24                                  /* our view parameters */
25   VIEW  ourview = STDVIEW;
26 < double  pixaspect = 0.0;
26 > double  pixaspect = 1.0;
27   int  hres = 512, vres = 512, hmult = 2, vmult = 2;
28                                  /* output file */
29   char  *outfile = NULL;
30   int  outfd;
31   long  scanorig;
32 + int  syncfd = -1;               /* lock file descriptor */
33  
34   char  *progname;
35   int  verbose = 0;
36  
37   extern long  lseek(), ftell();
38  
39 + int  gotalrm = 0;
40 + int  onalrm() { gotalrm++; }
41  
42 +
43   main(argc, argv)
44   int  argc;
45   char  *argv[];
# Line 88 | Line 93 | char  *argv[];
93                                          break;
94                                  vmult = atoi(argv[++i]);
95                                  continue;
96 +                        case 'F':               /* syncronization file */
97 +                                if (argv[i][2])
98 +                                        break;
99 +                                if ((syncfd = open(argv[++i], O_RDWR)) < 0) {
100 +                                        fprintf(stderr, "%s: cannot open\n",
101 +                                                        argv[i]);
102 +                                        exit(1);
103 +                                }
104 +                                continue;
105                          case 'o':               /* output file */
106                                  if (argv[i][2])
107                                          break;
# Line 121 | Line 135 | char  **av;
135                  fprintf(stderr, "%s: %s\n", progname, err);
136                  exit(1);
137          }
138 +        if (syncfd != -1) {
139 +                char  buf[32];
140 +                buf[read(syncfd, buf, sizeof(buf)-1)] = '\0';
141 +                sscanf(buf, "%d %d", &hmult, &vmult);
142 +        }
143          normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres);
144                                          /* open output file */
145          if ((outfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0666)) >= 0) {
# Line 137 | Line 156 | char  **av;
156                  putc('\n', fp);
157                  fprtresolu(hres*hmult, vres*vmult, fp);
158          } else if ((outfd = open(outfile, O_RDWR)) >= 0) {
140                sleep(30);                      /* wait for header */
159                  if ((fp = fdopen(dup(outfd), "r+")) == NULL)
160                          goto filerr;
161                  getheader(fp, NULL);            /* skip header */
# Line 154 | Line 172 | char  **av;
172          scanorig = ftell(fp);           /* record position of first scanline */
173          if (fclose(fp) == -1)           /* done with stream i/o */
174                  goto filerr;
175 +        sync();                         /* avoid NFS buffering */
176                                          /* start rpict process */
177          if (open_process(rpd, rpargv) <= 0) {
178 <                fprintf(stderr, "%s: cannot start\n", rpargv[0]);
178 >                fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]);
179                  exit(1);
180          }
181          if ((fromrp = fdopen(rpd[0], "r")) == NULL ||
# Line 169 | Line 188 | char  **av;
188                  fprintf(stderr, "%s: out of memory\n", progname);
189                  exit(1);
190          }
191 +        signal(SIGALRM, onalrm);
192          return;
193   filerr:
194          fprintf(stderr, "%s: file i/o error\n", outfile);
# Line 177 | Line 197 | filerr:
197  
198  
199   int
200 + nextpiece(xp, yp)               /* get next piece assignment */
201 + int  *xp, *yp;
202 + {
203 +        extern char  *fgets();
204 +        struct flock  fls;
205 +        char  buf[64];
206 +
207 +        if (gotalrm)                    /* someone wants us to quit */
208 +                return(0);
209 +        if (syncfd != -1) {             /* use sync file */
210 +                fls.l_type = F_WRLCK;           /* gain exclusive access */
211 +                fls.l_whence = 0;
212 +                fls.l_start = 0L;
213 +                fls.l_len = 0L;
214 +                fcntl(syncfd, F_SETLKW, &fls);
215 +                lseek(syncfd, 0L, 0);
216 +                buf[read(syncfd, buf, sizeof(buf)-1)] = '\0';
217 +                if (sscanf(buf, "%*d %*d %d %d", xp, yp) < 2) {
218 +                        *xp = hmult;
219 +                        *yp = vmult-1;
220 +                }
221 +                if (--(*xp) < 0) {              /* decrement position */
222 +                        *xp = hmult-1;
223 +                        if (--(*yp) < 0) {      /* all done! */
224 +                                close(syncfd);
225 +                                return(0);
226 +                        }
227 +                }
228 +                sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp);
229 +                lseek(syncfd, 0L, 0);           /* write new position */
230 +                write(syncfd, buf, strlen(buf));
231 +                fls.l_type = F_UNLCK;           /* release sync file */
232 +                fcntl(syncfd, F_SETLKW, &fls);
233 +                return(1);
234 +        }
235 +        if (fgets(buf, sizeof(buf), stdin) == NULL)     /* use stdin */
236 +                return(0);
237 +        if (sscanf(buf, "%d %d", xp, yp) == 2)
238 +                return(1);
239 +        fprintf(stderr, "%s: input format error\n", progname);
240 +        exit(1);
241 + }
242 +
243 +
244 + int
245   cleanup()                       /* close rpict process and clean up */
246   {
247          register int  rpstat;
# Line 193 | Line 258 | cleanup()                      /* close rpict process and clean up */
258  
259   rpiece()                        /* render picture piece by piece */
260   {
196        extern char  *gets(), *strcat();
261          VIEW  pview;
198        char  buf[48];
262          int  xorg, yorg;
263          
264 <        while (gets(buf) != NULL) {
202 <                if (sscanf(buf, "%d %d", &xorg, &yorg) != 2) {
203 <                        fprintf(stderr, "%s: input format error\n", progname);
204 <                        exit(1);
205 <                }
264 >        while (nextpiece(&xorg, &yorg)) {
265                  copystruct(&pview, &ourview);   /* compute view for piece */
266                  switch (ourview.type) {
267                  case VT_PER:
# Line 217 | Line 276 | rpiece()                       /* render picture piece by piece */
276                          pview.vert = ourview.vert / vmult;
277                          break;
278                  case VT_HEM:
279 +                        pview.horiz = 2.*180./PI*asin(
280 +                                        sin(PI/180./2.*ourview.horiz)/hmult );
281 +                        pview.vert = 2.*180./PI*asin(
282 +                                        sin(PI/180./2.*ourview.vert)/vmult );
283 +                        break;
284                  default:
285                          fprintf(stderr, "%s: unknown view type '-vt%c'\n",
286                                          progname, ourview.type);
# Line 230 | Line 294 | rpiece()                       /* render picture piece by piece */
294                  fflush(torp);                   /* assign piece to rpict */
295                  putpiece(xorg, yorg);           /* place piece in output */
296                  if (verbose) {                  /* notify caller */
297 <                        strcat(buf, " done\n");
298 <                        writebuf(fileno(stdout), buf, strlen(buf));
297 >                        printf("%d %d done\n", xorg, yorg);
298 >                        fflush(stdout);
299                  }
300          }
301   }
# Line 243 | Line 307 | int  xpos, ypos;
307          int  hr, vr;
308          int  y;
309  
310 +        if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) {
311 +                fprintf(stderr, "%s: requested piece (%d,%d) out of range\n",
312 +                                progname, xpos, ypos);
313 +                exit(1);
314 +        }
315          getheader(fromrp, NULL);        /* discard header info. */
316          if (fscnresolu(&hr, &vr, fromrp) < 0 || /* check resolution */
317                          hr != hres || vr != vres) {
318 <                fprintf(stderr, "%s: resolution mismatch from rpict\n",
319 <                                progname);
318 >                fprintf(stderr, "%s: resolution mismatch from %s\n",
319 >                                progname, rpargv[0]);
320                  exit(1);
321          }
322          for (y = 0; y < vr; y++) {      /* transfer scanlines */
323                  if (freadcolrs(scanline, hr, fromrp) < 0) {
324 <                        fprintf(stderr, "%s: read error from rpict\n",
325 <                                        progname);
324 >                        fprintf(stderr, "%s: read error from %s\n",
325 >                                        progname, rpargv[0]);
326                          exit(1);
327                  }
328                  if ((y == 0 || hmult != 1) && lseek(outfd,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines