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.37 by greg, Sat Jan 18 03:49:00 2025 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
37 char  *shm_boundary = NULL;             /* boundary of shared memory */
38
33   char  *errfile = NULL;                  /* error output file */
34  
35   extern time_t  time();
# Line 55 | Line 49 | extern double  dstrpix;                        /* square pixel distribution
49  
50   extern double  mblur;                   /* motion blur parameter */
51  
52 < void    onsig();
59 < void    sigdie();
60 < void    printdefaults();
52 > extern double  dblur;                   /* depth-of-field blur parameter */
53  
54 + RGBPRIMP  out_prims = stdprims;         /* output color primitives */
55 + static RGBPRIMS  our_prims;             /* private output color primitives */
56  
57 + static void onsig(int signo);
58 + static void sigdie(int  signo, char  *msg);
59 + static void printdefaults(void);
60 +                                        /* rpict additional features */
61 + #ifdef PERSIST
62 + #define RPICT_FEATURES  "Persist\nParallelPersist\n" \
63 +                "ParticipatingMedia=Mist\n" \
64 +                "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
65 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
66 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
67 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
68 +                "AdaptiveShadowTesting\nOutputs=v,l\n" \
69 +                "OutputCS=RGB,XYZ,prims\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 +                "OutputCS=RGB,XYZ,prims\n"
78 + #endif
79 +
80 +
81   int
82 < main(argc, argv)
65 < int  argc;
66 < char  *argv[];
82 > main(int  argc, char  *argv[])
83   {
84   #define  check(ol,al)           if (argv[i][ol] || \
85                                  badarg(argc-i-1,argv+i+1,al)) \
86                                  goto badopt
87 < #define  bool(olen,var)         switch (argv[i][olen]) { \
87 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
88                                  case '\0': var = !var; break; \
89                                  case 'y': case 'Y': case 't': case 'T': \
90                                  case '+': case '1': var = 1; break; \
# Line 82 | Line 98 | char  *argv[];
98          int  loadflags = ~IO_FILES;
99          int  seqstart = 0;
100          int  persist = 0;
101 <        int  duped1;
101 >        int  duped1 = -1;
102          int  rval;
103          int  i;
104                                          /* record start time */
105          tstart = time((time_t *)NULL);
106                                          /* global program name */
107          progname = argv[0] = fixargv0(argv[0]);
108 +                                        /* feature check only? */
109 +        strcat(RFeatureList, RPICT_FEATURES);
110 +        if (argc > 1 && !strcmp(argv[1], "-features"))
111 +                return feature_status(argc-2, argv+2);
112                                          /* option city */
113          for (i = 1; i < argc; i++) {
114                                                  /* expand arguments */
# Line 160 | Line 180 | char  *argv[];
180                                  check(3,"f");
181                                  mblur = atof(argv[++i]);
182                                  break;
183 +                        case 'd':                               /* aperture */
184 +                                check(3,"f");
185 +                                dblur = atof(argv[++i]);
186 +                                break;
187 +                        case 'R':                               /* standard RGB output */
188 +                                if (strcmp(argv[i]+2, "RGB"))
189 +                                        goto badopt;
190 +                                out_prims = stdprims;
191 +                                break;
192 +                        case 'X':                               /* XYZ output */
193 +                                if (strcmp(argv[i]+2, "XYZ"))
194 +                                        goto badopt;
195 +                                out_prims = xyzprims;
196 +                                break;
197 +                        case 'c': {                             /* chromaticities */
198 +                                int     j;
199 +                                check(3,"ffffffff");
200 +                                rval = 0;
201 +                                for (j = 0; j < 8; j++) {
202 +                                        our_prims[0][j] = atof(argv[++i]);
203 +                                        rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001;
204 +                                }
205 +                                if (rval) {
206 +                                        if (!colorprimsOK(our_prims))
207 +                                                error(USER, "illegal primary chromaticities");
208 +                                        out_prims = our_prims;
209 +                                } else
210 +                                        out_prims = stdprims;
211 +                                } break;
212                          default:
213                                  goto badopt;
214                          }
# Line 192 | Line 241 | char  *argv[];
241                                  check(2,"s");
242                          recover = argv[++i];
243                          break;
195                case 't':                               /* timer */
196                        check(2,"i");
197                        ralrm = atoi(argv[++i]);
198                        break;
244   #ifdef  PERSIST
245                  case 'P':                               /* persist file */
246                          if (argv[i][2] == 'P') {
# Line 208 | Line 253 | char  *argv[];
253                          persistfile(argv[++i]);
254                          break;
255   #endif
256 +                case 't':                               /* timer */
257 +                        check(2,"i");
258 +                        ralrm = atoi(argv[++i]);
259 +                        break;
260                  case 'w':                               /* warnings */
261                          rval = erract[WARNING].pf != NULL;
262 <                        bool(2,rval);
262 >                        check_bool(2,rval);
263                          if (rval) erract[WARNING].pf = wputs;
264                          else erract[WARNING].pf = NULL;
265                          break;
# Line 222 | Line 271 | char  *argv[];
271                          goto badopt;
272                  }
273          }
274 +                                        /* set/check spectral sampling */
275 +        if (setspectrsamp(CNDX, WLPART) <= 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 */
298
357          setambient();                   /* initialize ambient calculation */
358 +        
359 +        fflush(stdout);                 /* in case we're duplicating header */
360  
361   #ifdef  PERSIST
362          if (persist) {
303                fflush(stdout);
363                  if (outfile == NULL) {          /* reconnect stdout */
364                          dup2(duped1, fileno(stdout));
365                          close(duped1);
366                  }
367                  if (persist == PARALLEL) {      /* multiprocessing */
368 <                        preload_objs();         /* preload scene */
310 <                        shm_boundary = (char *)malloc(16);
311 <                        strcpy(shm_boundary, "SHM_BOUNDARY");
368 >                        cow_memshare();         /* preloads scene */
369                          while ((rval=fork()) == 0) {    /* keep on forkin' */
370                                  pflock(1);
371                                  pfhold();
372                                  tstart = time((time_t *)NULL);
373 +                                ambsync();              /* load new values */
374                          }
375                          if (rval < 0)
376                                  error(SYSTEM, "cannot fork child for persist function");
377 <                        pfdetach();             /* parent exits */
377 >                        pfdetach();             /* parent will run then exit */
378                  }
379          }
380   runagain:
381 <        if (persist)
381 >        if (persist) {
382                  if (outfile == NULL)                    /* if out to stdout */
383                          dupheader();                    /* send header */
384                  else                                    /* if out to file */
385                          duped1 = dup(fileno(stdout));   /* hang onto pipe */
386 +        }
387   #endif
388                                          /* batch render picture(s) */
389          rpict(seqstart, outfile, zfile, recover);
# Line 350 | Line 409 | runagain:
409                  goto runagain;
410          }
411   #endif
412 +
413 +
414 +        ray_done_pmap();           /* PMAP: free photon maps */
415 +        
416          quit(0);
417  
418   badopt:
419          sprintf(errmsg, "command line error at '%s'", argv[i]);
420          error(USER, errmsg);
421 +        return 1; /* pro forma return */
422  
423   #undef  check
424 < #undef  bool
424 > #undef  check_bool
425   }
426  
427  
428   void
429 < wputs(s)                                /* warning output function */
430 < char    *s;
429 > wputs(                          /* warning output function */
430 >        const char      *s
431 > )
432   {
433          int  lasterrno = errno;
434 +        if (erract[WARNING].pf == NULL)
435 +                return;         /* called by calcomp or someone */
436          eputs(s);
437          errno = lasterrno;
438   }
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 391 | 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  
# Line 411 | 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 422 | 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   {
428        register char  *cp;
429
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 448 | 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