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.8 by schorsch, Tue Oct 21 19:19:28 2003 UTC vs.
Revision 2.44 by greg, Mon Feb 6 22:40:21 2023 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  "source.h"
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  
33 < char  *progname;                        /* argv[0] */
33 > char  *sigerr[NSIG];                    /* signal error messages */
34 > char  *errfile = NULL;                  /* error output file */
35  
36 < char  *octname;                         /* octree name */
36 > int  nproc = 1;                         /* number of processes */
37  
38 < char  *sigerr[NSIG];                    /* signal error messages */
38 > extern int  setrtoutput(void);          /* set output values */
39  
40 < char  *shm_boundary = NULL;             /* boundary of shared memory */
40 > int  inform = 'a';                      /* input format */
41 > int  outform = 'a';                     /* output format */
42 > char  *outvals = "v";                   /* output specification */
43  
44 < char  *errfile = NULL;                  /* error output file */
44 > int  hresolu = 0;                       /* horizontal (scan) size */
45 > int  vresolu = 0;                       /* vertical resolution */
46  
47 < extern char  *formstr();                /* string from format */
39 < extern int  inform;                     /* input format */
40 < extern int  outform;                    /* output format */
41 < extern char  *outvals;                  /* output values */
47 > extern int  castonly;                   /* only doing ray-casting? */
48  
49 < extern int  hresolu;                    /* horizontal resolution */
50 < extern int  vresolu;                    /* vertical resolution */
49 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
50 > int  lim_dist = 0;                      /* limit distance? */
51  
52 < extern int  imm_irrad;                  /* compute immediate irradiance? */
53 < extern int  lim_dist;                   /* limit distance? */
52 > #ifndef MAXMODLIST
53 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
54 > #endif
55  
56 < extern char  *tralist[];                /* list of modifers to trace (or no) */
57 < extern int  traincl;                    /* include == 1, exclude == 0 */
56 > extern void  (*addobjnotify[])();       /* object notification calls */
57 > extern void  tranotify(OBJECT obj);
58  
59 < void    onsig(int);
60 < void    sigdie(int, char*);
54 < void    printdefaults(void);
59 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
60 > int  traincl = -1;                      /* include == 1, exclude == 0 */
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 +                        "HessianAmbientCache\nAmbientAveraging\n" \
72 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
73 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n"
74 + #else
75 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
76 +                        "HessianAmbientCache\nAmbientAveraging\n" \
77 +                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \
78 +                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n"
79 + #endif
80 +
81 +
82   int
83 < main(argc, argv)
59 < int  argc;
60 < char  *argv[];
83 > main(int  argc, char  *argv[])
84   {
85   #define  check(ol,al)           if (argv[i][ol] || \
86                                  badarg(argc-i-1,argv+i+1,al)) \
87                                  goto badopt
88 < #define  bool(olen,var)         switch (argv[i][olen]) { \
88 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
89                                  case '\0': var = !var; break; \
90                                  case 'y': case 'Y': case 't': case 'T': \
91                                  case '+': case '1': var = 1; break; \
92                                  case 'n': case 'N': case 'f': case 'F': \
93                                  case '-': case '0': var = 0; break; \
94                                  default: goto badopt; }
95 <        int  loadflags = ~IO_FILES;
95 >        extern char  *octname;
96          int  persist = 0;
97 <        char  **tralp;
98 <        int  duped1;
97 >        char  *octnm = NULL;
98 >        char  **tralp = NULL;
99 >        int  duped1 = -1;
100          int  rval;
101          int  i;
102                                          /* global program name */
103          progname = argv[0] = fixargv0(argv[0]);
104 +                                        /* feature check only? */
105 +        strcat(RFeatureList, RTRACE_FEATURES);
106 +        if (argc > 1 && !strcmp(argv[1], "-features"))
107 +                return feature_status(argc-2, argv+2);
108 +                                        /* add trace notify function */
109 +        for (i = 0; addobjnotify[i] != NULL; i++)
110 +                ;
111 +        addobjnotify[i] = tranotify;
112                                          /* option city */
113          for (i = 1; i < argc; i++) {
114                                                  /* expand arguments */
# Line 103 | Line 135 | char  *argv[];
135                          continue;
136                  }
137                  switch (argv[i][1]) {
138 +                case 'n':                               /* number of cores */
139 +                        check(2,"i");
140 +                        nproc = atoi(argv[++i]);
141 +                        if (nproc <= 0)
142 +                                error(USER, "bad number of processes");
143 +                        break;
144                  case 'x':                               /* x resolution */
145                          check(2,"i");
146                          hresolu = atoi(argv[++i]);
# Line 113 | Line 151 | char  *argv[];
151                          break;
152                  case 'w':                               /* warnings */
153                          rval = erract[WARNING].pf != NULL;
154 <                        bool(2,rval);
154 >                        check_bool(2,rval);
155                          if (rval) erract[WARNING].pf = wputs;
156                          else erract[WARNING].pf = NULL;
157                          break;
# Line 124 | Line 162 | char  *argv[];
162                  case 'l':                               /* limit distance */
163                          if (argv[i][2] != 'd')
164                                  goto badopt;
165 <                        bool(3,lim_dist);
165 >                        check_bool(3,lim_dist);
166                          break;
167                  case 'I':                               /* immed. irradiance */
168 <                        bool(2,imm_irrad);
168 >                        check_bool(2,imm_irrad);
169                          break;
170                  case 'f':                               /* format i/o */
171                          switch (argv[i][2]) {
# Line 159 | Line 197 | char  *argv[];
197                          break;
198                  case 'h':                               /* header output */
199                          rval = loadflags & IO_INFO;
200 <                        bool(2,rval);
200 >                        check_bool(2,rval);
201                          loadflags = rval ? loadflags | IO_INFO :
202                                          loadflags & ~IO_INFO;
203                          break;
# Line 173 | Line 211 | char  *argv[];
211                                          tralp = tralist;
212                                  }
213                                  if (argv[i][2] == 'I') {        /* file */
214 <                                        rval = wordfile(tralp,
214 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
215                                          getpath(argv[++i],getrlibpath(),R_OK));
216                                          if (rval < 0) {
217                                                  sprintf(errmsg,
# Line 195 | Line 233 | char  *argv[];
233                                          tralp = tralist;
234                                  }
235                                  if (argv[i][2] == 'E') {        /* file */
236 <                                        rval = wordfile(tralp,
236 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
237                                          getpath(argv[++i],getrlibpath(),R_OK));
238                                          if (rval < 0) {
239                                                  sprintf(errmsg,
# Line 229 | Line 267 | char  *argv[];
267                          goto badopt;
268                  }
269          }
270 +        if (nproc > 1 && persist)
271 +                error(USER, "multiprocessing incompatible with persist file");
272                                          /* initialize object types */
273          initotypes();
274                                          /* initialize urand */
275 <        initurand(2048);
275 >        if (rand_samp) {
276 >                srandom((long)time(0));
277 >                initurand(0);
278 >        } else {
279 >                srandom(0L);
280 >                initurand(2048);
281 >        }
282                                          /* set up signal handling */
283          sigdie(SIGINT, "Interrupt");
284   #ifdef SIGHUP
# Line 264 | Line 310 | char  *argv[];
310   #endif
311                                          /* get octree */
312          if (i == argc)
313 <                octname = NULL;
313 >                octnm = NULL;
314          else if (i == argc-1)
315 <                octname = argv[i];
315 >                octnm = argv[i];
316          else
317                  goto badopt;
318 <        if (octname == NULL)
318 >        if (octnm == NULL)
319                  error(USER, "missing octree argument");
320                                          /* set up output */
321   #ifdef  PERSIST
# Line 278 | Line 324 | char  *argv[];
324                  openheader();
325          }
326   #endif
281 #ifdef  _WIN32
327          if (outform != 'a')
328                  SET_FILE_BINARY(stdout);
329 <        if (octname == NULL)
330 <                SET_FILE_BINARY(stdin);
286 < #endif
329 >        rval = setrtoutput();
330 >        octname = savqstr(octnm);
331          readoct(octname, loadflags, &thescene, NULL);
332          nsceneobjs = nobjects;
333  
# Line 291 | Line 335 | char  *argv[];
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) {
304                fflush(stdout);
360                                                  /* reconnect stdout */
361                  dup2(duped1, fileno(stdout));
362                  close(duped1);
# Line 312 | Line 367 | 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 323 | 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 338 | Line 394 | runagain:
394                  }
395          }
396          if (persist == PCHILD) {        /* wait for a signal then go again */
341                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:
408          sprintf(errmsg, "command line error at '%s'", argv[i]);
409          error(USER, errmsg);
410 +        return 1; /* pro forma return */
411  
412   #undef  check
413 < #undef  bool
413 > #undef  check_bool
414   }
415  
416  
417   void
418 < wputs(s)                                /* warning output function */
419 < char    *s;
418 > wputs(                          /* warning output function */
419 >        const char      *s
420 > )
421   {
422          int  lasterrno = errno;
423          eputs(s);
# Line 366 | Line 426 | char   *s;
426  
427  
428   void
429 < eputs(s)                                /* put string to stderr */
430 < register char  *s;
429 > eputs(                          /* put string to stderr */
430 >        const char  *s
431 > )
432   {
433          static int  midline = 0;
434  
# Line 385 | Line 446 | register char  *s;
446   }
447  
448  
449 < void
450 < onsig(signo)                            /* fatal signal */
451 < int  signo;
449 > static void
450 > onsig(                          /* fatal signal */
451 >        int  signo
452 > )
453   {
454          static int  gotsig = 0;
455  
# Line 405 | Line 467 | int  signo;
467   }
468  
469  
470 < void
471 < sigdie(signo, msg)                      /* set fatal signal */
472 < int  signo;
473 < char  *msg;
470 > static void
471 > sigdie(                 /* set fatal signal */
472 >        int  signo,
473 >        char  *msg
474 > )
475   {
476          if (signal(signo, onsig) == SIG_IGN)
477                  signal(signo, SIG_IGN);
# Line 416 | Line 479 | char  *msg;
479   }
480  
481  
482 < void
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\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 ? '+' : '-',
496 +                        loadflags & IO_INFO ? "output" : "no");
497          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
498                          inform, outform, formstr(inform), formstr(outform));
499 <        printf("-o%s\t\t\t\t# output", outvals);
499 >        printf("-o%-9s\t\t\t# output", outvals);
500          for (cp = outvals; *cp; cp++)
501                  switch (*cp) {
502 <                case 't': printf(" trace"); break;
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 443 | 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 '~': printf(" tilde"); break;
522                  }
523          putchar('\n');
524          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines