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

Comparing ray/src/hd/rholo.c (file contents):
Revision 3.27 by gregl, Sun Dec 14 09:46:52 1997 UTC vs.
Revision 3.29 by gregl, Tue Dec 16 15:45:55 1997 UTC

# Line 58 | Line 58 | main(argc, argv)
58   int     argc;
59   char    *argv[];
60   {
61        HDGRID  hdg;
61          int     i;
62                                                  /* mark start time */
63          starttime = time(NULL);
# Line 108 | Line 107 | char   *argv[];
107                                                  /* load RIF if any */
108          getradfile();
109  
110 <        if (hdlist[i] == NULL) {                /* create new holodeck */
110 >        if (hdlist[0] == NULL) {                /* create new holodeck */
111 >                HDGRID  hdg[HDMAX];
112                                                          /* set defaults */
113 <                setdefaults(&hdg);
113 >                setdefaults(hdg);
114                                                          /* holodeck exists? */
115                  if (!force && access(hdkfile, R_OK|W_OK) == 0)
116                          error(USER,
117                                  "holodeck file exists -- use -f to overwrite");
118                                                          /* create holodeck */
119 <                creatholo(&hdg);
119 >                creatholo(hdg);
120          } else                                  /* else just set defaults */
121                  setdefaults(NULL);
122                                                  /* initialize */
# Line 142 | Line 142 | int  signo;
142          if (gotsig++)                   /* two signals and we're gone! */
143                  _exit(signo);
144  
145 <        alarm(30);                      /* allow 30 seconds to clean up */
145 >        alarm(60);                      /* allow 60 seconds to clean up */
146          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
147          eputs("signal - ");
148          eputs(sigerr[signo]);
# Line 272 | Line 272 | rholo()                                /* holodeck main loop */
272                  if (!disp_check(idle))
273                          return(0);
274                                          /* display only? */
275 <        if (nprocs <= 0)
275 >        if (nprocs <= 0) {
276 >                idle = 1;
277                  return(outdev != NULL);
278 +        }
279                                          /* check file size */
280          if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) {
281                  error(WARNING, "file limit exceeded");
282                  done_rtrace();
281                idle = 1;
283                  return(1);      /* comes back */
284          }
285                                          /* check time */
# Line 287 | Line 288 | rholo()                                /* holodeck main loop */
288          if (endtime > 0 && t >= endtime) {
289                  error(WARNING, "time limit exceeded");
290                  done_rtrace();
290                idle = 1;
291                  return(1);      /* comes back */
292          }
293          if (reporttime > 0 && t >= reporttime)
294                  report(t);
295 <                                        /* get packets to process */
295 >        idle = 0;                       /* get packets to process */
296          while (freepacks != NULL) {
297                  p = freepacks; freepacks = p->next; p->next = NULL;
298                  if (!next_packet(p)) {
# Line 315 | Line 315 | register HDGRID        *gp;
315   {
316          extern char     *atos();
317          register int    i;
318 +        int     n;
319          double  len[3], maxlen, d;
320          char    buf[64];
321  
# Line 322 | Line 323 | register HDGRID        *gp;
323                  sprintf(errmsg, "%s must be defined", vnam(SECTION));
324                  error(USER, errmsg);
325          }
325        if (vdef(SECTION) > 1) {
326                sprintf(errmsg, "ignoring all but first %s", vnam(SECTION));
327                error(WARNING, errmsg);
328        }
326          if (!vdef(OCTREE)) {
327                  if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL)
328                          error(SYSTEM, "out of memory");
# Line 336 | Line 333 | register HDGRID        *gp;
333                  vval(VDIST) = "F";
334                  vdef(VDIST)++;
335          }
339        if (!vdef(OCCUPANCY)) {
340                vval(OCCUPANCY) = "U";
341                vdef(OCCUPANCY)++;
342        }
336                                  /* append rendering options */
337          if (vdef(RENDER))
338                  rtargc += wordstring(rtargv+rtargc, vval(RENDER));
# Line 347 | Line 340 | register HDGRID        *gp;
340          if (gp == NULL)         /* already initialized? */
341                  return;
342                                  /* set grid parameters */
343 <        gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
344 <        if (sscanf(vval(SECTION),
343 >        for (n = 0; n < vdef(SECTION); n++, gp++) {
344 >                gp->grid[0] = gp->grid[1] = gp->grid[2] = 0;
345 >                if (sscanf(nvalue(SECTION, n),
346                  "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd",
347 <                        &gp->orig[0], &gp->orig[1], &gp->orig[2],
348 <                        &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
349 <                        &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
350 <                        &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
351 <                        &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
352 <                badvalue(SECTION);
353 <        maxlen = 0.;
354 <        for (i = 0; i < 3; i++)
355 <                if ((len[i] = VLEN(gp->xv[i])) > maxlen)
356 <                        maxlen = len[i];
357 <        if (!vdef(GRID)) {
358 <                sprintf(buf, "%.4f", maxlen/8.);
359 <                vval(GRID) = savqstr(buf);
360 <                vdef(GRID)++;
347 >                                &gp->orig[0], &gp->orig[1], &gp->orig[2],
348 >                                &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2],
349 >                                &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2],
350 >                                &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2],
351 >                                &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12)
352 >                        badvalue(SECTION);
353 >                maxlen = 0.;
354 >                for (i = 0; i < 3; i++)
355 >                        if ((len[i] = VLEN(gp->xv[i])) > maxlen)
356 >                                maxlen = len[i];
357 >                if (!vdef(GRID))
358 >                        d = 0.125*maxlen;
359 >                else if ((d = vflt(GRID)) <= FTINY)
360 >                        badvalue(GRID);
361 >                for (i = 0; i < 3; i++)
362 >                        if (gp->grid[i] <= 0)
363 >                                gp->grid[i] = len[i]/d + (1.-FTINY);
364          }
368        if ((d = vflt(GRID)) <= FTINY)
369                badvalue(GRID);
370        for (i = 0; i < 3; i++)
371                if (gp->grid[i] <= 0)
372                        gp->grid[i] = len[i]/d + (1.-FTINY);
365   }
366  
367  
# Line 377 | Line 369 | creatholo(gp)                  /* create a holodeck output file */
369   HDGRID  *gp;
370   {
371          extern char     VersionID[];
372 <        long    endloc = 0;
372 >        int4    lastloc, nextloc;
373 >        int     n;
374          int     fd;
375          FILE    *fp;
376                                          /* open & truncate file */
# Line 391 | Line 384 | HDGRID *gp;
384          printvars(fp);
385          fputformat(HOLOFMT, fp);
386          fputc('\n', fp);
387 <        putw(HOLOMAGIC, fp);            /* put magic number & terminus */
395 <        fwrite(&endloc, sizeof(long), 1, fp);
387 >        putw(HOLOMAGIC, fp);            /* put magic number */
388          fd = dup(fileno(fp));
389          fclose(fp);                     /* flush and close stdio stream */
390 <        hdinit(fd, gp);                 /* allocate and initialize index */
390 >        lastloc = lseek(fd, 0L, 2);
391 >        for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */
392 >                nextloc = 0L;
393 >                write(fd, (char *)&nextloc, sizeof(nextloc));
394 >                hdinit(fd, gp);                 /* writes beam index */
395 >                if (!n)
396 >                        break;
397 >                nextloc = hdfilen(fd);          /* write section pointer */
398 >                if (lseek(fd, (long)lastloc, 0) < 0)
399 >                        error(SYSTEM,
400 >                                "cannot seek on holodeck file in creatholo");
401 >                write(fd, (char *)&nextloc, sizeof(nextloc));
402 >                lseek(fd, (long)(lastloc=nextloc), 0);
403 >        }
404   }
405  
406  
# Line 428 | Line 433 | loadholo()                     /* start loading a holodeck from fname */
433          extern long     ftell();
434          FILE    *fp;
435          int     fd;
436 <        long    fpos;
436 >        int     n;
437 >        int4    nextloc;
438                                          /* open holodeck file */
439          if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) {
440                  sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile,
# Line 443 | Line 449 | loadholo()                     /* start loading a holodeck from fname */
449                                  hdkfile);
450                  error(USER, errmsg);
451          }
452 <        fread(&fpos, sizeof(long), 1, fp);
447 <        if (fpos != 0)
448 <                error(WARNING, "ignoring multiple sections in holodeck file");
449 <        fpos = ftell(fp);                       /* get stdio position */
452 >        nextloc = ftell(fp);                    /* get stdio position */
453          fd = dup(fileno(fp));
454          fclose(fp);                             /* done with stdio */
455 <        lseek(fd, fpos, 0);                     /* align system file pointer */
456 <        hdinit(fd, NULL);                       /* allocate and load index */
455 >        for (n = 0; nextloc > 0L; n++) {        /* initialize each section */
456 >                lseek(fd, (long)nextloc, 0);
457 >                read(fd, (char *)&nextloc, sizeof(nextloc));
458 >                hdinit(fd, NULL);
459 >        }
460 >        if (n != vdef(SECTION)) {
461 >                sprintf(errmsg, "number of sections does not match %s setting",
462 >                                vnam(SECTION));
463 >                error(WARNING, errmsg);
464 >        }
465   }
466  
467  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines