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

Comparing ray/src/rt/rpmain.c (file contents):
Revision 2.3 by schorsch, Thu Jun 5 19:29:34 2003 UTC vs.
Revision 2.31 by greg, Thu Jan 18 00:28:54 2024 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7  
8   #include "copyright.h"
9  
10 < #include  <sys/types.h>
10 > #include  <time.h>
11   #include  <signal.h>
12  
13   #include  "platform.h"
14 + #include  "rtprocess.h" /* getpid() */
15   #include  "ray.h"
16   #include  "source.h"
17   #include  "ambient.h"
18   #include  "random.h"
19   #include  "paths.h"
20   #include  "view.h"
21 + #include  "pmapray.h"
22  
23                                          /* persistent processes define */
24   #ifdef  F_SETLKW
# Line 26 | Line 28 | static const char      RCSid[] = "$Id$";
28   #endif
29  
30   char  *progname;                        /* argv[0] */
29
31   char  *octname;                         /* octree name */
31
32   char  *sigerr[NSIG];                    /* signal error messages */
33
33   char  *shm_boundary = NULL;             /* boundary of shared memory */
35
34   char  *errfile = NULL;                  /* error output file */
35  
36   extern time_t  time();
# Line 52 | Line 50 | extern double  dstrpix;                        /* square pixel distribution
50  
51   extern double  mblur;                   /* motion blur parameter */
52  
53 < void    onsig();
56 < void    sigdie();
57 < void    printdefaults();
53 > extern double  dblur;                   /* depth-of-field blur parameter */
54  
55 + RGBPRIMP  out_prims = stdprims;         /* output color primitives */
56 + static RGBPRIMS  our_prims;             /* private output color primitives */
57  
58 + static void onsig(int signo);
59 + static void sigdie(int  signo, char  *msg);
60 + static void printdefaults(void);
61 +                                        /* rpict additional features */
62 + #ifdef PERSIST
63 + #define RPICT_FEATURES  "Persist\nParallelPersist\n" \
64 +                "ParticipatingMedia=Mist\n" \
65 +                "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
66 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
67 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
68 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
69 +                "AdaptiveShadowTesting\nOutputs=v,l\n"
70 + #else
71 + #define RPICT_FEATURES  "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
72 +                "ParticipatingMedia=Mist\n" \
73 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
74 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
75 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
76 +                "AdaptiveShadowTesting\nOutputs=v,l\n"
77 + #endif
78 +
79 +
80   int
81 < main(argc, argv)
62 < int  argc;
63 < char  *argv[];
81 > main(int  argc, char  *argv[])
82   {
83   #define  check(ol,al)           if (argv[i][ol] || \
84                                  badarg(argc-i-1,argv+i+1,al)) \
85                                  goto badopt
86 < #define  bool(olen,var)         switch (argv[i][olen]) { \
86 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
87                                  case '\0': var = !var; break; \
88                                  case 'y': case 'Y': case 't': case 'T': \
89                                  case '+': case '1': var = 1; break; \
# Line 79 | Line 97 | char  *argv[];
97          int  loadflags = ~IO_FILES;
98          int  seqstart = 0;
99          int  persist = 0;
100 <        int  duped1;
100 >        int  duped1 = -1;
101          int  rval;
102          int  i;
103                                          /* record start time */
104          tstart = time((time_t *)NULL);
105                                          /* global program name */
106          progname = argv[0] = fixargv0(argv[0]);
107 +                                        /* feature check only? */
108 +        strcat(RFeatureList, RPICT_FEATURES);
109 +        if (argc > 1 && !strcmp(argv[1], "-features"))
110 +                return feature_status(argc-2, argv+2);
111                                          /* option city */
112          for (i = 1; i < argc; i++) {
113                                                  /* expand arguments */
# Line 157 | Line 179 | char  *argv[];
179                                  check(3,"f");
180                                  mblur = atof(argv[++i]);
181                                  break;
182 +                        case 'd':                               /* aperture */
183 +                                check(3,"f");
184 +                                dblur = atof(argv[++i]);
185 +                                break;
186 +                        case 'R':                               /* standard RGB output */
187 +                                if (strcmp(argv[i]+2, "RGB"))
188 +                                        goto badopt;
189 +                                out_prims = stdprims;
190 +                                break;
191 +                        case 'X':                               /* XYZ output */
192 +                                if (strcmp(argv[i]+2, "XYZ"))
193 +                                        goto badopt;
194 +                                out_prims = xyzprims;
195 +                                break;
196 +                        case 'c': {                             /* chromaticities */
197 +                                int     j;
198 +                                check(3,"ffffffff");
199 +                                rval = 0;
200 +                                for (j = 0; j < 8; j++) {
201 +                                        our_prims[0][j] = atof(argv[++i]);
202 +                                        rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001;
203 +                                }
204 +                                if (rval) {
205 +                                        if (!colorprimsOK(our_prims))
206 +                                                error(USER, "illegal primary chromaticities");
207 +                                        out_prims = our_prims;
208 +                                } else
209 +                                        out_prims = stdprims;
210 +                                } break;
211                          default:
212                                  goto badopt;
213                          }
# Line 207 | Line 258 | char  *argv[];
258   #endif
259                  case 'w':                               /* warnings */
260                          rval = erract[WARNING].pf != NULL;
261 <                        bool(2,rval);
261 >                        check_bool(2,rval);
262                          if (rval) erract[WARNING].pf = wputs;
263                          else erract[WARNING].pf = NULL;
264                          break;
# Line 219 | Line 270 | char  *argv[];
270                          goto badopt;
271                  }
272          }
273 +                                        /* set/check spectral sampling */
274 +        if (setspectrsamp(CNDX, WLPART) <= 0)
275 +                error(USER, "unsupported spectral sampling");
276 +
277          err = setview(&ourview);        /* set viewing parameters */
278          if (err != NULL)
279                  error(USER, err);
280                                          /* initialize object types */
281          initotypes();
282                                          /* initialize urand */
283 <        initurand(2048);
283 >        if (rand_samp) {
284 >                srandom((long)time(0));
285 >                initurand(0);
286 >        } else {
287 >                srandom(0L);
288 >                initurand(2048);
289 >        }
290                                          /* set up signal handling */
291          sigdie(SIGINT, "Interrupt");
292 + #ifdef SIGHUP
293          sigdie(SIGHUP, "Hangup");
294 + #endif
295          sigdie(SIGTERM, "Terminate");
296 + #ifdef SIGPIPE
297          sigdie(SIGPIPE, "Broken pipe");
298 + #endif
299 + #ifdef SIGALRM
300          sigdie(SIGALRM, "Alarm clock");
301 + #endif
302   #ifdef  SIGXCPU
303          sigdie(SIGXCPU, "CPU limit exceeded");
304          sigdie(SIGXFSZ, "File size exceeded");
# Line 272 | Line 339 | char  *argv[];
339   #endif
340          if (outfile != NULL)
341                  openheader();
275 #ifdef  _WIN32
342          SET_FILE_BINARY(stdout);
343          if (octname == NULL)
344                  SET_FILE_BINARY(stdin);
279 #endif
345          readoct(octname, loadflags, &thescene, NULL);
346          nsceneobjs = nobjects;
347  
348          if (loadflags & IO_INFO) {      /* print header */
349                  printargs(i, argv, stdout);
350                  printf("SOFTWARE= %s\n", VersionID);
286                fputnow(stdout);
351          }
352 +                  
353 +        ray_init_pmap();     /* PMAP: set up & load photon maps */
354  
355          marksources();                  /* find and mark sources */
356  
357          setambient();                   /* initialize ambient calculation */
358 +        
359 +        fflush(stdout);                 /* in case we're duplicating header */
360  
361   #ifdef  PERSIST
362          if (persist) {
295                fflush(stdout);
363                  if (outfile == NULL) {          /* reconnect stdout */
364                          dup2(duped1, fileno(stdout));
365                          close(duped1);
# Line 305 | Line 372 | char  *argv[];
372                                  pflock(1);
373                                  pfhold();
374                                  tstart = time((time_t *)NULL);
375 +                                ambsync();              /* load new values */
376                          }
377                          if (rval < 0)
378                                  error(SYSTEM, "cannot fork child for persist function");
379 <                        pfdetach();             /* parent exits */
379 >                        pfdetach();             /* parent will run then exit */
380                  }
381          }
382   runagain:
383 <        if (persist)
383 >        if (persist) {
384                  if (outfile == NULL)                    /* if out to stdout */
385                          dupheader();                    /* send header */
386                  else                                    /* if out to file */
387                          duped1 = dup(fileno(stdout));   /* hang onto pipe */
388 +        }
389   #endif
390                                          /* batch render picture(s) */
391          rpict(seqstart, outfile, zfile, recover);
# Line 342 | Line 411 | runagain:
411                  goto runagain;
412          }
413   #endif
414 +
415 +
416 +        ray_done_pmap();           /* PMAP: free photon maps */
417 +        
418          quit(0);
419  
420   badopt:
421          sprintf(errmsg, "command line error at '%s'", argv[i]);
422          error(USER, errmsg);
423 +        return 1; /* pro forma return */
424  
425   #undef  check
426 < #undef  bool
426 > #undef  check_bool
427   }
428  
429  
430   void
431 < wputs(s)                                /* warning output function */
432 < char    *s;
431 > wputs(                          /* warning output function */
432 >        const char      *s
433 > )
434   {
435          int  lasterrno = errno;
436          eputs(s);
# Line 364 | Line 439 | char   *s;
439  
440  
441   void
442 < eputs(s)                                /* put string to stderr */
443 < register char  *s;
442 > eputs(                          /* put string to stderr */
443 >        const char  *s
444 > )
445   {
446          static int  midline = 0;
447  
# Line 383 | Line 459 | register char  *s;
459   }
460  
461  
462 < void
463 < onsig(signo)                            /* fatal signal */
464 < int  signo;
462 > static void
463 > onsig(                          /* fatal signal */
464 >        int  signo
465 > )
466   {
467          static int  gotsig = 0;
468  
469          if (gotsig++)                   /* two signals and we're gone! */
470                  _exit(signo);
471  
472 + #ifdef SIGALRM /* XXX how critical is this? */
473          alarm(15);                      /* allow 15 seconds to clean up */
474          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
475 + #endif
476          eputs("signal - ");
477          eputs(sigerr[signo]);
478          eputs("\n");
# Line 401 | Line 480 | int  signo;
480   }
481  
482  
483 < void
484 < sigdie(signo, msg)                      /* set fatal signal */
485 < int  signo;
486 < char  *msg;
483 > static void
484 > sigdie(                 /* set fatal signal */
485 >        int  signo,
486 >        char  *msg
487 > )
488   {
489          if (signal(signo, onsig) == SIG_IGN)
490                  signal(signo, SIG_IGN);
# Line 412 | Line 492 | char  *msg;
492   }
493  
494  
495 < void
496 < printdefaults()                 /* print default values to stdout */
495 > static void
496 > printdefaults(void)                     /* print default values to stdout */
497   {
418        register char  *cp;
419
498          printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
499                          ourview.type==VT_PER ? "perspective" :
500                          ourview.type==VT_PAR ? "parallel" :
501                          ourview.type==VT_HEM ? "hemispherical" :
502                          ourview.type==VT_ANG ? "angular" :
503                          ourview.type==VT_CYL ? "cylindrical" :
504 +                        ourview.type==VT_PLS ? "planisphere" :
505                          "unknown");
506          printf("-vp %f %f %f\t# view point\n",
507                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
# Line 438 | Line 517 | printdefaults()                        /* print default values to stdout */
517          printf("-vl %f\t\t\t# view lift\n", ourview.voff);
518          printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
519          printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
520 +        if (out_prims == stdprims)
521 +                printf("-pRGB\t\t\t\t# standard RGB color output\n");
522 +        else if (out_prims == xyzprims)
523 +                printf("-pXYZ\t\t\t\t# CIE XYZ color output\n");
524 +        else if (out_prims != NULL)
525 +                printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n",
526 +                                out_prims[RED][0], out_prims[RED][1],
527 +                                out_prims[GRN][0], out_prims[GRN][1],
528 +                                out_prims[BLU][0], out_prims[BLU][1],
529 +                                out_prims[WHT][0], out_prims[WHT][1]);
530          printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect);
531          printf("-pj %f\t\t\t# pixel jitter\n", dstrpix);
532          printf("-pm %f\t\t\t# pixel motion\n", mblur);
533 +        printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur);
534          printf("-ps %-9d\t\t\t# pixel sample\n", psample);
535          printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
536          printf("-t  %-9d\t\t\t# time between reports\n", ralrm);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines