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.1 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.40 by greg, Thu Jun 5 18:26:46 2025 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  rpmain.c - main for rpict batch rendering program
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10 < #include  "ray.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  "func.h"
17   #include  "source.h"
68
18   #include  "ambient.h"
70
19   #include  "random.h"
72
20   #include  "paths.h"
74
75 #include  <sys/types.h>
76
77 #include  <signal.h>
78
21   #include  "view.h"
22 + #include  "pmapray.h"
23  
81 #include  "paths.h"
24                                          /* persistent processes define */
25   #ifdef  F_SETLKW
26   #define  PERSIST        1               /* normal persist */
# Line 86 | Line 28 | static const char      RCSid[] = "$Id$";
28   #define  PCHILD         3               /* child of normal persist */
29   #endif
30  
89 char  *progname;                        /* argv[0] */
90
31   char  *octname;                         /* octree name */
92
32   char  *sigerr[NSIG];                    /* signal error messages */
94
95 char  *shm_boundary = NULL;             /* boundary of shared memory */
96
33   char  *errfile = NULL;                  /* error output file */
34  
99 extern time_t  time();
35   extern time_t  tstart;                  /* start time */
36  
37   extern int  ralrm;                      /* seconds between reports */
# Line 113 | Line 48 | extern double  dstrpix;                        /* square pixel distribution
48  
49   extern double  mblur;                   /* motion blur parameter */
50  
51 < void    onsig();
117 < void    sigdie();
118 < void    printdefaults();
51 > extern double  dblur;                   /* depth-of-field blur parameter */
52  
53 + RGBPRIMP  out_prims = stdprims;         /* output color primitives */
54 + static RGBPRIMS  our_prims;             /* private output color primitives */
55  
56 + static void onsig(int signo);
57 + static void sigdie(int  signo, char  *msg);
58 + static void printdefaults(void);
59 +                                        /* rpict additional features */
60 + #ifdef PERSIST
61 + #define RPICT_FEATURES  "Persist\nParallelPersist\n" \
62 +                "ParticipatingMedia=Mist\n" \
63 +                "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
64 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
65 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
66 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
67 +                "AdaptiveShadowTesting\nOutputs=v,l\n" \
68 +                "OutputCS=RGB,XYZ,prims\n"
69 + #else
70 + #define RPICT_FEATURES  "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
71 +                "ParticipatingMedia=Mist\n" \
72 +                "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
73 +                "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
74 +                "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
75 +                "AdaptiveShadowTesting\nOutputs=v,l\n" \
76 +                "OutputCS=RGB,XYZ,prims\n"
77 + #endif
78 +
79 +
80   int
81 < main(argc, argv)
123 < int  argc;
124 < 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 140 | 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 +                                        /* initialize calcomp routines */
112 +        initfunc();
113                                          /* option city */
114          for (i = 1; i < argc; i++) {
115                                                  /* expand arguments */
# Line 218 | Line 181 | char  *argv[];
181                                  check(3,"f");
182                                  mblur = atof(argv[++i]);
183                                  break;
184 +                        case 'd':                               /* aperture */
185 +                                check(3,"f");
186 +                                dblur = atof(argv[++i]);
187 +                                break;
188 +                        case 'R':                               /* standard RGB output */
189 +                                if (strcmp(argv[i]+2, "RGB"))
190 +                                        goto badopt;
191 +                                out_prims = stdprims;
192 +                                break;
193 +                        case 'X':                               /* XYZ output */
194 +                                if (strcmp(argv[i]+2, "XYZ"))
195 +                                        goto badopt;
196 +                                out_prims = xyzprims;
197 +                                break;
198 +                        case 'c': {                             /* chromaticities */
199 +                                int     j;
200 +                                check(3,"ffffffff");
201 +                                rval = 0;
202 +                                for (j = 0; j < 8; j++) {
203 +                                        our_prims[0][j] = atof(argv[++i]);
204 +                                        rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001;
205 +                                }
206 +                                if (rval) {
207 +                                        if (!colorprimsOK(our_prims))
208 +                                                error(USER, "illegal primary chromaticities");
209 +                                        out_prims = our_prims;
210 +                                } else
211 +                                        out_prims = stdprims;
212 +                                } break;
213                          default:
214                                  goto badopt;
215                          }
# Line 250 | Line 242 | char  *argv[];
242                                  check(2,"s");
243                          recover = argv[++i];
244                          break;
253                case 't':                               /* timer */
254                        check(2,"i");
255                        ralrm = atoi(argv[++i]);
256                        break;
245   #ifdef  PERSIST
246                  case 'P':                               /* persist file */
247                          if (argv[i][2] == 'P') {
# Line 266 | Line 254 | char  *argv[];
254                          persistfile(argv[++i]);
255                          break;
256   #endif
257 +                case 't':                               /* timer */
258 +                        check(2,"i");
259 +                        ralrm = atoi(argv[++i]);
260 +                        break;
261                  case 'w':                               /* warnings */
262                          rval = erract[WARNING].pf != NULL;
263 <                        bool(2,rval);
263 >                        check_bool(2,rval);
264                          if (rval) erract[WARNING].pf = wputs;
265                          else erract[WARNING].pf = NULL;
266                          break;
# Line 280 | Line 272 | char  *argv[];
272                          goto badopt;
273                  }
274          }
275 +                                        /* set/check spectral sampling */
276 +        if (setspectrsamp(CNDX, WLPART) <= 0)
277 +                error(USER, "unsupported spectral sampling");
278 +
279          err = setview(&ourview);        /* set viewing parameters */
280          if (err != NULL)
281                  error(USER, err);
282                                          /* initialize object types */
283          initotypes();
284                                          /* initialize urand */
285 <        initurand(2048);
285 >        if (rand_samp) {
286 >                srandom((long)time(0));
287 >                initurand(0);
288 >        } else {
289 >                srandom(0L);
290 >                initurand(2048);
291 >        }
292                                          /* set up signal handling */
293          sigdie(SIGINT, "Interrupt");
294 + #ifdef SIGHUP
295          sigdie(SIGHUP, "Hangup");
296 + #endif
297          sigdie(SIGTERM, "Terminate");
298 + #ifdef SIGPIPE
299          sigdie(SIGPIPE, "Broken pipe");
300 + #endif
301 + #ifdef SIGALRM
302          sigdie(SIGALRM, "Alarm clock");
303 + #endif
304   #ifdef  SIGXCPU
305          sigdie(SIGXCPU, "CPU limit exceeded");
306          sigdie(SIGXFSZ, "File size exceeded");
# Line 333 | Line 341 | char  *argv[];
341   #endif
342          if (outfile != NULL)
343                  openheader();
344 < #ifdef  MSDOS
337 <        setmode(fileno(stdout), O_BINARY);
344 >        SET_FILE_BINARY(stdout);
345          if (octname == NULL)
346 <                setmode(fileno(stdin), O_BINARY);
340 < #endif
346 >                SET_FILE_BINARY(stdin);
347          readoct(octname, loadflags, &thescene, NULL);
348          nsceneobjs = nobjects;
349  
350          if (loadflags & IO_INFO) {      /* print header */
351                  printargs(i, argv, stdout);
352                  printf("SOFTWARE= %s\n", VersionID);
347                fputnow(stdout);
353          }
354 +                  
355 +        ray_init_pmap();     /* PMAP: set up & load photon maps */
356  
357          marksources();                  /* find and mark sources */
351
358          setambient();                   /* initialize ambient calculation */
359 +        
360 +        fflush(stdout);                 /* in case we're duplicating header */
361  
362   #ifdef  PERSIST
363          if (persist) {
356                fflush(stdout);
364                  if (outfile == NULL) {          /* reconnect stdout */
365                          dup2(duped1, fileno(stdout));
366                          close(duped1);
367                  }
368                  if (persist == PARALLEL) {      /* multiprocessing */
369 <                        preload_objs();         /* preload scene */
363 <                        shm_boundary = (char *)malloc(16);
364 <                        strcpy(shm_boundary, "SHM_BOUNDARY");
369 >                        cow_memshare();         /* preloads scene */
370                          while ((rval=fork()) == 0) {    /* keep on forkin' */
371                                  pflock(1);
372                                  pfhold();
373                                  tstart = time((time_t *)NULL);
374 +                                ambsync();              /* load new values */
375                          }
376                          if (rval < 0)
377                                  error(SYSTEM, "cannot fork child for persist function");
378 <                        pfdetach();             /* parent exits */
378 >                        pfdetach();             /* parent will run then exit */
379                  }
380          }
381   runagain:
382 <        if (persist)
382 >        if (persist) {
383                  if (outfile == NULL)                    /* if out to stdout */
384                          dupheader();                    /* send header */
385                  else                                    /* if out to file */
386                          duped1 = dup(fileno(stdout));   /* hang onto pipe */
387 +        }
388   #endif
389                                          /* batch render picture(s) */
390          rpict(seqstart, outfile, zfile, recover);
# Line 403 | Line 410 | runagain:
410                  goto runagain;
411          }
412   #endif
413 +
414 +
415 +        ray_done_pmap();           /* PMAP: free photon maps */
416 +        
417          quit(0);
418  
419   badopt:
420          sprintf(errmsg, "command line error at '%s'", argv[i]);
421          error(USER, errmsg);
422 +        return 1; /* pro forma return */
423  
424   #undef  check
425 < #undef  bool
425 > #undef  check_bool
426   }
427  
428  
429   void
430 < wputs(s)                                /* warning output function */
431 < char    *s;
430 > wputs(                          /* warning output function */
431 >        const char      *s
432 > )
433   {
434          int  lasterrno = errno;
435 +        if (erract[WARNING].pf == NULL)
436 +                return;         /* called by calcomp or someone */
437          eputs(s);
438          errno = lasterrno;
439   }
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 444 | 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  
470          if (gotsig++)                   /* two signals and we're gone! */
471                  _exit(signo);
472  
473 + #ifdef SIGALRM /* XXX how critical is this? */
474          alarm(15);                      /* allow 15 seconds to clean up */
475          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
476 + #endif
477          eputs("signal - ");
478          eputs(sigerr[signo]);
479          eputs("\n");
# Line 462 | 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 473 | 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   {
479        register char  *cp;
480
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 499 | 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