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.32 by greg, Mon Apr 6 04:10:44 2020 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 > int  castonly = 0;                      /* 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 +
70   int
71 < main(argc, argv)
59 < int  argc;
60 < char  *argv[];
71 > main(int  argc, char  *argv[])
72   {
73   #define  check(ol,al)           if (argv[i][ol] || \
74                                  badarg(argc-i-1,argv+i+1,al)) \
75                                  goto badopt
76 < #define  bool(olen,var)         switch (argv[i][olen]) { \
76 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
77                                  case '\0': var = !var; break; \
78                                  case 'y': case 'Y': case 't': case 'T': \
79                                  case '+': case '1': var = 1; break; \
80                                  case 'n': case 'N': case 'f': case 'F': \
81                                  case '-': case '0': var = 0; break; \
82                                  default: goto badopt; }
83 <        int  loadflags = ~IO_FILES;
83 >        extern char  *octname;
84          int  persist = 0;
85 <        char  **tralp;
86 <        int  duped1;
85 >        char  *octnm = NULL;
86 >        char  **tralp = NULL;
87 >        int  duped1 = -1;
88          int  rval;
89          int  i;
90                                          /* global program name */
91          progname = argv[0] = fixargv0(argv[0]);
92 +                                        /* add trace notify function */
93 +        for (i = 0; addobjnotify[i] != NULL; i++)
94 +                ;
95 +        addobjnotify[i] = tranotify;
96                                          /* option city */
97          for (i = 1; i < argc; i++) {
98                                                  /* expand arguments */
# Line 103 | Line 119 | char  *argv[];
119                          continue;
120                  }
121                  switch (argv[i][1]) {
122 +                case 'n':                               /* number of cores */
123 +                        check(2,"i");
124 +                        nproc = atoi(argv[++i]);
125 +                        if (nproc <= 0)
126 +                                error(USER, "bad number of processes");
127 +                        break;
128                  case 'x':                               /* x resolution */
129                          check(2,"i");
130                          hresolu = atoi(argv[++i]);
# Line 113 | Line 135 | char  *argv[];
135                          break;
136                  case 'w':                               /* warnings */
137                          rval = erract[WARNING].pf != NULL;
138 <                        bool(2,rval);
138 >                        check_bool(2,rval);
139                          if (rval) erract[WARNING].pf = wputs;
140                          else erract[WARNING].pf = NULL;
141                          break;
# Line 124 | Line 146 | char  *argv[];
146                  case 'l':                               /* limit distance */
147                          if (argv[i][2] != 'd')
148                                  goto badopt;
149 <                        bool(3,lim_dist);
149 >                        check_bool(3,lim_dist);
150                          break;
151                  case 'I':                               /* immed. irradiance */
152 <                        bool(2,imm_irrad);
152 >                        check_bool(2,imm_irrad);
153                          break;
154                  case 'f':                               /* format i/o */
155                          switch (argv[i][2]) {
# Line 159 | Line 181 | char  *argv[];
181                          break;
182                  case 'h':                               /* header output */
183                          rval = loadflags & IO_INFO;
184 <                        bool(2,rval);
184 >                        check_bool(2,rval);
185                          loadflags = rval ? loadflags | IO_INFO :
186                                          loadflags & ~IO_INFO;
187                          break;
# Line 173 | Line 195 | char  *argv[];
195                                          tralp = tralist;
196                                  }
197                                  if (argv[i][2] == 'I') {        /* file */
198 <                                        rval = wordfile(tralp,
198 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
199                                          getpath(argv[++i],getrlibpath(),R_OK));
200                                          if (rval < 0) {
201                                                  sprintf(errmsg,
# Line 195 | Line 217 | char  *argv[];
217                                          tralp = tralist;
218                                  }
219                                  if (argv[i][2] == 'E') {        /* file */
220 <                                        rval = wordfile(tralp,
220 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
221                                          getpath(argv[++i],getrlibpath(),R_OK));
222                                          if (rval < 0) {
223                                                  sprintf(errmsg,
# Line 229 | Line 251 | char  *argv[];
251                          goto badopt;
252                  }
253          }
254 +        if (nproc > 1) {
255 +                if (persist)
256 +                        error(USER, "multiprocessing incompatible with persist file");
257 +                if (!vresolu && hresolu > 0 && hresolu < nproc)
258 +                        error(WARNING, "number of cores should not exceed horizontal resolution");
259 +                if (trace != NULL)
260 +                        error(WARNING, "multiprocessing does not work properly with trace mode");
261 +        }
262                                          /* initialize object types */
263          initotypes();
264                                          /* initialize urand */
265 <        initurand(2048);
265 >        if (rand_samp) {
266 >                srandom((long)time(0));
267 >                initurand(0);
268 >        } else {
269 >                srandom(0L);
270 >                initurand(2048);
271 >        }
272                                          /* set up signal handling */
273          sigdie(SIGINT, "Interrupt");
274   #ifdef SIGHUP
# Line 264 | Line 300 | char  *argv[];
300   #endif
301                                          /* get octree */
302          if (i == argc)
303 <                octname = NULL;
303 >                octnm = NULL;
304          else if (i == argc-1)
305 <                octname = argv[i];
305 >                octnm = argv[i];
306          else
307                  goto badopt;
308 <        if (octname == NULL)
308 >        if (octnm == NULL)
309                  error(USER, "missing octree argument");
310                                          /* set up output */
311   #ifdef  PERSIST
# Line 278 | Line 314 | char  *argv[];
314                  openheader();
315          }
316   #endif
281 #ifdef  _WIN32
317          if (outform != 'a')
318                  SET_FILE_BINARY(stdout);
319 <        if (octname == NULL)
320 <                SET_FILE_BINARY(stdin);
286 < #endif
287 <        readoct(octname, loadflags, &thescene, NULL);
319 >        rval = setrtoutput();
320 >        readoct(octname = octnm, loadflags, &thescene, NULL);
321          nsceneobjs = nobjects;
322  
323          if (loadflags & IO_INFO) {      /* print header */
324                  printargs(i, argv, stdout);
325                  printf("SOFTWARE= %s\n", VersionID);
326                  fputnow(stdout);
327 +                if (rval > 0)           /* saved from setrtoutput() call */
328 +                        printf("NCOMP=%d\n", rval);
329 +                if ((outform == 'f') | (outform == 'd'))
330 +                        fputendian(stdout);
331                  fputformat(formstr(outform), stdout);
332                  putchar('\n');
333          }
334  
335 <        marksources();                  /* find and mark sources */
335 >        if (!castonly) {        /* any actual ray traversal to do? */
336  
337 <        setambient();                   /* initialize ambient calculation */
337 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
338 >                
339 >                marksources();          /* find and mark sources */
340  
341 +                setambient();           /* initialize ambient calculation */
342 +        }
343   #ifdef  PERSIST
344          if (persist) {
345                  fflush(stdout);
# Line 312 | Line 353 | char  *argv[];
353                          while ((rval=fork()) == 0) {    /* keep on forkin' */
354                                  pflock(1);
355                                  pfhold();
356 +                                ambsync();              /* load new values */
357                          }
358                          if (rval < 0)
359                                  error(SYSTEM, "cannot fork child for persist function");
360 <                        pfdetach();             /* parent exits */
360 >                        pfdetach();             /* parent will run then exit */
361                  }
362          }
363   runagain:
# Line 323 | Line 365 | runagain:
365                  dupheader();                    /* send header to stdout */
366   #endif
367                                          /* trace rays */
368 <        rtrace(NULL);
368 >        rtrace(NULL, nproc);
369                                          /* flush ambient file */
370          ambsync();
371   #ifdef  PERSIST
# Line 338 | Line 380 | runagain:
380                  }
381          }
382          if (persist == PCHILD) {        /* wait for a signal then go again */
341                close(duped1);                  /* release output handle */
383                  pfhold();
384                  raynum = nrays = 0;             /* reinitialize */
385                  goto runagain;
386          }
387   #endif
388 +
389 +        ray_done_pmap();           /* PMAP: free photon maps */
390 +        
391          quit(0);
392  
393   badopt:
394          sprintf(errmsg, "command line error at '%s'", argv[i]);
395          error(USER, errmsg);
396 +        return 1; /* pro forma return */
397  
398   #undef  check
399 < #undef  bool
399 > #undef  check_bool
400   }
401  
402  
403   void
404 < wputs(s)                                /* warning output function */
405 < char    *s;
404 > wputs(                          /* warning output function */
405 >        char    *s
406 > )
407   {
408          int  lasterrno = errno;
409          eputs(s);
# Line 366 | Line 412 | char   *s;
412  
413  
414   void
415 < eputs(s)                                /* put string to stderr */
416 < register char  *s;
415 > eputs(                          /* put string to stderr */
416 >        register char  *s
417 > )
418   {
419          static int  midline = 0;
420  
# Line 385 | Line 432 | register char  *s;
432   }
433  
434  
435 < void
436 < onsig(signo)                            /* fatal signal */
437 < int  signo;
435 > static void
436 > onsig(                          /* fatal signal */
437 >        int  signo
438 > )
439   {
440          static int  gotsig = 0;
441  
# Line 405 | Line 453 | int  signo;
453   }
454  
455  
456 < void
457 < sigdie(signo, msg)                      /* set fatal signal */
458 < int  signo;
459 < char  *msg;
456 > static void
457 > sigdie(                 /* set fatal signal */
458 >        int  signo,
459 >        char  *msg
460 > )
461   {
462          if (signal(signo, onsig) == SIG_IGN)
463                  signal(signo, SIG_IGN);
# Line 416 | Line 465 | char  *msg;
465   }
466  
467  
468 < void
469 < printdefaults()                 /* print default values to stdout */
468 > static void
469 > printdefaults(void)                     /* print default values to stdout */
470   {
471          register char  *cp;
472  
473          if (imm_irrad)
474                  printf("-I+\t\t\t\t# immediate irradiance on\n");
475 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
476 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
475 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
476 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
477 >                        vresolu && hresolu ? "x resolution" : "flush interval");
478 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
479          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
480                          "-ld-\t\t\t\t# limit distance off\n");
481 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
482 +                        loadflags & IO_INFO ? "output" : "no");
483          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
484                          inform, outform, formstr(inform), formstr(outform));
485 <        printf("-o%s\t\t\t\t# output", outvals);
485 >        printf("-o%-9s\t\t\t# output", outvals);
486          for (cp = outvals; *cp; cp++)
487                  switch (*cp) {
488 <                case 't': printf(" trace"); break;
488 >                case 't': case 'T': printf(" trace"); break;
489                  case 'o': printf(" origin"); break;
490                  case 'd': printf(" direction"); break;
491 +                case 'r': printf(" reflect_contrib"); break;
492 +                case 'R': printf(" reflect_length"); break;
493 +                case 'x': printf(" unreflect_contrib"); break;
494 +                case 'X': printf(" unreflect_length"); break;
495                  case 'v': printf(" value"); break;
496 +                case 'V': printf(" contribution"); break;
497                  case 'l': printf(" length"); break;
498                  case 'L': printf(" first_length"); break;
499                  case 'p': printf(" point"); break;
# Line 443 | Line 501 | printdefaults()                        /* print default values to stdout */
501                  case 'N': printf(" unperturbed_normal"); break;
502                  case 's': printf(" surface"); break;
503                  case 'w': printf(" weight"); break;
504 +                case 'W': printf(" coefficient"); break;
505                  case 'm': printf(" modifier"); break;
506 +                case 'M': printf(" material"); break;
507 +                case '-': printf(" stroke"); break;
508                  }
509          putchar('\n');
510          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines