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.11 by greg, Thu Jun 2 04:47:27 2005 UTC vs.
Revision 2.40 by greg, Thu Oct 20 17:18:33 2022 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"
# Line 18 | 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 26 | Line 30 | static const char      RCSid[] = "$Id$";
30   #define  PCHILD         3               /* child of normal persist */
31   #endif
32  
29 char  *progname;                        /* argv[0] */
30 char  *octname;                         /* octree name */
33   char  *sigerr[NSIG];                    /* signal error messages */
32 char  *shm_boundary = NULL;             /* boundary of shared memory */
34   char  *errfile = NULL;                  /* error output file */
35  
36 < extern char  *formstr();                /* string from format */
36 < extern int  inform;                     /* input format */
37 < extern int  outform;                    /* output format */
38 < 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\n" \
73 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
74 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n"
75 + #else
76 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
77 +                        "HessianAmbientCache\nAmbientAveraging\n" \
78 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
79 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n"
80 + #endif
81  
82 +
83   int
84   main(int  argc, char  *argv[])
85   {
86   #define  check(ol,al)           if (argv[i][ol] || \
87                                  badarg(argc-i-1,argv+i+1,al)) \
88                                  goto badopt
89 < #define  bool(olen,var)         switch (argv[i][olen]) { \
89 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
90                                  case '\0': var = !var; break; \
91                                  case 'y': case 'Y': case 't': case 'T': \
92                                  case '+': case '1': var = 1; break; \
93                                  case 'n': case 'N': case 'f': case 'F': \
94                                  case '-': case '0': var = 0; break; \
95                                  default: goto badopt; }
96 +        extern char  *octname;
97          int  persist = 0;
98 <        char  **tralp;
99 <        int  duped1;
98 >        char  *octnm = NULL;
99 >        char  **tralp = NULL;
100 >        int  duped1 = -1;
101          int  rval;
102          int  i;
103                                          /* global program name */
104          progname = argv[0] = fixargv0(argv[0]);
105 +                                        /* feature check only? */
106 +        strcat(RFeatureList, RTRACE_FEATURES);
107 +        if (!strcmp(argv[1], "-features"))
108 +                return feature_status(argc-2, argv+2);
109 +                                        /* add trace notify function */
110 +        for (i = 0; addobjnotify[i] != NULL; i++)
111 +                ;
112 +        addobjnotify[i] = tranotify;
113                                          /* option city */
114          for (i = 1; i < argc; i++) {
115                                                  /* expand arguments */
# Line 99 | Line 136 | main(int  argc, char  *argv[])
136                          continue;
137                  }
138                  switch (argv[i][1]) {
139 +                case 'n':                               /* number of cores */
140 +                        check(2,"i");
141 +                        nproc = atoi(argv[++i]);
142 +                        if (nproc <= 0)
143 +                                error(USER, "bad number of processes");
144 +                        break;
145                  case 'x':                               /* x resolution */
146                          check(2,"i");
147                          hresolu = atoi(argv[++i]);
# Line 109 | Line 152 | main(int  argc, char  *argv[])
152                          break;
153                  case 'w':                               /* warnings */
154                          rval = erract[WARNING].pf != NULL;
155 <                        bool(2,rval);
155 >                        check_bool(2,rval);
156                          if (rval) erract[WARNING].pf = wputs;
157                          else erract[WARNING].pf = NULL;
158                          break;
# Line 120 | Line 163 | main(int  argc, char  *argv[])
163                  case 'l':                               /* limit distance */
164                          if (argv[i][2] != 'd')
165                                  goto badopt;
166 <                        bool(3,lim_dist);
166 >                        check_bool(3,lim_dist);
167                          break;
168                  case 'I':                               /* immed. irradiance */
169 <                        bool(2,imm_irrad);
169 >                        check_bool(2,imm_irrad);
170                          break;
171                  case 'f':                               /* format i/o */
172                          switch (argv[i][2]) {
# Line 155 | Line 198 | main(int  argc, char  *argv[])
198                          break;
199                  case 'h':                               /* header output */
200                          rval = loadflags & IO_INFO;
201 <                        bool(2,rval);
201 >                        check_bool(2,rval);
202                          loadflags = rval ? loadflags | IO_INFO :
203                                          loadflags & ~IO_INFO;
204                          break;
# Line 169 | Line 212 | main(int  argc, char  *argv[])
212                                          tralp = tralist;
213                                  }
214                                  if (argv[i][2] == 'I') {        /* file */
215 <                                        rval = wordfile(tralp,
215 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
216                                          getpath(argv[++i],getrlibpath(),R_OK));
217                                          if (rval < 0) {
218                                                  sprintf(errmsg,
# Line 191 | Line 234 | main(int  argc, char  *argv[])
234                                          tralp = tralist;
235                                  }
236                                  if (argv[i][2] == 'E') {        /* file */
237 <                                        rval = wordfile(tralp,
237 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
238                                          getpath(argv[++i],getrlibpath(),R_OK));
239                                          if (rval < 0) {
240                                                  sprintf(errmsg,
# Line 225 | Line 268 | main(int  argc, char  *argv[])
268                          goto badopt;
269                  }
270          }
271 +        if (nproc > 1 && persist)
272 +                error(USER, "multiprocessing incompatible with persist file");
273                                          /* initialize object types */
274          initotypes();
275                                          /* initialize urand */
276 <        initurand(2048);
276 >        if (rand_samp) {
277 >                srandom((long)time(0));
278 >                initurand(0);
279 >        } else {
280 >                srandom(0L);
281 >                initurand(2048);
282 >        }
283                                          /* set up signal handling */
284          sigdie(SIGINT, "Interrupt");
285   #ifdef SIGHUP
# Line 260 | Line 311 | main(int  argc, char  *argv[])
311   #endif
312                                          /* get octree */
313          if (i == argc)
314 <                octname = NULL;
314 >                octnm = NULL;
315          else if (i == argc-1)
316 <                octname = argv[i];
316 >                octnm = argv[i];
317          else
318                  goto badopt;
319 <        if (octname == NULL)
319 >        if (octnm == NULL)
320                  error(USER, "missing octree argument");
321                                          /* set up output */
322   #ifdef  PERSIST
# Line 276 | Line 327 | main(int  argc, char  *argv[])
327   #endif
328          if (outform != 'a')
329                  SET_FILE_BINARY(stdout);
330 <        readoct(octname, loadflags, &thescene, NULL);
330 >        rval = setrtoutput();
331 >        readoct(octname = octnm, loadflags, &thescene, NULL);
332          nsceneobjs = nobjects;
333  
334          if (loadflags & IO_INFO) {      /* print header */
335                  printargs(i, argv, stdout);
336                  printf("SOFTWARE= %s\n", VersionID);
337                  fputnow(stdout);
338 +                if (rval > 0)           /* saved from setrtoutput() call */
339 +                        printf("NCOMP=%d\n", rval);
340 +                if ((outform == 'f') | (outform == 'd'))
341 +                        fputendian(stdout);
342                  fputformat(formstr(outform), stdout);
343                  putchar('\n');
344          }
345  
346 <        marksources();                  /* find and mark sources */
346 >        if (!castonly) {        /* any actual ray traversal to do? */
347  
348 <        setambient();                   /* initialize ambient calculation */
348 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
349 >                
350 >                marksources();          /* find and mark sources */
351  
352 +                setambient();           /* initialize ambient calculation */
353 +        } else
354 +                distantsources();       /* else mark only distant sources */
355 +
356 +        fflush(stdout);                 /* in case we're duplicating header */
357 +
358   #ifdef  PERSIST
359          if (persist) {
296                fflush(stdout);
360                                                  /* reconnect stdout */
361                  dup2(duped1, fileno(stdout));
362                  close(duped1);
# Line 304 | Line 367 | main(int  argc, char  *argv[])
367                          while ((rval=fork()) == 0) {    /* keep on forkin' */
368                                  pflock(1);
369                                  pfhold();
370 +                                ambsync();              /* load new values */
371                          }
372                          if (rval < 0)
373                                  error(SYSTEM, "cannot fork child for persist function");
374 <                        pfdetach();             /* parent exits */
374 >                        pfdetach();             /* parent will run then exit */
375                  }
376          }
377   runagain:
# Line 315 | Line 379 | runagain:
379                  dupheader();                    /* send header to stdout */
380   #endif
381                                          /* trace rays */
382 <        rtrace(NULL);
382 >        rtrace(NULL, nproc);
383                                          /* flush ambient file */
384          ambsync();
385   #ifdef  PERSIST
# Line 330 | Line 394 | runagain:
394                  }
395          }
396          if (persist == PCHILD) {        /* wait for a signal then go again */
333                close(duped1);                  /* release output handle */
397                  pfhold();
398                  raynum = nrays = 0;             /* reinitialize */
399                  goto runagain;
400          }
401   #endif
402 +
403 +        ray_done_pmap();           /* PMAP: free photon maps */
404 +        
405          quit(0);
406  
407   badopt:
# Line 344 | Line 410 | badopt:
410          return 1; /* pro forma return */
411  
412   #undef  check
413 < #undef  bool
413 > #undef  check_bool
414   }
415  
416  
# Line 361 | Line 427 | wputs(                         /* warning output function */
427  
428   void
429   eputs(                          /* put string to stderr */
430 <        register char  *s
430 >        char  *s
431   )
432   {
433          static int  midline = 0;
# Line 416 | Line 482 | sigdie(                        /* set fatal signal */
482   static void
483   printdefaults(void)                     /* print default values to stdout */
484   {
485 <        register char  *cp;
485 >        char  *cp;
486  
487          if (imm_irrad)
488                  printf("-I+\t\t\t\t# immediate irradiance on\n");
489 <        printf("-x  %-9d\t\t\t# x resolution (flush interval)\n", hresolu);
490 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
489 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
490 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
491 >                        vresolu && hresolu ? "x resolution" : "flush interval");
492 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
493          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
494                          "-ld-\t\t\t\t# limit distance off\n");
495          printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
# Line 434 | Line 502 | printdefaults(void)                    /* print default values to stdou
502                  case 't': case 'T': printf(" trace"); break;
503                  case 'o': printf(" origin"); break;
504                  case 'd': printf(" direction"); break;
505 +                case 'r': printf(" reflect_contrib"); break;
506 +                case 'R': printf(" reflect_length"); break;
507 +                case 'x': printf(" unreflect_contrib"); break;
508 +                case 'X': printf(" unreflect_length"); break;
509                  case 'v': printf(" value"); break;
510 +                case 'V': printf(" contribution"); break;
511                  case 'l': printf(" length"); break;
512                  case 'L': printf(" first_length"); break;
513                  case 'p': printf(" point"); break;
# Line 442 | Line 515 | printdefaults(void)                    /* print default values to stdou
515                  case 'N': printf(" unperturbed_normal"); break;
516                  case 's': printf(" surface"); break;
517                  case 'w': printf(" weight"); break;
518 +                case 'W': printf(" coefficient"); break;
519                  case 'm': printf(" modifier"); break;
520                  case 'M': printf(" material"); break;
521 <                case 'W': printf(" contribution"); break;
448 <                case '-': printf(" stroke"); break;
521 >                case '~': printf(" tilde"); break;
522                  }
523          putchar('\n');
524          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines