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

Comparing ray/src/rt/rtmain.c (file contents):
Revision 2.9 by schorsch, Tue Mar 30 16:13:01 2004 UTC vs.
Revision 2.61 by greg, Fri Jun 20 16:34:23 2025 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7  
8   #include "copyright.h"
9  
10 #include  <sys/types.h>
10   #include  <signal.h>
11  
12   #include  "platform.h"
13   #include  "rtprocess.h" /* getpid() */
14   #include  "resolu.h"
15   #include  "ray.h"
16 + #include  "func.h"
17   #include  "source.h"
18   #include  "ambient.h"
19   #include  "random.h"
20 < #include  "paths.h"
21 <
20 > #include  "pmapray.h"
21                                          /* persistent processes define */
22   #ifdef  F_SETLKW
23   #define  PERSIST        1               /* normal persist */
# Line 26 | Line 25 | static const char      RCSid[] = "$Id$";
25   #define  PCHILD         3               /* child of normal persist */
26   #endif
27  
29 char  *progname;                        /* argv[0] */
30 char  *octname;                         /* octree name */
28   char  *sigerr[NSIG];                    /* signal error messages */
32 char  *shm_boundary = NULL;             /* boundary of shared memory */
29   char  *errfile = NULL;                  /* error output file */
30  
31 < extern char  *formstr();                /* string from format */
36 < extern int  inform;                     /* input format */
37 < extern int  outform;                    /* output format */
38 < extern char  *outvals;                  /* output values */
31 > int  nproc = 1;                         /* number of processes */
32  
33 < extern int  hresolu;                    /* horizontal resolution */
41 < extern int  vresolu;                    /* vertical resolution */
33 > extern int  setrtoutput(void);          /* set output values */
34  
35 < extern int  imm_irrad;                  /* compute immediate irradiance? */
36 < extern int  lim_dist;                   /* limit distance? */
35 > int  inform = 'a';                      /* input format */
36 > int  outform = 'a';                     /* output format */
37 > char  *outvals = "v";                   /* output specification */
38  
39 < extern char  *tralist[];                /* list of modifers to trace (or no) */
40 < extern int  traincl;                    /* include == 1, exclude == 0 */
39 > int  hresolu = 0;                       /* horizontal (scan) size */
40 > int  vresolu = 0;                       /* vertical resolution */
41  
42 + extern int  castonly;                   /* only doing ray-casting? */
43 +
44 + int  imm_irrad = 0;                     /* compute immediate irradiance? */
45 + int  lim_dist = 0;                      /* limit distance? */
46 +
47 + #ifndef MAXMODLIST
48 + #define MAXMODLIST      1024            /* maximum modifiers we'll track */
49 + #endif
50 +
51 + extern void  (*addobjnotify[])();       /* object notification calls */
52 + extern void  tranotify(OBJECT obj);
53 +
54 + char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
55 + int  traincl = -1;                      /* include == 1, exclude == 0 */
56 +
57 + double  (*sens_curve)(const SCOLOR scol) = NULL;        /* spectral conversion for 1-channel */
58 + double  out_scalefactor = 1;            /* output calibration scale factor */
59 + RGBPRIMP  out_prims = stdprims;         /* output color primitives (NULL if spectral) */
60 + static RGBPRIMS  our_prims;             /* private output color primitives */
61 +
62 + static int  loadflags = ~IO_FILES;      /* what to load from octree */
63 +
64   static void onsig(int  signo);
65   static void sigdie(int  signo, char  *msg);
66   static void printdefaults(void);
67  
68 + #ifdef PERSIST
69 + #define RTRACE_FEATURES "Persist\nParallelPersist\nMultiprocessing\n" \
70 +                        "IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \
71 +                        "ParticipatingMedia=Mist\n" \
72 +                        "HessianAmbientCache\nAmbientAveraging\n" \
73 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
74 +                        "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \
75 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" \
76 +                        "OutputCS=RGB,XYZ,Y,S,M,prims,spec\n"
77 + #else
78 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
79 +                        "ParticipatingMedia=Mist\n" \
80 +                        "HessianAmbientCache\nAmbientAveraging\n" \
81 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
82 +                        "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \
83 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" \
84 +                        "OutputCS=RGB,XYZ,Y,S,M,prims,spec\n"
85 + #endif
86  
87 +
88   int
89   main(int  argc, char  *argv[])
90   {
91   #define  check(ol,al)           if (argv[i][ol] || \
92                                  badarg(argc-i-1,argv+i+1,al)) \
93                                  goto badopt
94 < #define  bool(olen,var)         switch (argv[i][olen]) { \
94 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
95                                  case '\0': var = !var; break; \
96                                  case 'y': case 'Y': case 't': case 'T': \
97                                  case '+': case '1': var = 1; break; \
98                                  case 'n': case 'N': case 'f': case 'F': \
99                                  case '-': case '0': var = 0; break; \
100                                  default: goto badopt; }
101 <        int  loadflags = ~IO_FILES;
101 >        extern char  *octname;
102          int  persist = 0;
103 <        char  **tralp;
104 <        int  duped1;
103 >        char  *octnm = NULL;
104 >        char  **tralp = NULL;
105 >        int  duped1 = -1;
106          int  rval;
107          int  i;
108                                          /* global program name */
109          progname = argv[0] = fixargv0(argv[0]);
110 +                                        /* feature check only? */
111 +        strcat(RFeatureList, RTRACE_FEATURES);
112 +        if (argc > 1 && !strcmp(argv[1], "-features"))
113 +                return feature_status(argc-2, argv+2);
114 +                                        /* initialize calcomp routines */
115 +        initfunc();
116 +                                        /* add trace notify function */
117 +        for (i = 0; addobjnotify[i] != NULL; i++)
118 +                ;
119 +        addobjnotify[i] = tranotify;
120                                          /* option city */
121          for (i = 1; i < argc; i++) {
122                                                  /* expand arguments */
# Line 98 | Line 143 | main(int  argc, char  *argv[])
143                          continue;
144                  }
145                  switch (argv[i][1]) {
146 +                case 'n':                               /* number of cores */
147 +                        check(2,"i");
148 +                        nproc = atoi(argv[++i]);
149 +                        if (nproc <= 0)
150 +                                error(USER, "bad number of processes");
151 +                        break;
152                  case 'x':                               /* x resolution */
153                          check(2,"i");
154                          hresolu = atoi(argv[++i]);
# Line 106 | Line 157 | main(int  argc, char  *argv[])
157                          check(2,"i");
158                          vresolu = atoi(argv[++i]);
159                          break;
160 <                case 'w':                               /* warnings */
160 >                case 'w':                               /* warnings & spectral */
161                          rval = erract[WARNING].pf != NULL;
162 <                        bool(2,rval);
162 >                        check_bool(2,rval);
163                          if (rval) erract[WARNING].pf = wputs;
164                          else erract[WARNING].pf = NULL;
165                          break;
# Line 119 | Line 170 | main(int  argc, char  *argv[])
170                  case 'l':                               /* limit distance */
171                          if (argv[i][2] != 'd')
172                                  goto badopt;
173 <                        bool(3,lim_dist);
173 >                        check_bool(3,lim_dist);
174                          break;
175                  case 'I':                               /* immed. irradiance */
176 <                        bool(2,imm_irrad);
176 >                        check_bool(2,imm_irrad);
177                          break;
178                  case 'f':                               /* format i/o */
179                          switch (argv[i][2]) {
# Line 154 | Line 205 | main(int  argc, char  *argv[])
205                          break;
206                  case 'h':                               /* header output */
207                          rval = loadflags & IO_INFO;
208 <                        bool(2,rval);
208 >                        check_bool(2,rval);
209                          loadflags = rval ? loadflags | IO_INFO :
210                                          loadflags & ~IO_INFO;
211                          break;
# Line 168 | Line 219 | main(int  argc, char  *argv[])
219                                          tralp = tralist;
220                                  }
221                                  if (argv[i][2] == 'I') {        /* file */
222 <                                        rval = wordfile(tralp,
222 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
223                                          getpath(argv[++i],getrlibpath(),R_OK));
224                                          if (rval < 0) {
225                                                  sprintf(errmsg,
# Line 190 | Line 241 | main(int  argc, char  *argv[])
241                                          tralp = tralist;
242                                  }
243                                  if (argv[i][2] == 'E') {        /* file */
244 <                                        rval = wordfile(tralp,
244 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
245                                          getpath(argv[++i],getrlibpath(),R_OK));
246                                          if (rval < 0) {
247                                                  sprintf(errmsg,
# Line 208 | Line 259 | main(int  argc, char  *argv[])
259                                  goto badopt;
260                          }
261                          break;
262 +                case 'p':                               /* value output */
263 +                        switch (argv[i][2]) {
264 +                        case 'R':                       /* standard RGB output */
265 +                                if (strcmp(argv[i]+2, "RGB"))
266 +                                        goto badopt;
267 +                                out_prims = stdprims;
268 +                                out_scalefactor = 1;
269 +                                sens_curve = NULL;
270 +                                break;
271 +                        case 'X':                       /* XYZ output */
272 +                                if (strcmp(argv[i]+2, "XYZ"))
273 +                                        goto badopt;
274 +                                out_prims = xyzprims;
275 +                                out_scalefactor = WHTEFFICACY;
276 +                                sens_curve = NULL;
277 +                                break;
278 +                        case 'c': {
279 +                                int     j;
280 +                                check(3,"ffffffff");
281 +                                rval = 0;
282 +                                for (j = 0; j < 8; j++) {
283 +                                        our_prims[0][j] = atof(argv[++i]);
284 +                                        rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001;
285 +                                }
286 +                                if (rval) {
287 +                                        if (!colorprimsOK(our_prims))
288 +                                                error(USER, "illegal primary chromaticities");
289 +                                        out_prims = our_prims;
290 +                                } else
291 +                                        out_prims = stdprims;
292 +                                out_scalefactor = 1;
293 +                                sens_curve = NULL;
294 +                                } break;
295 +                        case 'Y':                       /* photopic response */
296 +                                if (argv[i][3])
297 +                                        goto badopt;
298 +                                sens_curve = scolor_photopic;
299 +                                out_scalefactor = WHTEFFICACY;
300 +                                break;
301 +                        case 'S':                       /* scotopic response */
302 +                                if (argv[i][3])
303 +                                        goto badopt;
304 +                                sens_curve = scolor_scotopic;
305 +                                out_scalefactor = WHTSCOTOPIC;
306 +                                break;
307 +                        case 'M':                       /* melanopic response */
308 +                                if (argv[i][3])
309 +                                        goto badopt;
310 +                                sens_curve = scolor_melanopic;
311 +                                out_scalefactor = WHTMELANOPIC;
312 +                                break;
313 +                        default:
314 +                                goto badopt;
315 +                        }
316 +                        break;
317 + #if MAXCSAMP>3
318 +                case 'c':                               /* output spectral results */
319 +                        if (argv[i][2] != 'o')
320 +                                goto badopt;
321 +                        rval = (out_prims == NULL) & (sens_curve == NULL);
322 +                        check_bool(3,rval);
323 +                        if (rval) {
324 +                                out_prims = NULL;
325 +                                sens_curve = NULL;
326 +                        } else if (out_prims == NULL)
327 +                                out_prims = stdprims;
328 +                        break;
329 + #endif
330   #ifdef  PERSIST
331                  case 'P':                               /* persist file */
332                          if (argv[i][2] == 'P') {
# Line 224 | Line 343 | main(int  argc, char  *argv[])
343                          goto badopt;
344                  }
345          }
346 +                                        /* set/check spectral sampling */
347 +        rval = setspectrsamp(CNDX, WLPART);
348 +        if (rval < 0)
349 +                error(USER, "unsupported spectral sampling");
350 +        if (sens_curve != NULL)
351 +                out_prims = NULL;
352 +        else if (out_prims != NULL) {
353 +                if (!rval)
354 +                        error(WARNING, "spectral range incompatible with color output");
355 +        } else if (NCSAMP == 3)
356 +                out_prims = stdprims;   /* 3 samples do not a spectrum make */
357 +        if (nproc > 1 && persist)
358 +                error(USER, "multiprocessing incompatible with persist file");
359                                          /* initialize object types */
360          initotypes();
361                                          /* initialize urand */
362 <        initurand(2048);
362 >        reset_random();
363                                          /* set up signal handling */
364          sigdie(SIGINT, "Interrupt");
365   #ifdef SIGHUP
# Line 259 | Line 391 | main(int  argc, char  *argv[])
391   #endif
392                                          /* get octree */
393          if (i == argc)
394 <                octname = NULL;
394 >                octnm = NULL;
395          else if (i == argc-1)
396 <                octname = argv[i];
396 >                octnm = argv[i];
397          else
398                  goto badopt;
399 <        if (octname == NULL)
399 >        if (octnm == NULL)
400                  error(USER, "missing octree argument");
401                                          /* set up output */
402   #ifdef  PERSIST
# Line 273 | Line 405 | main(int  argc, char  *argv[])
405                  openheader();
406          }
407   #endif
276 #ifdef  _WIN32
408          if (outform != 'a')
409                  SET_FILE_BINARY(stdout);
410 <        if (octname == NULL)
411 <                SET_FILE_BINARY(stdin);
281 < #endif
410 >        rval = setrtoutput();
411 >        octname = savqstr(octnm);
412          readoct(octname, loadflags, &thescene, NULL);
413          nsceneobjs = nobjects;
414  
# Line 286 | Line 416 | main(int  argc, char  *argv[])
416                  printargs(i, argv, stdout);
417                  printf("SOFTWARE= %s\n", VersionID);
418                  fputnow(stdout);
419 +                if (rval > 0)           /* saved from setrtoutput() call */
420 +                        fputncomp(rval, stdout);
421 +                if (NCSAMP > 3)
422 +                        fputwlsplit(WLPART, stdout);
423 +                if ((out_prims != stdprims) & (out_prims != NULL))
424 +                        fputprims(out_prims, stdout);
425 +                if ((outform == 'f') | (outform == 'd'))
426 +                        fputendian(stdout);
427                  fputformat(formstr(outform), stdout);
428 <                putchar('\n');
428 >                fputc('\n', stdout);    /* end of header */
429          }
430  
431 <        marksources();                  /* find and mark sources */
431 >        if (!castonly) {        /* any actual ray traversal to do? */
432  
433 <        setambient();                   /* initialize ambient calculation */
433 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
434 >                
435 >                marksources();          /* find and mark sources */
436  
437 +                setambient();           /* initialize ambient calculation */
438 +        } else
439 +                distantsources();       /* else mark only distant sources */
440 +
441 +        fflush(stdout);                 /* in case we're duplicating header */
442 +
443   #ifdef  PERSIST
444          if (persist) {
299                fflush(stdout);
445                                                  /* reconnect stdout */
446                  dup2(duped1, fileno(stdout));
447                  close(duped1);
448                  if (persist == PARALLEL) {      /* multiprocessing */
449 <                        preload_objs();         /* preload scene */
305 <                        shm_boundary = (char *)malloc(16);
306 <                        strcpy(shm_boundary, "SHM_BOUNDARY");
449 >                        cow_memshare();         /* preloads scene */
450                          while ((rval=fork()) == 0) {    /* keep on forkin' */
451                                  pflock(1);
452                                  pfhold();
453 +                                ambsync();              /* load new values */
454                          }
455                          if (rval < 0)
456                                  error(SYSTEM, "cannot fork child for persist function");
457 <                        pfdetach();             /* parent exits */
457 >                        pfdetach();             /* parent will run then exit */
458                  }
459          }
460   runagain:
# Line 318 | Line 462 | runagain:
462                  dupheader();                    /* send header to stdout */
463   #endif
464                                          /* trace rays */
465 <        rtrace(NULL);
465 >        rtrace(NULL, nproc);
466                                          /* flush ambient file */
467          ambsync();
468   #ifdef  PERSIST
# Line 333 | Line 477 | runagain:
477                  }
478          }
479          if (persist == PCHILD) {        /* wait for a signal then go again */
336                close(duped1);                  /* release output handle */
480                  pfhold();
481                  raynum = nrays = 0;             /* reinitialize */
482                  goto runagain;
483          }
484   #endif
485 +
486 +        ray_done_pmap();           /* PMAP: free photon maps */
487 +        
488          quit(0);
489  
490   badopt:
# Line 347 | Line 493 | badopt:
493          return 1; /* pro forma return */
494  
495   #undef  check
496 < #undef  bool
496 > #undef  check_bool
497   }
498  
499  
500   void
501   wputs(                          /* warning output function */
502 <        char    *s
502 >        const char      *s
503   )
504   {
505          int  lasterrno = errno;
506 +        if (erract[WARNING].pf == NULL)
507 +                return;         /* called by calcomp or someone */
508          eputs(s);
509          errno = lasterrno;
510   }
# Line 364 | Line 512 | wputs(                         /* warning output function */
512  
513   void
514   eputs(                          /* put string to stderr */
515 <        register char  *s
515 >        const char  *s
516   )
517   {
518          static int  midline = 0;
# Line 419 | Line 567 | sigdie(                        /* set fatal signal */
567   static void
568   printdefaults(void)                     /* print default values to stdout */
569   {
570 <        register char  *cp;
570 >        char  *cp;
571  
572 +        printf(erract[WARNING].pf != NULL ?
573 +                        "-w+\t\t\t\t# warning messages on\n" :
574 +                        "-w-\t\t\t\t# warning messages off\n");
575          if (imm_irrad)
576                  printf("-I+\t\t\t\t# immediate irradiance on\n");
577 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
578 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
577 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
578 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
579 >                        vresolu && hresolu ? "x resolution" : "flush interval");
580 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
581          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
582                          "-ld-\t\t\t\t# limit distance off\n");
583 +        printf(loadflags & IO_INFO ? "-h+\t\t\t\t# output header\n" :
584 +                        "-h-\t\t\t\t# no header\n");
585          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
586                          inform, outform, formstr(inform), formstr(outform));
587 <        printf("-o%s\t\t\t\t# output", outvals);
587 >        printf("-o%-9s\t\t\t# output", outvals);
588          for (cp = outvals; *cp; cp++)
589                  switch (*cp) {
590 <                case 't': printf(" trace"); break;
590 >                case 't': case 'T': printf(" trace"); break;
591                  case 'o': printf(" origin"); break;
592                  case 'd': printf(" direction"); break;
593 +                case 'r': printf(" reflect_contrib"); break;
594 +                case 'R': printf(" reflect_length"); break;
595 +                case 'x': printf(" unreflect_contrib"); break;
596 +                case 'X': printf(" unreflect_length"); break;
597                  case 'v': printf(" value"); break;
598 +                case 'V': printf(" contribution"); break;
599                  case 'l': printf(" length"); break;
600                  case 'L': printf(" first_length"); break;
601                  case 'p': printf(" point"); break;
# Line 443 | Line 603 | printdefaults(void)                    /* print default values to stdou
603                  case 'N': printf(" unperturbed_normal"); break;
604                  case 's': printf(" surface"); break;
605                  case 'w': printf(" weight"); break;
606 +                case 'W': printf(" coefficient"); break;
607                  case 'm': printf(" modifier"); break;
608 +                case 'M': printf(" material"); break;
609 +                case '~': printf(" tilde"); break;
610                  }
611 <        putchar('\n');
612 <        printf(erract[WARNING].pf != NULL ?
613 <                        "-w+\t\t\t\t# warning messages on\n" :
614 <                        "-w-\t\t\t\t# warning messages off\n");
611 >        fputc('\n', stdout);
612 >        if (sens_curve == scolor_photopic)
613 >                printf("-pY\t\t\t\t# photopic output\n");
614 >        else if (sens_curve == scolor_scotopic)
615 >                printf("-pS\t\t\t\t# scotopic output\n");
616 >        else if (sens_curve == scolor_melanopic)
617 >                printf("-pM\t\t\t\t# melanopic output\n");
618 >        else if (out_prims == stdprims)
619 >                printf("-pRGB\t\t\t\t# standard RGB color output\n");
620 >        else if (out_prims == xyzprims)
621 >                printf("-pXYZ\t\t\t\t# CIE XYZ color output\n");
622 >        else if (out_prims != NULL)
623 >                printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n",
624 >                                out_prims[RED][0], out_prims[RED][1],
625 >                                out_prims[GRN][0], out_prims[GRN][1],
626 >                                out_prims[BLU][0], out_prims[BLU][1],
627 >                                out_prims[WHT][0], out_prims[WHT][1]);
628 >        if ((sens_curve == NULL) & (NCSAMP > 3))
629 >                printf(out_prims != NULL ? "-co-\t\t\t\t# output tristimulus colors\n" :
630 >                                "-co+\t\t\t\t# output spectral values\n");
631          print_rdefaults();
632   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines