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.7 by schorsch, Mon Jul 14 20:02:30 2003 UTC vs.
Revision 2.38 by greg, Wed Oct 19 21:25:20 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"
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 char  *formstr(int f);           /* string from format */
39 > extern int  setrtoutput(void);          /* set output values */
40  
41 < char  *shm_boundary = NULL;             /* boundary of shared memory */
41 > int  inform = 'a';                      /* input format */
42 > int  outform = 'a';                     /* output format */
43 > char  *outvals = "v";                   /* output specification */
44  
45 < char  *errfile = NULL;                  /* error output file */
45 > int  hresolu = 0;                       /* horizontal (scan) size */
46 > int  vresolu = 0;                       /* vertical resolution */
47  
48 < extern char  *formstr();                /* string from format */
39 < extern int  inform;                     /* input format */
40 < extern int  outform;                    /* output format */
41 < extern char  *outvals;                  /* output values */
48 > extern int  castonly;                   /* only doing ray-casting? */
49  
50 < extern int  hresolu;                    /* horizontal resolution */
51 < extern int  vresolu;                    /* vertical resolution */
50 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
51 > int  lim_dist = 0;                      /* limit distance? */
52  
53 < extern int  imm_irrad;                  /* compute immediate irradiance? */
54 < extern int  lim_dist;                   /* limit distance? */
53 > #ifndef MAXMODLIST
54 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
55 > #endif
56  
57 < extern char  *tralist[];                /* list of modifers to trace (or no) */
58 < extern int  traincl;                    /* include == 1, exclude == 0 */
57 > extern void  (*addobjnotify[])();       /* object notification calls */
58 > extern void  tranotify(OBJECT obj);
59  
60 < void    onsig();
61 < void    sigdie();
54 < void    printdefaults();
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(argc, argv)
59 < int  argc;
60 < char  *argv[];
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 <        int  loadflags = ~IO_FILES;
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 103 | Line 132 | 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 113 | Line 148 | 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 124 | Line 159 | 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 159 | Line 194 | 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 173 | Line 208 | 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 195 | Line 230 | 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 229 | Line 264 | 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);
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 264 | Line 307 | 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 278 | Line 321 | char  *argv[];
321                  openheader();
322          }
323   #endif
281 #ifdef  _WIN32
324          if (outform != 'a')
325                  SET_FILE_BINARY(stdout);
326 <        if (octname == NULL)
327 <                SET_FILE_BINARY(stdin);
286 < #endif
287 <        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) {
304                fflush(stdout);
356                                                  /* reconnect stdout */
357                  dup2(duped1, fileno(stdout));
358                  close(duped1);
# Line 312 | Line 363 | 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 323 | 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 338 | Line 390 | runagain:
390                  }
391          }
392          if (persist == PCHILD) {        /* wait for a signal then go again */
341                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:
404          sprintf(errmsg, "command line error at '%s'", argv[i]);
405          error(USER, errmsg);
406 +        return 1; /* pro forma return */
407  
408   #undef  check
409 < #undef  bool
409 > #undef  check_bool
410   }
411  
412  
413   void
414 < wputs(s)                                /* warning output function */
415 < char    *s;
414 > wputs(                          /* warning output function */
415 >        char    *s
416 > )
417   {
418          int  lasterrno = errno;
419          eputs(s);
# Line 366 | Line 422 | char   *s;
422  
423  
424   void
425 < eputs(s)                                /* put string to stderr */
426 < register char  *s;
425 > eputs(                          /* put string to stderr */
426 >        char  *s
427 > )
428   {
429          static int  midline = 0;
430  
# Line 385 | Line 442 | register char  *s;
442   }
443  
444  
445 < void
446 < onsig(signo)                            /* fatal signal */
447 < int  signo;
445 > static void
446 > onsig(                          /* fatal signal */
447 >        int  signo
448 > )
449   {
450          static int  gotsig = 0;
451  
# Line 405 | Line 463 | int  signo;
463   }
464  
465  
466 < void
467 < sigdie(signo, msg)                      /* set fatal signal */
468 < int  signo;
469 < char  *msg;
466 > static void
467 > sigdie(                 /* set fatal signal */
468 >        int  signo,
469 >        char  *msg
470 > )
471   {
472          if (signal(signo, onsig) == SIG_IGN)
473                  signal(signo, SIG_IGN);
# Line 416 | Line 475 | char  *msg;
475   }
476  
477  
478 < void
479 < printdefaults()                 /* print default values to stdout */
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\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 ? '+' : '-',
492 +                        loadflags & IO_INFO ? "output" : "no");
493          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
494                          inform, outform, formstr(inform), formstr(outform));
495 <        printf("-o%s\t\t\t\t# output", outvals);
495 >        printf("-o%-9s\t\t\t# output", outvals);
496          for (cp = outvals; *cp; cp++)
497                  switch (*cp) {
498 <                case 't': printf(" trace"); break;
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;
508                  case 'L': printf(" first_length"); break;
509                  case 'p': printf(" point"); break;
# Line 443 | Line 511 | printdefaults()                        /* print default values to stdout */
511                  case 'N': printf(" unperturbed_normal"); break;
512                  case 's': printf(" surface"); break;
513                  case 'w': printf(" weight"); break;
514 +                case 'W': printf(" coefficient"); break;
515                  case 'm': printf(" modifier"); break;
516 +                case 'M': printf(" material"); 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