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.1 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.25 by greg, Thu Apr 23 20:29:14 2015 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  rtmain.c - main for rtrace per-ray calculation program
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10 < #include  "ray.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"
68
17   #include  "ambient.h"
70
18   #include  "random.h"
72
19   #include  "paths.h"
20 + #include  "pmapray.h"
21  
22 < #include  <sys/types.h>
22 > extern char     *progname;              /* global argv[0] */
23  
24 < #include  <signal.h>
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 82 | 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();                /* string from format */
39 > int  inform = 'a';                      /* input format */
40 > int  outform = 'a';                     /* output format */
41 > char  *outvals = "v";                   /* output specification */
42  
43 < char  *shm_boundary = NULL;             /* boundary of shared memory */
43 > int  hresolu = 0;                       /* horizontal (scan) size */
44 > int  vresolu = 0;                       /* vertical resolution */
45  
46 < char  *errfile = NULL;                  /* error output file */
46 > int  imm_irrad = 0;                     /* compute immediate irradiance? */
47 > int  lim_dist = 0;                      /* limit distance? */
48  
49 < extern char  *formstr();                /* string from format */
50 < extern int  inform;                     /* input format */
51 < extern int  outform;                    /* output format */
98 < extern char  *outvals;                  /* output values */
49 > #ifndef MAXMODLIST
50 > #define MAXMODLIST      1024            /* maximum modifiers we'll track */
51 > #endif
52  
53 < extern int  hresolu;                    /* horizontal resolution */
54 < extern int  vresolu;                    /* vertical resolution */
53 > extern void  (*addobjnotify[])();       /* object notification calls */
54 > extern void  tranotify(OBJECT obj);
55  
56 < extern int  imm_irrad;                  /* compute immediate irradiance? */
57 < extern int  lim_dist;                   /* limit distance? */
56 > char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */
57 > int  traincl = -1;                      /* include == 1, exclude == 0 */
58  
59 < extern char  *tralist[];                /* list of modifers to trace (or no) */
107 < extern int  traincl;                    /* include == 1, exclude == 0 */
59 > static int  loadflags = ~IO_FILES;      /* what to load from octree */
60  
61 < void    onsig();
62 < void    sigdie();
63 < void    printdefaults();
61 > static void onsig(int  signo);
62 > static void sigdie(int  signo, char  *msg);
63 > static void printdefaults(void);
64  
65  
66   int
67 < main(argc, argv)
116 < int  argc;
117 < char  *argv[];
67 > main(int  argc, char  *argv[])
68   {
69   #define  check(ol,al)           if (argv[i][ol] || \
70                                  badarg(argc-i-1,argv+i+1,al)) \
# Line 126 | Line 76 | char  *argv[];
76                                  case 'n': case 'N': case 'f': case 'F': \
77                                  case '-': case '0': var = 0; break; \
78                                  default: goto badopt; }
79 <        int  loadflags = ~IO_FILES;
79 >        extern char  *octname;
80          int  persist = 0;
81 <        char  **tralp;
82 <        int  duped1;
81 >        char  *octnm = NULL;
82 >        char  **tralp = NULL;
83 >        int  duped1 = -1;
84          int  rval;
85          int  i;
86                                          /* global program name */
87          progname = argv[0] = fixargv0(argv[0]);
88 +                                        /* add trace notify function */
89 +        for (i = 0; addobjnotify[i] != NULL; i++)
90 +                ;
91 +        addobjnotify[i] = tranotify;
92 +                                        /* set our defaults */
93 +        rand_samp = 1;
94 +        maxdepth = -10;
95 +        minweight = 2e-3;
96                                          /* option city */
97          for (i = 1; i < argc; i++) {
98                                                  /* expand arguments */
# Line 160 | 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 231 | Line 196 | char  *argv[];
196                                  }
197                                  if (argv[i][2] == 'I') {        /* file */
198                                          rval = wordfile(tralp,
199 <                                        getpath(argv[++i],getlibpath(),R_OK));
199 >                                        getpath(argv[++i],getrlibpath(),R_OK));
200                                          if (rval < 0) {
201                                                  sprintf(errmsg,
202                                  "cannot open trace include file \"%s\"",
# Line 253 | Line 218 | char  *argv[];
218                                  }
219                                  if (argv[i][2] == 'E') {        /* file */
220                                          rval = wordfile(tralp,
221 <                                        getpath(argv[++i],getlibpath(),R_OK));
221 >                                        getpath(argv[++i],getrlibpath(),R_OK));
222                                          if (rval < 0) {
223                                                  sprintf(errmsg,
224                                  "cannot open trace exclude file \"%s\"",
# Line 286 | 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
275          sigdie(SIGHUP, "Hangup");
276 + #endif
277          sigdie(SIGTERM, "Terminate");
278 + #ifdef SIGPIPE
279          sigdie(SIGPIPE, "Broken pipe");
280 + #endif
281 + #ifdef SIGALRM
282          sigdie(SIGALRM, "Alarm clock");
283 + #endif
284   #ifdef  SIGXCPU
285          sigdie(SIGXCPU, "CPU limit exceeded");
286          sigdie(SIGXFSZ, "File size exceeded");
# Line 315 | 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 329 | Line 314 | char  *argv[];
314                  openheader();
315          }
316   #endif
332 #ifdef  MSDOS
317          if (outform != 'a')
318 <                setmode(fileno(stdout), O_BINARY);
319 <        if (octname == NULL)
336 <                setmode(fileno(stdin), O_BINARY);
337 < #endif
338 <        readoct(octname, loadflags, &thescene, NULL);
318 >                SET_FILE_BINARY(stdout);
319 >        readoct(octname = octnm, loadflags, &thescene, NULL);
320          nsceneobjs = nobjects;
321  
322          if (loadflags & IO_INFO) {      /* print header */
# Line 345 | Line 326 | char  *argv[];
326                  fputformat(formstr(outform), stdout);
327                  putchar('\n');
328          }
329 <
329 >        
330 >        ray_init_pmap();     /* PMAP: set up & load photon maps */
331 >        
332          marksources();                  /* find and mark sources */
333  
334          setambient();                   /* initialize ambient calculation */
335 <
335 >        
336   #ifdef  PERSIST
337          if (persist) {
338                  fflush(stdout);
# Line 363 | Line 346 | char  *argv[];
346                          while ((rval=fork()) == 0) {    /* keep on forkin' */
347                                  pflock(1);
348                                  pfhold();
349 +                                ambsync();              /* load new values */
350                          }
351                          if (rval < 0)
352                                  error(SYSTEM, "cannot fork child for persist function");
353 <                        pfdetach();             /* parent exits */
353 >                        pfdetach();             /* parent will run then exit */
354                  }
355          }
356   runagain:
# Line 374 | Line 358 | runagain:
358                  dupheader();                    /* send header to stdout */
359   #endif
360                                          /* trace rays */
361 <        rtrace(NULL);
361 >        rtrace(NULL, nproc);
362                                          /* flush ambient file */
363          ambsync();
364   #ifdef  PERSIST
# Line 389 | Line 373 | runagain:
373                  }
374          }
375          if (persist == PCHILD) {        /* wait for a signal then go again */
392                close(duped1);                  /* release output handle */
376                  pfhold();
377                  raynum = nrays = 0;             /* reinitialize */
378                  goto runagain;
379          }
380   #endif
381 +
382 +        ray_done_pmap();           /* PMAP: free photon maps */
383 +        
384          quit(0);
385  
386   badopt:
387          sprintf(errmsg, "command line error at '%s'", argv[i]);
388          error(USER, errmsg);
389 +        return 1; /* pro forma return */
390  
391   #undef  check
392   #undef  bool
# Line 407 | Line 394 | badopt:
394  
395  
396   void
397 < wputs(s)                                /* warning output function */
398 < char    *s;
397 > wputs(                          /* warning output function */
398 >        char    *s
399 > )
400   {
401          int  lasterrno = errno;
402          eputs(s);
# Line 417 | Line 405 | char   *s;
405  
406  
407   void
408 < eputs(s)                                /* put string to stderr */
409 < register char  *s;
408 > eputs(                          /* put string to stderr */
409 >        register char  *s
410 > )
411   {
412          static int  midline = 0;
413  
# Line 436 | Line 425 | register char  *s;
425   }
426  
427  
428 < void
429 < onsig(signo)                            /* fatal signal */
430 < int  signo;
428 > static void
429 > onsig(                          /* fatal signal */
430 >        int  signo
431 > )
432   {
433          static int  gotsig = 0;
434  
435          if (gotsig++)                   /* two signals and we're gone! */
436                  _exit(signo);
437  
438 + #ifdef SIGALRM
439          alarm(15);                      /* allow 15 seconds to clean up */
440          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
441 + #endif
442          eputs("signal - ");
443          eputs(sigerr[signo]);
444          eputs("\n");
# Line 454 | Line 446 | int  signo;
446   }
447  
448  
449 < void
450 < sigdie(signo, msg)                      /* set fatal signal */
451 < int  signo;
452 < char  *msg;
449 > static void
450 > sigdie(                 /* set fatal signal */
451 >        int  signo,
452 >        char  *msg
453 > )
454   {
455          if (signal(signo, onsig) == SIG_IGN)
456                  signal(signo, SIG_IGN);
# Line 465 | Line 458 | char  *msg;
458   }
459  
460  
461 < void
462 < printdefaults()                 /* print default values to stdout */
461 > static void
462 > printdefaults(void)                     /* print default values to stdout */
463   {
464          register char  *cp;
465  
466          if (imm_irrad)
467                  printf("-I+\t\t\t\t# immediate irradiance on\n");
468 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
469 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
468 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
469 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
470 >                        vresolu && hresolu ? "x resolution" : "flush interval");
471 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
472          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
473                          "-ld-\t\t\t\t# limit distance off\n");
474 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
475 +                        loadflags & IO_INFO ? "output" : "no");
476          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
477                          inform, outform, formstr(inform), formstr(outform));
478 <        printf("-o%s\t\t\t\t# output", outvals);
478 >        printf("-o%-9s\t\t\t# output", outvals);
479          for (cp = outvals; *cp; cp++)
480                  switch (*cp) {
481 <                case 't': printf(" trace"); break;
481 >                case 't': case 'T': printf(" trace"); break;
482                  case 'o': printf(" origin"); break;
483                  case 'd': printf(" direction"); break;
484                  case 'v': printf(" value"); break;
485 +                case 'V': printf(" contribution"); break;
486                  case 'l': printf(" length"); break;
487                  case 'L': printf(" first_length"); break;
488                  case 'p': printf(" point"); break;
# Line 492 | Line 490 | printdefaults()                        /* print default values to stdout */
490                  case 'N': printf(" unperturbed_normal"); break;
491                  case 's': printf(" surface"); break;
492                  case 'w': printf(" weight"); break;
493 +                case 'W': printf(" coefficient"); break;
494                  case 'm': printf(" modifier"); break;
495 +                case 'M': printf(" material"); break;
496 +                case '-': printf(" stroke"); break;
497                  }
498          putchar('\n');
499          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines