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.6 by schorsch, Mon Jun 30 14:59:12 2003 UTC vs.
Revision 2.19 by greg, Sun Dec 13 19:13:04 2009 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>
12 #ifdef _WIN32
13 #include <process.h> /* getpid() */
14 #endif
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  
21 + extern char     *progname;              /* global argv[0] */
22 +
23 + extern char     *shm_boundary;          /* boundary of shared memory */
24 +
25                                          /* persistent processes define */
26   #ifdef  F_SETLKW
27   #define  PERSIST        1               /* normal persist */
# Line 27 | Line 29 | static const char      RCSid[] = "$Id$";
29   #define  PCHILD         3               /* child of normal persist */
30   #endif
31  
32 < char  *progname;                        /* argv[0] */
32 > char  *sigerr[NSIG];                    /* signal error messages */
33 > char  *errfile = NULL;                  /* error output file */
34  
35 < char  *octname;                         /* octree name */
35 > int  nproc = 1;                         /* number of processes */
36  
37 < char  *sigerr[NSIG];                    /* signal error messages */
37 > extern char  *formstr();                /* string from format */
38 > int  inform = 'a';                      /* input format */
39 > int  outform = 'a';                     /* output format */
40 > char  *outvals = "v";                   /* output specification */
41  
42 < char  *shm_boundary = NULL;             /* boundary of shared memory */
42 > int  hresolu = 0;                       /* horizontal (scan) size */
43 > int  vresolu = 0;                       /* vertical resolution */
44  
45 < char  *errfile = NULL;                  /* error output file */
45 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
46 > int  lim_dist = 0;                      /* limit distance? */
47  
48 < extern char  *formstr();                /* string from format */
49 < extern int  inform;                     /* input format */
50 < extern int  outform;                    /* output format */
43 < extern char  *outvals;                  /* output values */
48 > #ifndef MAXMODLIST
49 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
50 > #endif
51  
52 < extern int  hresolu;                    /* horizontal resolution */
53 < extern int  vresolu;                    /* vertical resolution */
52 > extern void  (*addobjnotify[])();       /* object notification calls */
53 > extern void  tranotify(OBJECT obj);
54  
55 < extern int  imm_irrad;                  /* compute immediate irradiance? */
56 < extern int  lim_dist;                   /* limit distance? */
55 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
56 > int  traincl = -1;                      /* include == 1, exclude == 0 */
57  
58 < extern char  *tralist[];                /* list of modifers to trace (or no) */
52 < extern int  traincl;                    /* include == 1, exclude == 0 */
58 > static int  loadflags = ~IO_FILES;      /* what to load from octree */
59  
60 < void    onsig();
61 < void    sigdie();
62 < void    printdefaults();
60 > static void onsig(int  signo);
61 > static void sigdie(int  signo, char  *msg);
62 > static void printdefaults(void);
63  
64  
65   int
66 < main(argc, argv)
61 < int  argc;
62 < char  *argv[];
66 > main(int  argc, char  *argv[])
67   {
68   #define  check(ol,al)           if (argv[i][ol] || \
69                                  badarg(argc-i-1,argv+i+1,al)) \
# Line 71 | Line 75 | char  *argv[];
75                                  case 'n': case 'N': case 'f': case 'F': \
76                                  case '-': case '0': var = 0; break; \
77                                  default: goto badopt; }
74        int  loadflags = ~IO_FILES;
78          int  persist = 0;
79 +        char  *octnm = NULL;
80          char  **tralp;
81          int  duped1;
82          int  rval;
83          int  i;
84                                          /* global program name */
85          progname = argv[0] = fixargv0(argv[0]);
86 +                                        /* add trace notify function */
87 +        for (i = 0; addobjnotify[i] != NULL; i++)
88 +                ;
89 +        addobjnotify[i] = tranotify;
90 +                                        /* set our defaults */
91 +        maxdepth = -10;
92 +        minweight = 2e-3;
93                                          /* option city */
94          for (i = 1; i < argc; i++) {
95                                                  /* expand arguments */
# Line 105 | 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 231 | 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 (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 266 | 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 280 | Line 311 | char  *argv[];
311                  openheader();
312          }
313   #endif
283 #ifdef  _WIN32
314          if (outform != 'a')
315                  SET_FILE_BINARY(stdout);
316 <        if (octname == NULL)
287 <                SET_FILE_BINARY(stdin);
288 < #endif
289 <        readoct(octname, loadflags, &thescene, NULL);
316 >        readoct(octnm, loadflags, &thescene, NULL);
317          nsceneobjs = nobjects;
318  
319          if (loadflags & IO_INFO) {      /* print header */
# Line 314 | Line 341 | char  *argv[];
341                          while ((rval=fork()) == 0) {    /* keep on forkin' */
342                                  pflock(1);
343                                  pfhold();
344 +                                ambsync();              /* load new values */
345                          }
346                          if (rval < 0)
347                                  error(SYSTEM, "cannot fork child for persist function");
348 <                        pfdetach();             /* parent exits */
348 >                        pfdetach();             /* parent will run then exit */
349                  }
350          }
351   runagain:
# Line 325 | Line 353 | runagain:
353                  dupheader();                    /* send header to stdout */
354   #endif
355                                          /* trace rays */
356 <        rtrace(NULL);
356 >        rtrace(NULL, nproc);
357                                          /* flush ambient file */
358          ambsync();
359   #ifdef  PERSIST
# Line 340 | Line 368 | runagain:
368                  }
369          }
370          if (persist == PCHILD) {        /* wait for a signal then go again */
343                close(duped1);                  /* release output handle */
371                  pfhold();
372                  raynum = nrays = 0;             /* reinitialize */
373                  goto runagain;
# Line 351 | Line 378 | runagain:
378   badopt:
379          sprintf(errmsg, "command line error at '%s'", argv[i]);
380          error(USER, errmsg);
381 +        return 1; /* pro forma return */
382  
383   #undef  check
384   #undef  bool
# Line 358 | Line 386 | badopt:
386  
387  
388   void
389 < wputs(s)                                /* warning output function */
390 < char    *s;
389 > wputs(                          /* warning output function */
390 >        char    *s
391 > )
392   {
393          int  lasterrno = errno;
394          eputs(s);
# Line 368 | Line 397 | char   *s;
397  
398  
399   void
400 < eputs(s)                                /* put string to stderr */
401 < register char  *s;
400 > eputs(                          /* put string to stderr */
401 >        register char  *s
402 > )
403   {
404          static int  midline = 0;
405  
# Line 387 | Line 417 | register char  *s;
417   }
418  
419  
420 < void
421 < onsig(signo)                            /* fatal signal */
422 < int  signo;
420 > static void
421 > onsig(                          /* fatal signal */
422 >        int  signo
423 > )
424   {
425          static int  gotsig = 0;
426  
# Line 407 | Line 438 | int  signo;
438   }
439  
440  
441 < void
442 < sigdie(signo, msg)                      /* set fatal signal */
443 < int  signo;
444 < char  *msg;
441 > static void
442 > sigdie(                 /* set fatal signal */
443 >        int  signo,
444 >        char  *msg
445 > )
446   {
447          if (signal(signo, onsig) == SIG_IGN)
448                  signal(signo, SIG_IGN);
# Line 418 | Line 450 | char  *msg;
450   }
451  
452  
453 < void
454 < printdefaults()                 /* print default values to stdout */
453 > static void
454 > printdefaults(void)                     /* print default values to stdout */
455   {
456          register char  *cp;
457  
458          if (imm_irrad)
459                  printf("-I+\t\t\t\t# immediate irradiance on\n");
460 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
461 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
460 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
461 >        printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu);
462 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
463          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
464                          "-ld-\t\t\t\t# limit distance off\n");
465 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
466 +                        loadflags & IO_INFO ? "output" : "no");
467          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
468                          inform, outform, formstr(inform), formstr(outform));
469 <        printf("-o%s\t\t\t\t# output", outvals);
469 >        printf("-o%-9s\t\t\t# output", outvals);
470          for (cp = outvals; *cp; cp++)
471                  switch (*cp) {
472 <                case 't': printf(" trace"); break;
472 >                case 't': case 'T': printf(" trace"); break;
473                  case 'o': printf(" origin"); break;
474                  case 'd': printf(" direction"); break;
475                  case 'v': printf(" value"); break;
476 +                case 'V': printf(" contribution"); break;
477                  case 'l': printf(" length"); break;
478                  case 'L': printf(" first_length"); break;
479                  case 'p': printf(" point"); break;
# Line 445 | Line 481 | printdefaults()                        /* print default values to stdout */
481                  case 'N': printf(" unperturbed_normal"); break;
482                  case 's': printf(" surface"); break;
483                  case 'w': printf(" weight"); break;
484 +                case 'W': printf(" coefficient"); break;
485                  case 'm': printf(" modifier"); break;
486 +                case 'M': printf(" material"); break;
487 +                case '-': printf(" stroke"); break;
488                  }
489          putchar('\n');
490          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines