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.12 by greg, Wed Apr 5 06:22:57 2006 UTC vs.
Revision 2.36 by greg, Fri Nov 15 20:47:42 2024 UTC

# Line 18 | Line 18 | static const char      RCSid[] = "$Id$";
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 30 | static const char      RCSid[] = "$Id$";
30   char  *progname;                        /* argv[0] */
31   char  *octname;                         /* octree name */
32   char  *sigerr[NSIG];                    /* signal error messages */
32 char  *shm_boundary = NULL;             /* boundary of shared memory */
33   char  *errfile = NULL;                  /* error output file */
34 <
34 > #ifdef SSKIPOPT
35 > int  *ssndx_map = NULL;                 /* loaded source index map */
36 > float  *scorr_map = NULL;               /* loaded source correction map */
37 > #endif
38   extern time_t  time();
39   extern time_t  tstart;                  /* start time */
40  
# Line 51 | Line 54 | extern double  mblur;                  /* motion blur parameter */
54  
55   extern double  dblur;                   /* depth-of-field blur parameter */
56  
57 + RGBPRIMP  out_prims = stdprims;         /* output color primitives */
58 + static RGBPRIMS  our_prims;             /* private output color primitives */
59 +
60   static void onsig(int signo);
61   static void sigdie(int  signo, char  *msg);
62   static void printdefaults(void);
63 +                                        /* rpict additional features */
64 + #ifdef PERSIST
65 + #define RPICT_FEATURES  "Persist\nParallelPersist\n" \
66 +                "ParticipatingMedia=Mist\n" \
67 +                "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
68 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
69 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
70 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
71 +                "AdaptiveShadowTesting\nOutputs=v,l\n" \
72 +                "OutputCS=RGB,XYZ,prims\n"
73 + #else
74 + #define RPICT_FEATURES  "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
75 +                "ParticipatingMedia=Mist\n" \
76 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
77 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
78 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
79 +                "AdaptiveShadowTesting\nOutputs=v,l\n" \
80 +                "OutputCS=RGB,XYZ,prims\n"
81 + #endif
82  
83  
84   int
# Line 62 | Line 87 | main(int  argc, char  *argv[])
87   #define  check(ol,al)           if (argv[i][ol] || \
88                                  badarg(argc-i-1,argv+i+1,al)) \
89                                  goto badopt
90 < #define  bool(olen,var)         switch (argv[i][olen]) { \
90 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
91                                  case '\0': var = !var; break; \
92                                  case 'y': case 'Y': case 't': case 'T': \
93                                  case '+': case '1': var = 1; break; \
# Line 73 | Line 98 | main(int  argc, char  *argv[])
98          char  *recover = NULL;
99          char  *outfile = NULL;
100          char  *zfile = NULL;
101 + #ifdef SSKIPOPT
102 +        char  *sskipspec = NULL;
103 +        char  *scorrfile = NULL;
104 + #endif
105          int  loadflags = ~IO_FILES;
106          int  seqstart = 0;
107          int  persist = 0;
108 <        int  duped1;
108 >        int  duped1 = -1;
109          int  rval;
110          int  i;
111                                          /* record start time */
112          tstart = time((time_t *)NULL);
113                                          /* global program name */
114          progname = argv[0] = fixargv0(argv[0]);
115 +                                        /* feature check only? */
116 +        strcat(RFeatureList, RPICT_FEATURES);
117 +        if (argc > 1 && !strcmp(argv[1], "-features"))
118 +                return feature_status(argc-2, argv+2);
119                                          /* option city */
120          for (i = 1; i < argc; i++) {
121                                                  /* expand arguments */
# Line 158 | Line 191 | main(int  argc, char  *argv[])
191                                  check(3,"f");
192                                  dblur = atof(argv[++i]);
193                                  break;
194 +                        case 'R':                               /* standard RGB output */
195 +                                if (strcmp(argv[i]+2, "RGB"))
196 +                                        goto badopt;
197 +                                out_prims = stdprims;
198 +                                break;
199 +                        case 'X':                               /* XYZ output */
200 +                                if (strcmp(argv[i]+2, "XYZ"))
201 +                                        goto badopt;
202 +                                out_prims = xyzprims;
203 +                                break;
204 +                        case 'c': {                             /* chromaticities */
205 +                                int     j;
206 +                                check(3,"ffffffff");
207 +                                rval = 0;
208 +                                for (j = 0; j < 8; j++) {
209 +                                        our_prims[0][j] = atof(argv[++i]);
210 +                                        rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001;
211 +                                }
212 +                                if (rval) {
213 +                                        if (!colorprimsOK(our_prims))
214 +                                                error(USER, "illegal primary chromaticities");
215 +                                        out_prims = our_prims;
216 +                                } else
217 +                                        out_prims = stdprims;
218 +                                } break;
219                          default:
220                                  goto badopt;
221                          }
# Line 190 | Line 248 | main(int  argc, char  *argv[])
248                                  check(2,"s");
249                          recover = argv[++i];
250                          break;
251 <                case 't':                               /* timer */
252 <                        check(2,"i");
253 <                        ralrm = atoi(argv[++i]);
251 > #ifdef SSKIPOPT
252 >                case 'd':
253 >                        switch (argv[i][2]) {
254 >                        case 'S':                       /* direct skip */
255 >                                check(3,"s");
256 >                                sskipspec = argv[++i];
257 >                                break;
258 >                        case 'C':                       /* direct correction */
259 >                                check(3,"s");
260 >                                scorrfile = argv[++i];
261 >                                break;
262 >                        default:
263 >                                goto badopt;
264 >                        }
265                          break;
266 + #endif
267   #ifdef  PERSIST
268                  case 'P':                               /* persist file */
269                          if (argv[i][2] == 'P') {
# Line 206 | Line 276 | main(int  argc, char  *argv[])
276                          persistfile(argv[++i]);
277                          break;
278   #endif
279 +                case 't':                               /* timer */
280 +                        check(2,"i");
281 +                        ralrm = atoi(argv[++i]);
282 +                        break;
283                  case 'w':                               /* warnings */
284                          rval = erract[WARNING].pf != NULL;
285 <                        bool(2,rval);
285 >                        check_bool(2,rval);
286                          if (rval) erract[WARNING].pf = wputs;
287                          else erract[WARNING].pf = NULL;
288                          break;
# Line 220 | Line 294 | main(int  argc, char  *argv[])
294                          goto badopt;
295                  }
296          }
297 +                                        /* set/check spectral sampling */
298 +        if (setspectrsamp(CNDX, WLPART) <= 0)
299 +                error(USER, "unsupported spectral sampling");
300 +
301          err = setview(&ourview);        /* set viewing parameters */
302          if (err != NULL)
303                  error(USER, err);
# Line 285 | Line 363 | main(int  argc, char  *argv[])
363   #endif
364          if (outfile != NULL)
365                  openheader();
288 #ifdef  _WIN32
366          SET_FILE_BINARY(stdout);
367          if (octname == NULL)
368                  SET_FILE_BINARY(stdin);
292 #endif
369          readoct(octname, loadflags, &thescene, NULL);
370          nsceneobjs = nobjects;
371  
# Line 297 | Line 373 | main(int  argc, char  *argv[])
373                  printargs(i, argv, stdout);
374                  printf("SOFTWARE= %s\n", VersionID);
375          }
376 +                  
377 +        ray_init_pmap();     /* PMAP: set up & load photon maps */
378  
379          marksources();                  /* find and mark sources */
380 <
380 > #ifdef SSKIPOPT
381 >        if (sskipspec != NULL) {        /* load source skip maps? */
382 >                if ((seqstart > 0) | (persist > 0))
383 >                        error(USER,
384 >                        "source skip map incompatible with -S/-P/-PP");
385 >                if (srcskip_open(sskipspec, scorrfile) <= 0)
386 >                        quit(1);
387 >                if ((ssndx_map = srcskip_ndxmap()) == NULL)
388 >                        quit(1);
389 >                if (scorrfile != NULL &&
390 >                                (scorr_map = srcskip_corrmap()) == NULL)
391 >                        quit(1);
392 >                srcskip_close();        /* leaves maps loaded */
393 >        }
394 > #endif
395          setambient();                   /* initialize ambient calculation */
396 +        
397 +        fflush(stdout);                 /* in case we're duplicating header */
398  
399   #ifdef  PERSIST
400          if (persist) {
307                fflush(stdout);
401                  if (outfile == NULL) {          /* reconnect stdout */
402                          dup2(duped1, fileno(stdout));
403                          close(duped1);
404                  }
405                  if (persist == PARALLEL) {      /* multiprocessing */
406 <                        preload_objs();         /* preload scene */
314 <                        shm_boundary = (char *)malloc(16);
315 <                        strcpy(shm_boundary, "SHM_BOUNDARY");
406 >                        cow_memshare();         /* preloads scene */
407                          while ((rval=fork()) == 0) {    /* keep on forkin' */
408                                  pflock(1);
409                                  pfhold();
410                                  tstart = time((time_t *)NULL);
411 +                                ambsync();              /* load new values */
412                          }
413                          if (rval < 0)
414                                  error(SYSTEM, "cannot fork child for persist function");
415 <                        pfdetach();             /* parent exits */
415 >                        pfdetach();             /* parent will run then exit */
416                  }
417          }
418   runagain:
# Line 355 | Line 447 | runagain:
447                  goto runagain;
448          }
449   #endif
450 +
451 +
452 +        ray_done_pmap();           /* PMAP: free photon maps */
453 +        
454          quit(0);
455  
456   badopt:
# Line 363 | Line 459 | badopt:
459          return 1; /* pro forma return */
460  
461   #undef  check
462 < #undef  bool
462 > #undef  check_bool
463   }
464  
465 + #ifdef SSKIPOPT
466 + void                            /* source skip parameters for primary */
467 + sskip_ray(RAY *r, double h, double v)
468 + {
469 +        size_t  ssi;
470  
471 +        if (ssndx_map == NULL)
472 +                return;         /* nothing to do */
473 +
474 +                                /* rows counted from the top! */
475 +        ssi = (size_t)((1.-v)*sskip_dim[1])*sskip_dim[0] +
476 +                        (size_t)(h*sskip_dim[0]);
477 +
478 +        if (ssi >= sskip_dim[0]*sskip_dim[1])
479 +                error(CONSISTENCY, "bad index in sskip_ray()");
480 +
481 +        r->rsrc = ssndx_map[ssi];
482 +        if (scorr_map != NULL)
483 +                r->scorr = scorr_map[ssi];
484 + }
485 + #endif
486 +
487   void
488   wputs(                          /* warning output function */
489 <        char    *s
489 >        const char      *s
490   )
491   {
492          int  lasterrno = errno;
493 +        if (erract[WARNING].pf == NULL)
494 +                return;         /* called by calcomp or someone */
495          eputs(s);
496          errno = lasterrno;
497   }
# Line 380 | Line 499 | wputs(                         /* warning output function */
499  
500   void
501   eputs(                          /* put string to stderr */
502 <        register char  *s
502 >        const char  *s
503   )
504   {
505          static int  midline = 0;
# Line 441 | Line 560 | printdefaults(void)                    /* print default values to stdou
560                          ourview.type==VT_HEM ? "hemispherical" :
561                          ourview.type==VT_ANG ? "angular" :
562                          ourview.type==VT_CYL ? "cylindrical" :
563 +                        ourview.type==VT_PLS ? "planisphere" :
564                          "unknown");
565          printf("-vp %f %f %f\t# view point\n",
566                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
# Line 456 | Line 576 | printdefaults(void)                    /* print default values to stdou
576          printf("-vl %f\t\t\t# view lift\n", ourview.voff);
577          printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
578          printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
579 +        if (out_prims == stdprims)
580 +                printf("-pRGB\t\t\t\t# standard RGB color output\n");
581 +        else if (out_prims == xyzprims)
582 +                printf("-pXYZ\t\t\t\t# CIE XYZ color output\n");
583 +        else if (out_prims != NULL)
584 +                printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n",
585 +                                out_prims[RED][0], out_prims[RED][1],
586 +                                out_prims[GRN][0], out_prims[GRN][1],
587 +                                out_prims[BLU][0], out_prims[BLU][1],
588 +                                out_prims[WHT][0], out_prims[WHT][1]);
589          printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect);
590          printf("-pj %f\t\t\t# pixel jitter\n", dstrpix);
591          printf("-pm %f\t\t\t# pixel motion\n", mblur);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines