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.13 by greg, Sun Feb 5 22:22:20 2006 UTC vs.
Revision 2.38 by greg, Wed Oct 19 21:25:20 2022 UTC

# Line 17 | Line 17 | static const char      RCSid[] = "$Id$";
17   #include  "ambient.h"
18   #include  "random.h"
19   #include  "paths.h"
20 + #include  "pmapray.h"
21  
22 + extern char     *progname;              /* global argv[0] */
23 +
24 + extern char     *shm_boundary;          /* boundary of shared memory */
25 +
26                                          /* persistent processes define */
27   #ifdef  F_SETLKW
28   #define  PERSIST        1               /* normal persist */
# Line 25 | Line 30 | static const char      RCSid[] = "$Id$";
30   #define  PCHILD         3               /* child of normal persist */
31   #endif
32  
28 char  *progname;                        /* argv[0] */
29 char  *octname;                         /* octree name */
33   char  *sigerr[NSIG];                    /* signal error messages */
31 char  *shm_boundary = NULL;             /* boundary of shared memory */
34   char  *errfile = NULL;                  /* error output file */
35  
36 < extern char  *formstr();                /* string from format */
35 < extern int  inform;                     /* input format */
36 < extern int  outform;                    /* output format */
37 < extern char  *outvals;                  /* output values */
36 > int  nproc = 1;                         /* number of processes */
37  
38 < extern int  hresolu;                    /* horizontal resolution */
39 < extern int  vresolu;                    /* vertical resolution */
38 > extern char  *formstr(int f);           /* string from format */
39 > extern int  setrtoutput(void);          /* set output values */
40  
41 < extern int  imm_irrad;                  /* compute immediate irradiance? */
42 < extern int  lim_dist;                   /* limit distance? */
41 > int  inform = 'a';                      /* input format */
42 > int  outform = 'a';                     /* output format */
43 > char  *outvals = "v";                   /* output specification */
44  
45 < extern char  *tralist[];                /* list of modifers to trace (or no) */
46 < extern int  traincl;                    /* include == 1, exclude == 0 */
45 > int  hresolu = 0;                       /* horizontal (scan) size */
46 > int  vresolu = 0;                       /* vertical resolution */
47  
48 + extern int  castonly;                   /* only doing ray-casting? */
49 +
50 + int  imm_irrad = 0;                     /* compute immediate irradiance? */
51 + int  lim_dist = 0;                      /* limit distance? */
52 +
53 + #ifndef MAXMODLIST
54 + #define MAXMODLIST      1024            /* maximum modifiers we'll track */
55 + #endif
56 +
57 + extern void  (*addobjnotify[])();       /* object notification calls */
58 + extern void  tranotify(OBJECT obj);
59 +
60 + char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
61 + int  traincl = -1;                      /* include == 1, exclude == 0 */
62 +
63   static int  loadflags = ~IO_FILES;      /* what to load from octree */
64  
65   static void onsig(int  signo);
66   static void sigdie(int  signo, char  *msg);
67   static void printdefaults(void);
68  
69 + #ifdef PERSIST
70 + #define RTRACE_FEATURES "Persist\nParallelPersist\nMultiProcessing\n" \
71 +                        "IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \
72 +                        "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n"
73 + #else
74 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
75 +                        "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n"
76 + #endif
77  
78 +
79   int
80   main(int  argc, char  *argv[])
81   {
82   #define  check(ol,al)           if (argv[i][ol] || \
83                                  badarg(argc-i-1,argv+i+1,al)) \
84                                  goto badopt
85 < #define  bool(olen,var)         switch (argv[i][olen]) { \
85 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
86                                  case '\0': var = !var; break; \
87                                  case 'y': case 'Y': case 't': case 'T': \
88                                  case '+': case '1': var = 1; break; \
89                                  case 'n': case 'N': case 'f': case 'F': \
90                                  case '-': case '0': var = 0; break; \
91                                  default: goto badopt; }
92 +        extern char  *octname;
93          int  persist = 0;
94 <        char  **tralp;
95 <        int  duped1;
94 >        char  *octnm = NULL;
95 >        char  **tralp = NULL;
96 >        int  duped1 = -1;
97          int  rval;
98          int  i;
99                                          /* global program name */
100          progname = argv[0] = fixargv0(argv[0]);
101 +                                        /* feature check only? */
102 +        strcat(RFeatureList, RTRACE_FEATURES);
103 +        if (!strcmp(argv[1], "-features"))
104 +                return feature_status(argc-2, argv+2);
105 +                                        /* add trace notify function */
106 +        for (i = 0; addobjnotify[i] != NULL; i++)
107 +                ;
108 +        addobjnotify[i] = tranotify;
109                                          /* option city */
110          for (i = 1; i < argc; i++) {
111                                                  /* expand arguments */
# Line 98 | Line 132 | main(int  argc, char  *argv[])
132                          continue;
133                  }
134                  switch (argv[i][1]) {
135 +                case 'n':                               /* number of cores */
136 +                        check(2,"i");
137 +                        nproc = atoi(argv[++i]);
138 +                        if (nproc <= 0)
139 +                                error(USER, "bad number of processes");
140 +                        break;
141                  case 'x':                               /* x resolution */
142                          check(2,"i");
143                          hresolu = atoi(argv[++i]);
# Line 108 | Line 148 | main(int  argc, char  *argv[])
148                          break;
149                  case 'w':                               /* warnings */
150                          rval = erract[WARNING].pf != NULL;
151 <                        bool(2,rval);
151 >                        check_bool(2,rval);
152                          if (rval) erract[WARNING].pf = wputs;
153                          else erract[WARNING].pf = NULL;
154                          break;
# Line 119 | Line 159 | main(int  argc, char  *argv[])
159                  case 'l':                               /* limit distance */
160                          if (argv[i][2] != 'd')
161                                  goto badopt;
162 <                        bool(3,lim_dist);
162 >                        check_bool(3,lim_dist);
163                          break;
164                  case 'I':                               /* immed. irradiance */
165 <                        bool(2,imm_irrad);
165 >                        check_bool(2,imm_irrad);
166                          break;
167                  case 'f':                               /* format i/o */
168                          switch (argv[i][2]) {
# Line 154 | Line 194 | main(int  argc, char  *argv[])
194                          break;
195                  case 'h':                               /* header output */
196                          rval = loadflags & IO_INFO;
197 <                        bool(2,rval);
197 >                        check_bool(2,rval);
198                          loadflags = rval ? loadflags | IO_INFO :
199                                          loadflags & ~IO_INFO;
200                          break;
# Line 168 | Line 208 | main(int  argc, char  *argv[])
208                                          tralp = tralist;
209                                  }
210                                  if (argv[i][2] == 'I') {        /* file */
211 <                                        rval = wordfile(tralp,
211 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
212                                          getpath(argv[++i],getrlibpath(),R_OK));
213                                          if (rval < 0) {
214                                                  sprintf(errmsg,
# Line 190 | Line 230 | main(int  argc, char  *argv[])
230                                          tralp = tralist;
231                                  }
232                                  if (argv[i][2] == 'E') {        /* file */
233 <                                        rval = wordfile(tralp,
233 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
234                                          getpath(argv[++i],getrlibpath(),R_OK));
235                                          if (rval < 0) {
236                                                  sprintf(errmsg,
# Line 224 | Line 264 | main(int  argc, char  *argv[])
264                          goto badopt;
265                  }
266          }
267 +        if (nproc > 1 && persist)
268 +                error(USER, "multiprocessing incompatible with persist file");
269                                          /* initialize object types */
270          initotypes();
271                                          /* initialize urand */
272 <        initurand(2048);
273 <        srandom(rand_samp ? (long)time(0) : 0L);
272 >        if (rand_samp) {
273 >                srandom((long)time(0));
274 >                initurand(0);
275 >        } else {
276 >                srandom(0L);
277 >                initurand(2048);
278 >        }
279                                          /* set up signal handling */
280          sigdie(SIGINT, "Interrupt");
281   #ifdef SIGHUP
# Line 260 | Line 307 | main(int  argc, char  *argv[])
307   #endif
308                                          /* get octree */
309          if (i == argc)
310 <                octname = NULL;
310 >                octnm = NULL;
311          else if (i == argc-1)
312 <                octname = argv[i];
312 >                octnm = argv[i];
313          else
314                  goto badopt;
315 <        if (octname == NULL)
315 >        if (octnm == NULL)
316                  error(USER, "missing octree argument");
317                                          /* set up output */
318   #ifdef  PERSIST
# Line 276 | Line 323 | main(int  argc, char  *argv[])
323   #endif
324          if (outform != 'a')
325                  SET_FILE_BINARY(stdout);
326 <        readoct(octname, loadflags, &thescene, NULL);
326 >        rval = setrtoutput();
327 >        readoct(octname = octnm, loadflags, &thescene, NULL);
328          nsceneobjs = nobjects;
329  
330          if (loadflags & IO_INFO) {      /* print header */
331                  printargs(i, argv, stdout);
332                  printf("SOFTWARE= %s\n", VersionID);
333                  fputnow(stdout);
334 +                if (rval > 0)           /* saved from setrtoutput() call */
335 +                        printf("NCOMP=%d\n", rval);
336 +                if ((outform == 'f') | (outform == 'd'))
337 +                        fputendian(stdout);
338                  fputformat(formstr(outform), stdout);
339                  putchar('\n');
340          }
341  
342 <        marksources();                  /* find and mark sources */
342 >        if (!castonly) {        /* any actual ray traversal to do? */
343  
344 <        setambient();                   /* initialize ambient calculation */
344 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
345 >                
346 >                marksources();          /* find and mark sources */
347  
348 +                setambient();           /* initialize ambient calculation */
349 +        } else
350 +                distantsources();       /* else mark only distant sources */
351 +
352 +        fflush(stdout);                 /* in case we're duplicating header */
353 +
354   #ifdef  PERSIST
355          if (persist) {
296                fflush(stdout);
356                                                  /* reconnect stdout */
357                  dup2(duped1, fileno(stdout));
358                  close(duped1);
# Line 304 | Line 363 | main(int  argc, char  *argv[])
363                          while ((rval=fork()) == 0) {    /* keep on forkin' */
364                                  pflock(1);
365                                  pfhold();
366 +                                ambsync();              /* load new values */
367                          }
368                          if (rval < 0)
369                                  error(SYSTEM, "cannot fork child for persist function");
370 <                        pfdetach();             /* parent exits */
370 >                        pfdetach();             /* parent will run then exit */
371                  }
372          }
373   runagain:
# Line 315 | Line 375 | runagain:
375                  dupheader();                    /* send header to stdout */
376   #endif
377                                          /* trace rays */
378 <        rtrace(NULL);
378 >        rtrace(NULL, nproc);
379                                          /* flush ambient file */
380          ambsync();
381   #ifdef  PERSIST
# Line 330 | Line 390 | runagain:
390                  }
391          }
392          if (persist == PCHILD) {        /* wait for a signal then go again */
333                close(duped1);                  /* release output handle */
393                  pfhold();
394                  raynum = nrays = 0;             /* reinitialize */
395                  goto runagain;
396          }
397   #endif
398 +
399 +        ray_done_pmap();           /* PMAP: free photon maps */
400 +        
401          quit(0);
402  
403   badopt:
# Line 344 | Line 406 | badopt:
406          return 1; /* pro forma return */
407  
408   #undef  check
409 < #undef  bool
409 > #undef  check_bool
410   }
411  
412  
# Line 361 | Line 423 | wputs(                         /* warning output function */
423  
424   void
425   eputs(                          /* put string to stderr */
426 <        register char  *s
426 >        char  *s
427   )
428   {
429          static int  midline = 0;
# Line 416 | Line 478 | sigdie(                        /* set fatal signal */
478   static void
479   printdefaults(void)                     /* print default values to stdout */
480   {
481 <        register char  *cp;
481 >        char  *cp;
482  
483          if (imm_irrad)
484                  printf("-I+\t\t\t\t# immediate irradiance on\n");
485 <        printf("-x  %-9d\t\t\t# x resolution (flush interval)\n", hresolu);
486 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
485 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
486 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
487 >                        vresolu && hresolu ? "x resolution" : "flush interval");
488 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
489          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
490                          "-ld-\t\t\t\t# limit distance off\n");
491          printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
# Line 434 | Line 498 | printdefaults(void)                    /* print default values to stdou
498                  case 't': case 'T': printf(" trace"); break;
499                  case 'o': printf(" origin"); break;
500                  case 'd': printf(" direction"); break;
501 +                case 'r': printf(" reflect_contrib"); break;
502 +                case 'R': printf(" reflect_length"); break;
503 +                case 'x': printf(" unreflect_contrib"); break;
504 +                case 'X': printf(" unreflect_length"); break;
505                  case 'v': printf(" value"); break;
506                  case 'V': printf(" contribution"); break;
507                  case 'l': printf(" length"); break;
# Line 446 | Line 514 | printdefaults(void)                    /* print default values to stdou
514                  case 'W': printf(" coefficient"); break;
515                  case 'm': printf(" modifier"); break;
516                  case 'M': printf(" material"); break;
517 <                case '-': printf(" stroke"); break;
517 >                case '~': printf(" tilde"); break;
518                  }
519          putchar('\n');
520          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines