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.31 by greg, Sun Apr 5 15:47:02 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 > int  inform = 'a';                      /* input format */
41 > int  outform = 'a';                     /* output format */
42 > char  *outvals = "v";                   /* output specification */
43  
44 < char  *shm_boundary = NULL;             /* boundary of shared memory */
44 > int  hresolu = 0;                       /* horizontal (scan) size */
45 > int  vresolu = 0;                       /* vertical resolution */
46  
47 < char  *errfile = NULL;                  /* error output file */
47 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
48 > int  lim_dist = 0;                      /* limit distance? */
49  
50 < extern char  *formstr();                /* string from format */
51 < extern int  inform;                     /* input format */
52 < extern int  outform;                    /* output format */
41 < extern char  *outvals;                  /* output values */
50 > #ifndef MAXMODLIST
51 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
52 > #endif
53  
54 < extern int  hresolu;                    /* horizontal resolution */
55 < extern int  vresolu;                    /* vertical resolution */
54 > extern void  (*addobjnotify[])();       /* object notification calls */
55 > extern void  tranotify(OBJECT obj);
56  
57 < extern int  imm_irrad;                  /* compute immediate irradiance? */
58 < extern int  lim_dist;                   /* limit distance? */
57 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
58 > int  traincl = -1;                      /* include == 1, exclude == 0 */
59  
60 < extern char  *tralist[];                /* list of modifers to trace (or no) */
50 < extern int  traincl;                    /* include == 1, exclude == 0 */
60 > static int  loadflags = ~IO_FILES;      /* what to load from octree */
61  
62 < void    onsig(int);
63 < void    sigdie(int, char*);
64 < void    printdefaults(void);
62 > static void onsig(int  signo);
63 > static void sigdie(int  signo, char  *msg);
64 > static void printdefaults(void);
65  
66  
67   int
68 < main(argc, argv)
59 < int  argc;
60 < char  *argv[];
68 > main(int  argc, char  *argv[])
69   {
70   #define  check(ol,al)           if (argv[i][ol] || \
71                                  badarg(argc-i-1,argv+i+1,al)) \
72                                  goto badopt
73 < #define  bool(olen,var)         switch (argv[i][olen]) { \
73 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
74                                  case '\0': var = !var; break; \
75                                  case 'y': case 'Y': case 't': case 'T': \
76                                  case '+': case '1': var = 1; break; \
77                                  case 'n': case 'N': case 'f': case 'F': \
78                                  case '-': case '0': var = 0; break; \
79                                  default: goto badopt; }
80 <        int  loadflags = ~IO_FILES;
80 >        extern char  *octname;
81          int  persist = 0;
82 <        char  **tralp;
83 <        int  duped1;
82 >        char  *octnm = NULL;
83 >        char  **tralp = NULL;
84 >        int  duped1 = -1;
85          int  rval;
86          int  i;
87                                          /* global program name */
88          progname = argv[0] = fixargv0(argv[0]);
89 +                                        /* add trace notify function */
90 +        for (i = 0; addobjnotify[i] != NULL; i++)
91 +                ;
92 +        addobjnotify[i] = tranotify;
93                                          /* option city */
94          for (i = 1; i < argc; i++) {
95                                                  /* expand arguments */
# Line 103 | Line 116 | char  *argv[];
116                          continue;
117                  }
118                  switch (argv[i][1]) {
119 +                case 'n':                               /* number of cores */
120 +                        check(2,"i");
121 +                        nproc = atoi(argv[++i]);
122 +                        if (nproc <= 0)
123 +                                error(USER, "bad number of processes");
124 +                        break;
125                  case 'x':                               /* x resolution */
126                          check(2,"i");
127                          hresolu = atoi(argv[++i]);
# Line 113 | Line 132 | char  *argv[];
132                          break;
133                  case 'w':                               /* warnings */
134                          rval = erract[WARNING].pf != NULL;
135 <                        bool(2,rval);
135 >                        check_bool(2,rval);
136                          if (rval) erract[WARNING].pf = wputs;
137                          else erract[WARNING].pf = NULL;
138                          break;
# Line 124 | Line 143 | char  *argv[];
143                  case 'l':                               /* limit distance */
144                          if (argv[i][2] != 'd')
145                                  goto badopt;
146 <                        bool(3,lim_dist);
146 >                        check_bool(3,lim_dist);
147                          break;
148                  case 'I':                               /* immed. irradiance */
149 <                        bool(2,imm_irrad);
149 >                        check_bool(2,imm_irrad);
150                          break;
151                  case 'f':                               /* format i/o */
152                          switch (argv[i][2]) {
# Line 159 | Line 178 | char  *argv[];
178                          break;
179                  case 'h':                               /* header output */
180                          rval = loadflags & IO_INFO;
181 <                        bool(2,rval);
181 >                        check_bool(2,rval);
182                          loadflags = rval ? loadflags | IO_INFO :
183                                          loadflags & ~IO_INFO;
184                          break;
# Line 173 | Line 192 | char  *argv[];
192                                          tralp = tralist;
193                                  }
194                                  if (argv[i][2] == 'I') {        /* file */
195 <                                        rval = wordfile(tralp,
195 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
196                                          getpath(argv[++i],getrlibpath(),R_OK));
197                                          if (rval < 0) {
198                                                  sprintf(errmsg,
# Line 195 | Line 214 | char  *argv[];
214                                          tralp = tralist;
215                                  }
216                                  if (argv[i][2] == 'E') {        /* file */
217 <                                        rval = wordfile(tralp,
217 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
218                                          getpath(argv[++i],getrlibpath(),R_OK));
219                                          if (rval < 0) {
220                                                  sprintf(errmsg,
# Line 229 | Line 248 | char  *argv[];
248                          goto badopt;
249                  }
250          }
251 +        if (nproc > 1) {
252 +                if (persist)
253 +                        error(USER, "multiprocessing incompatible with persist file");
254 +                if (!vresolu && hresolu > 0 && hresolu < nproc)
255 +                        error(WARNING, "number of cores should not exceed horizontal resolution");
256 +                if (trace != NULL)
257 +                        error(WARNING, "multiprocessing does not work properly with trace mode");
258 +        }
259                                          /* initialize object types */
260          initotypes();
261                                          /* initialize urand */
262 <        initurand(2048);
262 >        if (rand_samp) {
263 >                srandom((long)time(0));
264 >                initurand(0);
265 >        } else {
266 >                srandom(0L);
267 >                initurand(2048);
268 >        }
269                                          /* set up signal handling */
270          sigdie(SIGINT, "Interrupt");
271   #ifdef SIGHUP
# Line 264 | Line 297 | char  *argv[];
297   #endif
298                                          /* get octree */
299          if (i == argc)
300 <                octname = NULL;
300 >                octnm = NULL;
301          else if (i == argc-1)
302 <                octname = argv[i];
302 >                octnm = argv[i];
303          else
304                  goto badopt;
305 <        if (octname == NULL)
305 >        if (octnm == NULL)
306                  error(USER, "missing octree argument");
307                                          /* set up output */
308   #ifdef  PERSIST
# Line 278 | Line 311 | char  *argv[];
311                  openheader();
312          }
313   #endif
281 #ifdef  _WIN32
314          if (outform != 'a')
315                  SET_FILE_BINARY(stdout);
316 <        if (octname == NULL)
317 <                SET_FILE_BINARY(stdin);
286 < #endif
287 <        readoct(octname, loadflags, &thescene, NULL);
316 >        rval = setrtoutput();
317 >        readoct(octname = octnm, loadflags, &thescene, NULL);
318          nsceneobjs = nobjects;
319  
320          if (loadflags & IO_INFO) {      /* print header */
321                  printargs(i, argv, stdout);
322                  printf("SOFTWARE= %s\n", VersionID);
323                  fputnow(stdout);
324 +                if (rval > 0)           /* saved from setrtoutput() call */
325 +                        printf("NCOMP=%d\n", rval);
326 +                if ((outform == 'f') | (outform == 'd'))
327 +                        fputendian(stdout);
328                  fputformat(formstr(outform), stdout);
329                  putchar('\n');
330          }
331 <
331 >        
332 >        ray_init_pmap();     /* PMAP: set up & load photon maps */
333 >        
334          marksources();                  /* find and mark sources */
335  
336          setambient();                   /* initialize ambient calculation */
337 <
337 >        
338   #ifdef  PERSIST
339          if (persist) {
340                  fflush(stdout);
# Line 312 | Line 348 | char  *argv[];
348                          while ((rval=fork()) == 0) {    /* keep on forkin' */
349                                  pflock(1);
350                                  pfhold();
351 +                                ambsync();              /* load new values */
352                          }
353                          if (rval < 0)
354                                  error(SYSTEM, "cannot fork child for persist function");
355 <                        pfdetach();             /* parent exits */
355 >                        pfdetach();             /* parent will run then exit */
356                  }
357          }
358   runagain:
# Line 323 | Line 360 | runagain:
360                  dupheader();                    /* send header to stdout */
361   #endif
362                                          /* trace rays */
363 <        rtrace(NULL);
363 >        rtrace(NULL, nproc);
364                                          /* flush ambient file */
365          ambsync();
366   #ifdef  PERSIST
# Line 338 | Line 375 | runagain:
375                  }
376          }
377          if (persist == PCHILD) {        /* wait for a signal then go again */
341                close(duped1);                  /* release output handle */
378                  pfhold();
379                  raynum = nrays = 0;             /* reinitialize */
380                  goto runagain;
381          }
382   #endif
383 +
384 +        ray_done_pmap();           /* PMAP: free photon maps */
385 +        
386          quit(0);
387  
388   badopt:
389          sprintf(errmsg, "command line error at '%s'", argv[i]);
390          error(USER, errmsg);
391 +        return 1; /* pro forma return */
392  
393   #undef  check
394 < #undef  bool
394 > #undef  check_bool
395   }
396  
397  
398   void
399 < wputs(s)                                /* warning output function */
400 < char    *s;
399 > wputs(                          /* warning output function */
400 >        char    *s
401 > )
402   {
403          int  lasterrno = errno;
404          eputs(s);
# Line 366 | Line 407 | char   *s;
407  
408  
409   void
410 < eputs(s)                                /* put string to stderr */
411 < register char  *s;
410 > eputs(                          /* put string to stderr */
411 >        register char  *s
412 > )
413   {
414          static int  midline = 0;
415  
# Line 385 | Line 427 | register char  *s;
427   }
428  
429  
430 < void
431 < onsig(signo)                            /* fatal signal */
432 < int  signo;
430 > static void
431 > onsig(                          /* fatal signal */
432 >        int  signo
433 > )
434   {
435          static int  gotsig = 0;
436  
# Line 405 | Line 448 | int  signo;
448   }
449  
450  
451 < void
452 < sigdie(signo, msg)                      /* set fatal signal */
453 < int  signo;
454 < char  *msg;
451 > static void
452 > sigdie(                 /* set fatal signal */
453 >        int  signo,
454 >        char  *msg
455 > )
456   {
457          if (signal(signo, onsig) == SIG_IGN)
458                  signal(signo, SIG_IGN);
# Line 416 | Line 460 | char  *msg;
460   }
461  
462  
463 < void
463 > static void
464   printdefaults(void)                     /* print default values to stdout */
465   {
466          register char  *cp;
467  
468          if (imm_irrad)
469                  printf("-I+\t\t\t\t# immediate irradiance on\n");
470 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
471 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
470 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
471 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
472 >                        vresolu && hresolu ? "x resolution" : "flush interval");
473 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
474          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
475                          "-ld-\t\t\t\t# limit distance off\n");
476 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
477 +                        loadflags & IO_INFO ? "output" : "no");
478          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
479                          inform, outform, formstr(inform), formstr(outform));
480 <        printf("-o%s\t\t\t\t# output", outvals);
480 >        printf("-o%-9s\t\t\t# output", outvals);
481          for (cp = outvals; *cp; cp++)
482                  switch (*cp) {
483 <                case 't': printf(" trace"); break;
483 >                case 't': case 'T': printf(" trace"); break;
484                  case 'o': printf(" origin"); break;
485                  case 'd': printf(" direction"); break;
486 +                case 'r': printf(" reflect_contrib"); break;
487 +                case 'R': printf(" reflect_length"); break;
488 +                case 'x': printf(" unreflect_contrib"); break;
489 +                case 'X': printf(" unreflect_length"); break;
490                  case 'v': printf(" value"); break;
491 +                case 'V': printf(" contribution"); break;
492                  case 'l': printf(" length"); break;
493                  case 'L': printf(" first_length"); break;
494                  case 'p': printf(" point"); break;
# Line 443 | Line 496 | printdefaults(void)                    /* print default values to stdou
496                  case 'N': printf(" unperturbed_normal"); break;
497                  case 's': printf(" surface"); break;
498                  case 'w': printf(" weight"); break;
499 +                case 'W': printf(" coefficient"); break;
500                  case 'm': printf(" modifier"); break;
501 +                case 'M': printf(" material"); break;
502 +                case '-': printf(" stroke"); break;
503                  }
504          putchar('\n');
505          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines