ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/rt/rmain.c
(Generate patch)

Comparing ray/src/rt/rmain.c (file contents):
Revision 2.11 by greg, Fri Oct 9 10:26:46 1992 UTC vs.
Revision 2.41 by greg, Sat Jul 6 21:59:00 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 27 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27  
28   #include  "octree.h"
29  
30 + #include  <sys/types.h>
31 +
32   #include  <signal.h>
33  
34   #include  "view.h"
35  
36   #include  "paths.h"
37 +                                        /* persistent processes define */
38 + #ifdef  F_SETLKW
39 + #if  RPICT|RTRACE
40 + #define  PERSIST        1               /* normal persist */
41 + #define  PARALLEL       2               /* parallel persist */
42 + #define  PCHILD         3               /* child of normal persist */
43 + #endif
44 + #endif
45  
46   char  *progname;                        /* argv[0] */
47  
48   char  *octname;                         /* octree name */
49  
50 < char  *libpath;                         /* library directory list */
50 > char  *getlibpath();                    /* library directory list */
51  
52   char  *sigerr[NSIG];                    /* signal error messages */
53  
54 + char  *shm_boundary = NULL;             /* boundary of shared memory */
55 +
56   extern char  VersionID[];               /* version ID string */
57  
58   extern int  stderr_v();                 /* standard error output */
# Line 51 | Line 63 | int  (*cmdvec)() = NULL;               /* command error vector */
63   int  (*trace)() = NULL;                 /* trace call */
64   int  do_irrad = 0;                      /* compute irradiance? */
65  
66 < extern long  time();
55 < long  tstart;                           /* start time */
66 > char  *errfile = NULL;                  /* error output file */
67  
68 + extern time_t  time();
69 + time_t  tstart;                         /* start time */
70 +
71   extern int  ambnotify();                /* new object notify functions */
72 + #if  RTRACE
73 + extern int  tranotify();
74 + int  (*addobjnotify[])() = {ambnotify, tranotify, NULL};
75 + extern char  *tralist[];                /* trace include/exclude list */
76 + extern int  traincl;                    /* include == 1, exclude == 0 */
77 + #else
78   int  (*addobjnotify[])() = {ambnotify, NULL};
79 + #endif
80  
81   CUBE  thescene;                         /* our scene */
82   OBJECT  nsceneobjs;                     /* number of objects in our scene */
83  
84 + extern unsigned long  raynum, nrays;    /* ray counts */
85 +
86   extern int  imm_irrad;                  /* calculate immediate irradiance? */
87  
88   extern int  ralrm;                      /* seconds between reports */
89  
90   extern int  greyscale;                  /* map colors to brightness? */
91   extern char  *devname;                  /* output device name */
92 + extern double  exposure;                /* exposure compensation */
93  
94   extern char  *formstr();                /* string from format */
95   extern int  inform;                     /* input format */
# Line 74 | Line 98 | extern char  *outvals;                 /* output values */
98  
99   extern VIEW  ourview;                   /* viewing parameters */
100  
101 + extern char  rifname[];                 /* rad input file name */
102 +
103   extern int  hresolu;                    /* horizontal resolution */
104   extern int  vresolu;                    /* vertical resolution */
105   extern double  pixaspect;               /* pixel aspect ratio */
# Line 87 | Line 113 | extern double  shadthresh;             /* shadow threshold */
113   extern double  shadcert;                /* shadow testing certainty */
114   extern int  directrelay;                /* number of source relays */
115   extern int  vspretest;                  /* virtual source pretest density */
116 < extern int  directinvis;                /* light sources invisible to eye? */
116 > extern int  directvis;                  /* light sources visible to eye? */
117   extern double  srcsizerat;              /* maximum source size/dist. ratio */
118  
119   extern double  specthresh;              /* specular sampling threshold */
120   extern double  specjitter;              /* specular sampling jitter */
121  
122 + extern COLOR  cextinction;              /* global extinction coefficient */
123 + extern COLOR  salbedo;                  /* global scattering albedo */
124 + extern double  seccg;                   /* global scattering eccentricity */
125 + extern double  ssampdist;               /* scatter sampling distance */
126 +
127 + extern int  backvis;                    /* back face visibility */
128 +
129   extern int  maxdepth;                   /* maximum recursion depth */
130   extern double  minweight;               /* minimum ray weight */
131  
132   extern COLOR  ambval;                   /* ambient value */
133 + extern int  ambvwt;                     /* initial weight for ambient value */
134   extern double  ambacc;                  /* ambient accuracy */
135   extern int  ambres;                     /* ambient resolution */
136   extern int  ambdiv;                     /* ambient divisions */
# Line 120 | Line 154 | char  *argv[];
154                                  case 'n': case 'N': case 'f': case 'F': \
155                                  case '-': case '0': var = 0; break; \
156                                  default: goto badopt; }
123        extern char  *getenv();
157          char  *err;
158          char  *recover = NULL;
159          char  *outfile = NULL;
160          char  *zfile = NULL;
128        char  *errfile = NULL;
161          char  *ambfile = NULL;
130        char  **amblp = amblist;
162          int  loadflags = ~IO_FILES;
163          int  seqstart = 0;
164 +        int  persist = 0;
165 +        char  **amblp;
166 +        char  **tralp;
167 +        int  duped1;
168          int  rval;
169          int  i;
170                                          /* record start time */
171 <        tstart = time((long *)0);
171 >        tstart = time((time_t *)NULL);
172                                          /* global program name */
173          progname = argv[0] = fixargv0(argv[0]);
139                                        /* get library path */
140        if ((libpath = getenv(ULIBVAR)) == NULL)
141                libpath = DEFPATH;
174                                          /* initialize object types */
175          initotypes();
176                                          /* initialize urand */
177          initurand(2048);
178                                          /* option city */
179 <        for (i = 1; i < argc && argv[i][0] == '-'; i++) {
179 >        for (i = 1; i < argc; i++) {
180 >                                                /* expand arguments */
181 >                while (rval = expandarg(&argc, &argv, i))
182 >                        if (rval < 0) {
183 >                                sprintf(errmsg, "cannot expand '%s'", argv[i]);
184 >                                error(SYSTEM, errmsg);
185 >                        }
186 >                if (argv[i] == NULL || argv[i][0] != '-')
187 >                        break;                  /* break from options */
188                  if (!strcmp(argv[i], "-version")) {
189                          puts(VersionID);
190                          quit(0);
# Line 187 | Line 227 | char  *argv[];
227                          }
228                          break;
229   #endif
230 +                case 'b':                               /* back face vis. */
231 +                        if (argv[i][2] == 'v') {
232 +                                bool(3,backvis);
233 +                                break;
234 +                        }
235 + #if  RVIEW
236 +                        bool(2,greyscale);
237 +                        break;
238 + #else
239 +                        goto badopt;
240 + #endif
241                  case 'd':                               /* direct */
242                          switch (argv[i][2]) {
243                          case 't':                               /* threshold */
# Line 209 | Line 260 | char  *argv[];
260                                  check(3,"i");
261                                  vspretest = atoi(argv[++i]);
262                                  break;
263 <                        case 'i':                               /* invis. */
264 <                                bool(3,directinvis);
263 >                        case 'v':                               /* visibility */
264 >                                bool(3,directvis);
265                                  break;
266                          case 's':                               /* size */
267                                  check(3,"f");
# Line 255 | Line 306 | char  *argv[];
306                                  pixaspect = atof(argv[++i]);
307                                  break;
308   #endif
309 + #if  RVIEW
310 +                        case 'e':                               /* exposure */
311 +                                check(3,"f");
312 +                                exposure = atof(argv[++i]);
313 +                                if (argv[i][0] == '+' || argv[i][0] == '-')
314 +                                        exposure = pow(2.0, exposure);
315 +                                break;
316 + #endif
317                          default:
318                                  goto badopt;
319                          }
# Line 311 | Line 370 | char  *argv[];
370                          zfile = argv[++i];
371                          break;
372                  case 'r':                               /* recover file */
373 <                        check(2,"s");
373 >                        if (argv[i][2] == 'o') {                /* +output */
374 >                                check(3,"s");
375 >                                outfile = argv[i+1];
376 >                        } else
377 >                                check(2,"s");
378                          recover = argv[++i];
379                          break;
380                  case 't':                               /* timer */
# Line 328 | Line 391 | char  *argv[];
391                                                  atof(argv[i+3]));
392                                  i += 3;
393                                  break;
394 +                        case 'w':                               /* weight */
395 +                                check(3,"i");
396 +                                ambvwt = atoi(argv[++i]);
397 +                                break;
398                          case 'a':                               /* accuracy */
399                                  check(3,"f");
400                                  ambacc = atof(argv[++i]);
# Line 356 | Line 423 | char  *argv[];
423                                          amblp = amblist;
424                                  }
425                                  if (argv[i][2] == 'I') {        /* file */
426 <                                        rval = wordfile(amblp, argv[++i]);
426 >                                        rval = wordfile(amblp,
427 >                                        getpath(argv[++i],getlibpath(),R_OK));
428                                          if (rval < 0) {
429                                                  sprintf(errmsg,
430                                  "cannot open ambient include file \"%s\"",
# Line 364 | Line 432 | char  *argv[];
432                                                  error(SYSTEM, errmsg);
433                                          }
434                                          amblp += rval;
435 <                                } else
435 >                                } else {
436                                          *amblp++ = argv[++i];
437 +                                        *amblp = NULL;
438 +                                }
439                                  break;
440                          case 'e':                               /* exclude */
441                          case 'E':
# Line 375 | Line 445 | char  *argv[];
445                                          amblp = amblist;
446                                  }
447                                  if (argv[i][2] == 'E') {        /* file */
448 <                                        rval = wordfile(amblp, argv[++i]);
448 >                                        rval = wordfile(amblp,
449 >                                        getpath(argv[++i],getlibpath(),R_OK));
450                                          if (rval < 0) {
451                                                  sprintf(errmsg,
452                                  "cannot open ambient exclude file \"%s\"",
# Line 383 | Line 454 | char  *argv[];
454                                                  error(SYSTEM, errmsg);
455                                          }
456                                          amblp += rval;
457 <                                } else
457 >                                } else {
458                                          *amblp++ = argv[++i];
459 +                                        *amblp = NULL;
460 +                                }
461                                  break;
462                          case 'f':                               /* file */
463                                  check(3,"s");
# Line 394 | Line 467 | char  *argv[];
467                                  goto badopt;
468                          }
469                          break;
470 +                case 'm':                               /* medium */
471 +                        switch (argv[i][2]) {
472 +                        case 'e':                               /* extinction */
473 +                                check(3,"fff");
474 +                                setcolor(cextinction, atof(argv[i+1]),
475 +                                                atof(argv[i+2]),
476 +                                                atof(argv[i+3]));
477 +                                i += 3;
478 +                                break;
479 +                        case 'a':                               /* albedo */
480 +                                check(3,"fff");
481 +                                setcolor(salbedo, atof(argv[i+1]),
482 +                                                atof(argv[i+2]),
483 +                                                atof(argv[i+3]));
484 +                                i += 3;
485 +                                break;
486 +                        case 'g':                               /* eccentr. */
487 +                                check(3,"f");
488 +                                seccg = atof(argv[++i]);
489 +                                break;
490 +                        case 's':                               /* sampling */
491 +                                check(3,"f");
492 +                                ssampdist = atof(argv[++i]);
493 +                                break;
494 +                        default:
495 +                                goto badopt;
496 +                        }
497 +                        break;
498   #if  RTRACE
499                  case 'I':                               /* immed. irradiance */
500                          bool(2,imm_irrad);
# Line 432 | Line 533 | char  *argv[];
533                          loadflags = rval ? loadflags | IO_INFO :
534                                          loadflags & ~IO_INFO;
535                          break;
536 +                case 't':                               /* trace */
537 +                        switch (argv[i][2]) {
538 +                        case 'i':                               /* include */
539 +                        case 'I':
540 +                                check(3,"s");
541 +                                if (traincl != 1) {
542 +                                        traincl = 1;
543 +                                        tralp = tralist;
544 +                                }
545 +                                if (argv[i][2] == 'I') {        /* file */
546 +                                        rval = wordfile(tralp,
547 +                                        getpath(argv[++i],getlibpath(),R_OK));
548 +                                        if (rval < 0) {
549 +                                                sprintf(errmsg,
550 +                                "cannot open trace include file \"%s\"",
551 +                                                                argv[i]);
552 +                                                error(SYSTEM, errmsg);
553 +                                        }
554 +                                        tralp += rval;
555 +                                } else {
556 +                                        *tralp++ = argv[++i];
557 +                                        *tralp = NULL;
558 +                                }
559 +                                break;
560 +                        case 'e':                               /* exclude */
561 +                        case 'E':
562 +                                check(3,"s");
563 +                                if (traincl != 0) {
564 +                                        traincl = 0;
565 +                                        tralp = tralist;
566 +                                }
567 +                                if (argv[i][2] == 'E') {        /* file */
568 +                                        rval = wordfile(tralp,
569 +                                        getpath(argv[++i],getlibpath(),R_OK));
570 +                                        if (rval < 0) {
571 +                                                sprintf(errmsg,
572 +                                "cannot open trace exclude file \"%s\"",
573 +                                                                argv[i]);
574 +                                                error(SYSTEM, errmsg);
575 +                                        }
576 +                                        tralp += rval;
577 +                                } else {
578 +                                        *tralp++ = argv[++i];
579 +                                        *tralp = NULL;
580 +                                }
581 +                                break;
582 +                        default:
583 +                                goto badopt;
584 +                        }
585 +                        break;
586   #endif
587   #if  RVIEW
437                case 'b':                               /* black and white */
438                        bool(2,greyscale);
439                        break;
588                  case 'o':                               /* output device */
589                          check(2,"s");
590                          devname = argv[++i];
591                          break;
592 +                case 'R':                               /* render input file */
593 +                        check(2,"s");
594 +                        strcpy(rifname, argv[++i]);
595 +                        break;
596   #endif
597 + #ifdef  PERSIST
598 +                case 'P':                               /* persist file */
599 +                        if (argv[i][2] == 'P') {
600 +                                check(3,"s");
601 +                                persist = PARALLEL;
602 +                        } else {
603 +                                check(2,"s");
604 +                                persist = PERSIST;
605 +                        }
606 +                        persistfile(argv[++i]);
607 +                        break;
608 + #endif
609                  default:
610                          goto badopt;
611                  }
612          }
449        *amblp = NULL;
613   #if  RPICT|RVIEW
614          err = setview(&ourview);        /* set viewing parameters */
615          if (err != NULL)
# Line 469 | Line 632 | char  *argv[];
632                  fprintf(stderr, "**************\n*** PID %5d: ",
633                                  getpid());
634                  printargs(argc, argv, stderr);
635 <                fputs("\n", stderr);
635 >                putc('\n', stderr);
636                  fflush(stderr);
637          }
638   #ifdef  NICE
# Line 491 | Line 654 | char  *argv[];
654   #endif
655                          octname == NULL)
656                  error(USER, "missing octree argument");
657 +                                        /* set up output */
658 + #ifdef  PERSIST
659 +        if (persist) {
660   #if  RPICT
661 +                if (recover != NULL)
662 +                        error(USER, "persist option used with recover file");
663 +                if (seqstart <= 0)
664 +                        error(USER, "persist option only for sequences");
665 +                if (outfile == NULL)
666 + #endif
667 +                duped1 = dup(fileno(stdout));   /* don't lose our output */
668 +                openheader();
669 +        }
670 + #if  RPICT
671 +        else
672 + #endif
673 + #endif
674 + #if  RPICT
675          if (outfile != NULL)
676                  openheader();
677   #endif
# Line 519 | Line 699 | char  *argv[];
699  
700          setambient(ambfile);            /* initialize ambient calculation */
701  
702 + #ifdef  PERSIST
703 +        if (persist) {
704 +                fflush(stdout);
705 +                if (outfile == NULL) {          /* reconnect stdout */
706 +                        dup2(duped1, fileno(stdout));
707 +                        close(duped1);
708 +                }
709 +                if (persist == PARALLEL) {      /* multiprocessing */
710 +                        preload_objs();         /* preload scene */
711 +                        strcpy(shm_boundary=bmalloc(16), "SHM_BOUNDARY");
712 +                        while ((rval=fork()) == 0) {    /* keep on forkin' */
713 +                                pflock(1);
714 +                                pfhold();
715 +                                tstart = time((time_t *)NULL);
716 +                        }
717 +                        if (rval < 0)
718 +                                error(SYSTEM, "cannot fork child for persist function");
719 +                        pfdetach();             /* parent exits */
720 +                }
721 +        }
722 + runagain:
723 +        if (persist)
724 +                if (outfile == NULL)                    /* if out to stdout */
725 +                        dupheader();                    /* send header */
726 +                else                                    /* if out to file */
727 +                        duped1 = dup(fileno(stdout));   /* hang onto pipe */
728 + #endif
729   #if  RPICT
730          rpict(seqstart, outfile, zfile, recover);
731   #endif
# Line 528 | Line 735 | char  *argv[];
735   #if  RVIEW
736          rview();
737   #endif
738 +        ambsync();                      /* flush ambient file */
739 + #ifdef  PERSIST
740 +        if (persist == PERSIST) {       /* first run-through */
741 +                if ((rval=fork()) == 0) {       /* child loops until killed */
742 +                        pflock(1);
743 +                        persist = PCHILD;
744 +                } else {                        /* original process exits */
745 +                        if (rval < 0)
746 +                                error(SYSTEM, "cannot fork child for persist function");
747 +                        pfdetach();             /* parent exits */
748 +                }
749 +        }
750 +        if (persist == PCHILD) {        /* wait for a signal then go again */
751 +                if (outfile != NULL)
752 +                        close(duped1);          /* release output handle */
753 +                pfhold();
754 +                tstart = time((time_t *)NULL);  /* reinitialize */
755 +                raynum = nrays = 0;
756 +                goto runagain;
757 +        }
758 + #endif
759          quit(0);
760  
761   badopt:
# Line 634 | Line 862 | printdefaults()                        /* print default values to stdout */
862                          ourview.type==VT_PAR ? "parallel" :
863                          ourview.type==VT_HEM ? "hemispherical" :
864                          ourview.type==VT_ANG ? "angular" :
865 +                        ourview.type==VT_CYL ? "cylindrical" :
866                          "unknown");
867          printf("-vp %f %f %f\t# view point\n",
868                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
# Line 643 | Line 872 | printdefaults()                        /* print default values to stdout */
872                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
873          printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
874          printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
875 +        printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
876 +        printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
877          printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
878          printf("-vl %f\t\t\t# view lift\n", ourview.voff);
879   #endif
# Line 654 | Line 885 | printdefaults()                        /* print default values to stdout */
885          printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect);
886          printf("-pj %f\t\t\t# pixel jitter\n", dstrpix);
887   #endif
888 + #if  RVIEW
889 +        printf("-pe %f\t\t\t# pixel exposure\n", exposure);
890 + #endif
891   #if  RPICT|RVIEW
892          printf("-ps %-9d\t\t\t# pixel sample\n", psample);
893          printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
894   #endif
895 +        printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" :
896 +                        "-bv-\t\t\t\t# back face visibility off\n");
897          printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
898          printf("-dc %f\t\t\t# direct certainty\n", shadcert);
899          printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
900          printf("-ds %f\t\t\t# direct sampling\n", srcsizerat);
901          printf("-dr %-9d\t\t\t# direct relays\n", directrelay);
902          printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest);
903 <        printf(directinvis ? "-di+\t\t\t\t# direct invisibility on\n" :
904 <                        "-di-\t\t\t\t# direct invisibility off\n");
903 >        printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" :
904 >                        "-dv-\t\t\t\t# direct visibility off\n");
905          printf("-sj %f\t\t\t# specular jitter\n", specjitter);
906          printf("-st %f\t\t\t# specular threshold\n", specthresh);
907          printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
908                          colval(ambval,GRN), colval(ambval, BLU));
909 +        printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt);
910          printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
911          printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
912          printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
913          printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
914          printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
915 +        printf("-me %.2e %.2e %.2e\t# extinction coefficient\n",
916 +                        colval(cextinction,RED),
917 +                        colval(cextinction,GRN),
918 +                        colval(cextinction,BLU));
919 +        printf("-ma %f %f %f\t# scattering albedo\n", colval(salbedo,RED),
920 +                        colval(salbedo,GRN), colval(salbedo,BLU));
921 +        printf("-mg %f\t\t\t# scattering eccentricity\n", seccg);
922 +        printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist);
923          printf("-lr %-9d\t\t\t# limit reflection\n", maxdepth);
924          printf("-lw %f\t\t\t# limit weight\n", minweight);
925   #if  RPICT
# Line 694 | Line 939 | printdefaults()                        /* print default values to stdout */
939                  case 'd': printf(" direction"); break;
940                  case 'v': printf(" value"); break;
941                  case 'l': printf(" length"); break;
942 +                case 'L': printf(" first_length"); break;
943                  case 'p': printf(" point"); break;
944                  case 'n': printf(" normal"); break;
945 +                case 'N': printf(" unperturbed_normal"); break;
946                  case 's': printf(" surface"); break;
947                  case 'w': printf(" weight"); break;
948                  case 'm': printf(" modifier"); break;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)