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.5 by greg, Thu Jul 3 18:03:58 2003 UTC vs.
Revision 2.30 by greg, Wed Jan 17 01:31:08 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 #ifdef _WIN32
13  #include <process.h> /* getpid */
14 #endif
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 29 | Line 28 | static const char      RCSid[] = "$Id$";
28   #endif
29  
30   char  *progname;                        /* argv[0] */
32
31   char  *octname;                         /* octree name */
34
32   char  *sigerr[NSIG];                    /* signal error messages */
36
33   char  *shm_boundary = NULL;             /* boundary of shared memory */
38
34   char  *errfile = NULL;                  /* error output file */
35  
36   extern time_t  time();
# Line 55 | Line 50 | extern double  dstrpix;                        /* square pixel distribution
50  
51   extern double  mblur;                   /* motion blur parameter */
52  
53 < void    onsig();
59 < void    sigdie();
60 < 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)
65 < int  argc;
66 < 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 82 | 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 160 | 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 210 | 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 222 | Line 270 | char  *argv[];
270                          goto badopt;
271                  }
272          }
273 +                                        /* set/check spectral sampling */
274 +        rval = setspectrsamp(CNDX, WLPART);
275 +        if (rval < 0)
276 +                error(USER, "unsupported spectral sampling");
277 +
278          err = setview(&ourview);        /* set viewing parameters */
279          if (err != NULL)
280                  error(USER, err);
281                                          /* initialize object types */
282          initotypes();
283                                          /* initialize urand */
284 <        initurand(2048);
284 >        if (rand_samp) {
285 >                srandom((long)time(0));
286 >                initurand(0);
287 >        } else {
288 >                srandom(0L);
289 >                initurand(2048);
290 >        }
291                                          /* set up signal handling */
292          sigdie(SIGINT, "Interrupt");
293   #ifdef SIGHUP
# Line 281 | Line 340 | char  *argv[];
340   #endif
341          if (outfile != NULL)
342                  openheader();
284 #ifdef  _WIN32
343          SET_FILE_BINARY(stdout);
344          if (octname == NULL)
345                  SET_FILE_BINARY(stdin);
288 #endif
346          readoct(octname, loadflags, &thescene, NULL);
347          nsceneobjs = nobjects;
348  
# Line 293 | Line 350 | char  *argv[];
350                  printargs(i, argv, stdout);
351                  printf("SOFTWARE= %s\n", VersionID);
352          }
353 +                  
354 +        ray_init_pmap();     /* PMAP: set up & load photon maps */
355  
356          marksources();                  /* find and mark sources */
357  
358          setambient();                   /* initialize ambient calculation */
359 +        
360 +        fflush(stdout);                 /* in case we're duplicating header */
361  
362   #ifdef  PERSIST
363          if (persist) {
303                fflush(stdout);
364                  if (outfile == NULL) {          /* reconnect stdout */
365                          dup2(duped1, fileno(stdout));
366                          close(duped1);
# Line 313 | Line 373 | char  *argv[];
373                                  pflock(1);
374                                  pfhold();
375                                  tstart = time((time_t *)NULL);
376 +                                ambsync();              /* load new values */
377                          }
378                          if (rval < 0)
379                                  error(SYSTEM, "cannot fork child for persist function");
380 <                        pfdetach();             /* parent exits */
380 >                        pfdetach();             /* parent will run then exit */
381                  }
382          }
383   runagain:
384 <        if (persist)
384 >        if (persist) {
385                  if (outfile == NULL)                    /* if out to stdout */
386                          dupheader();                    /* send header */
387                  else                                    /* if out to file */
388                          duped1 = dup(fileno(stdout));   /* hang onto pipe */
389 +        }
390   #endif
391                                          /* batch render picture(s) */
392          rpict(seqstart, outfile, zfile, recover);
# Line 350 | Line 412 | runagain:
412                  goto runagain;
413          }
414   #endif
415 +
416 +
417 +        ray_done_pmap();           /* PMAP: free photon maps */
418 +        
419          quit(0);
420  
421   badopt:
422          sprintf(errmsg, "command line error at '%s'", argv[i]);
423          error(USER, errmsg);
424 +        return 1; /* pro forma return */
425  
426   #undef  check
427 < #undef  bool
427 > #undef  check_bool
428   }
429  
430  
431   void
432 < wputs(s)                                /* warning output function */
433 < char    *s;
432 > wputs(                          /* warning output function */
433 >        const char      *s
434 > )
435   {
436          int  lasterrno = errno;
437          eputs(s);
# Line 372 | Line 440 | char   *s;
440  
441  
442   void
443 < eputs(s)                                /* put string to stderr */
444 < register char  *s;
443 > eputs(                          /* put string to stderr */
444 >        const char  *s
445 > )
446   {
447          static int  midline = 0;
448  
# Line 391 | Line 460 | register char  *s;
460   }
461  
462  
463 < void
464 < onsig(signo)                            /* fatal signal */
465 < int  signo;
463 > static void
464 > onsig(                          /* fatal signal */
465 >        int  signo
466 > )
467   {
468          static int  gotsig = 0;
469  
# Line 411 | Line 481 | int  signo;
481   }
482  
483  
484 < void
485 < sigdie(signo, msg)                      /* set fatal signal */
486 < int  signo;
487 < char  *msg;
484 > static void
485 > sigdie(                 /* set fatal signal */
486 >        int  signo,
487 >        char  *msg
488 > )
489   {
490          if (signal(signo, onsig) == SIG_IGN)
491                  signal(signo, SIG_IGN);
# Line 422 | Line 493 | char  *msg;
493   }
494  
495  
496 < void
497 < printdefaults()                 /* print default values to stdout */
496 > static void
497 > printdefaults(void)                     /* print default values to stdout */
498   {
428        register char  *cp;
429
499          printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
500                          ourview.type==VT_PER ? "perspective" :
501                          ourview.type==VT_PAR ? "parallel" :
502                          ourview.type==VT_HEM ? "hemispherical" :
503                          ourview.type==VT_ANG ? "angular" :
504                          ourview.type==VT_CYL ? "cylindrical" :
505 +                        ourview.type==VT_PLS ? "planisphere" :
506                          "unknown");
507          printf("-vp %f %f %f\t# view point\n",
508                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
# Line 448 | Line 518 | printdefaults()                        /* print default values to stdout */
518          printf("-vl %f\t\t\t# view lift\n", ourview.voff);
519          printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
520          printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
521 +        if (out_prims == stdprims)
522 +                printf("-pRGB\t\t\t\t# standard RGB color output\n");
523 +        else if (out_prims == xyzprims)
524 +                printf("-pXYZ\t\t\t\t# CIE XYZ color output\n");
525 +        else if (out_prims != NULL)
526 +                printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n",
527 +                                out_prims[RED][0], out_prims[RED][1],
528 +                                out_prims[GRN][0], out_prims[GRN][1],
529 +                                out_prims[BLU][0], out_prims[BLU][1],
530 +                                out_prims[WHT][0], out_prims[WHT][1]);
531          printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect);
532          printf("-pj %f\t\t\t# pixel jitter\n", dstrpix);
533          printf("-pm %f\t\t\t# pixel motion\n", mblur);
534 +        printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur);
535          printf("-ps %-9d\t\t\t# pixel sample\n", psample);
536          printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
537          printf("-t  %-9d\t\t\t# time between reports\n", ralrm);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines