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.30 by greg, Wed Aug 14 20:07:20 2019 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)) \
71                                  goto badopt
72 < #define  bool(olen,var)         switch (argv[i][olen]) { \
72 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
73                                  case '\0': var = !var; break; \
74                                  case 'y': case 'Y': case 't': case 'T': \
75                                  case '+': case '1': var = 1; break; \
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                                          /* option city */
93          for (i = 1; i < argc; i++) {
94                                                  /* expand arguments */
# Line 160 | Line 115 | char  *argv[];
115                          continue;
116                  }
117                  switch (argv[i][1]) {
118 +                case 'n':                               /* number of cores */
119 +                        check(2,"i");
120 +                        nproc = atoi(argv[++i]);
121 +                        if (nproc <= 0)
122 +                                error(USER, "bad number of processes");
123 +                        break;
124                  case 'x':                               /* x resolution */
125                          check(2,"i");
126                          hresolu = atoi(argv[++i]);
# Line 170 | Line 131 | char  *argv[];
131                          break;
132                  case 'w':                               /* warnings */
133                          rval = erract[WARNING].pf != NULL;
134 <                        bool(2,rval);
134 >                        check_bool(2,rval);
135                          if (rval) erract[WARNING].pf = wputs;
136                          else erract[WARNING].pf = NULL;
137                          break;
# Line 181 | Line 142 | char  *argv[];
142                  case 'l':                               /* limit distance */
143                          if (argv[i][2] != 'd')
144                                  goto badopt;
145 <                        bool(3,lim_dist);
145 >                        check_bool(3,lim_dist);
146                          break;
147                  case 'I':                               /* immed. irradiance */
148 <                        bool(2,imm_irrad);
148 >                        check_bool(2,imm_irrad);
149                          break;
150                  case 'f':                               /* format i/o */
151                          switch (argv[i][2]) {
# Line 216 | Line 177 | char  *argv[];
177                          break;
178                  case 'h':                               /* header output */
179                          rval = loadflags & IO_INFO;
180 <                        bool(2,rval);
180 >                        check_bool(2,rval);
181                          loadflags = rval ? loadflags | IO_INFO :
182                                          loadflags & ~IO_INFO;
183                          break;
# Line 230 | Line 191 | char  *argv[];
191                                          tralp = tralist;
192                                  }
193                                  if (argv[i][2] == 'I') {        /* file */
194 <                                        rval = wordfile(tralp,
195 <                                        getpath(argv[++i],getlibpath(),R_OK));
194 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
195 >                                        getpath(argv[++i],getrlibpath(),R_OK));
196                                          if (rval < 0) {
197                                                  sprintf(errmsg,
198                                  "cannot open trace include file \"%s\"",
# Line 252 | Line 213 | char  *argv[];
213                                          tralp = tralist;
214                                  }
215                                  if (argv[i][2] == 'E') {        /* file */
216 <                                        rval = wordfile(tralp,
217 <                                        getpath(argv[++i],getlibpath(),R_OK));
216 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
217 >                                        getpath(argv[++i],getrlibpath(),R_OK));
218                                          if (rval < 0) {
219                                                  sprintf(errmsg,
220                                  "cannot open trace exclude file \"%s\"",
# Line 286 | Line 247 | char  *argv[];
247                          goto badopt;
248                  }
249          }
250 +        if (nproc > 1) {
251 +                if (persist)
252 +                        error(USER, "multiprocessing incompatible with persist file");
253 +                if (!vresolu && hresolu > 0 && hresolu < nproc)
254 +                        error(WARNING, "number of cores should not exceed horizontal resolution");
255 +                if (trace != NULL)
256 +                        error(WARNING, "multiprocessing does not work properly with trace mode");
257 +        }
258                                          /* initialize object types */
259          initotypes();
260                                          /* initialize urand */
261 <        initurand(2048);
261 >        if (rand_samp) {
262 >                srandom((long)time(0));
263 >                initurand(0);
264 >        } else {
265 >                srandom(0L);
266 >                initurand(2048);
267 >        }
268                                          /* set up signal handling */
269          sigdie(SIGINT, "Interrupt");
270 + #ifdef SIGHUP
271          sigdie(SIGHUP, "Hangup");
272 + #endif
273          sigdie(SIGTERM, "Terminate");
274 + #ifdef SIGPIPE
275          sigdie(SIGPIPE, "Broken pipe");
276 + #endif
277 + #ifdef SIGALRM
278          sigdie(SIGALRM, "Alarm clock");
279 + #endif
280   #ifdef  SIGXCPU
281          sigdie(SIGXCPU, "CPU limit exceeded");
282          sigdie(SIGXFSZ, "File size exceeded");
# Line 315 | Line 296 | char  *argv[];
296   #endif
297                                          /* get octree */
298          if (i == argc)
299 <                octname = NULL;
299 >                octnm = NULL;
300          else if (i == argc-1)
301 <                octname = argv[i];
301 >                octnm = argv[i];
302          else
303                  goto badopt;
304 <        if (octname == NULL)
304 >        if (octnm == NULL)
305                  error(USER, "missing octree argument");
306                                          /* set up output */
307   #ifdef  PERSIST
# Line 329 | Line 310 | char  *argv[];
310                  openheader();
311          }
312   #endif
332 #ifdef  MSDOS
313          if (outform != 'a')
314 <                setmode(fileno(stdout), O_BINARY);
315 <        if (octname == NULL)
336 <                setmode(fileno(stdin), O_BINARY);
337 < #endif
338 <        readoct(octname, loadflags, &thescene, NULL);
314 >                SET_FILE_BINARY(stdout);
315 >        readoct(octname = octnm, loadflags, &thescene, NULL);
316          nsceneobjs = nobjects;
317  
318          if (loadflags & IO_INFO) {      /* print header */
319                  printargs(i, argv, stdout);
320                  printf("SOFTWARE= %s\n", VersionID);
321                  fputnow(stdout);
322 +                if ((outform == 'f') | (outform == 'd'))
323 +                        fputendian(stdout);
324                  fputformat(formstr(outform), stdout);
325                  putchar('\n');
326          }
327 <
327 >        
328 >        ray_init_pmap();     /* PMAP: set up & load photon maps */
329 >        
330          marksources();                  /* find and mark sources */
331  
332          setambient();                   /* initialize ambient calculation */
333 <
333 >        
334   #ifdef  PERSIST
335          if (persist) {
336                  fflush(stdout);
# Line 363 | Line 344 | char  *argv[];
344                          while ((rval=fork()) == 0) {    /* keep on forkin' */
345                                  pflock(1);
346                                  pfhold();
347 +                                ambsync();              /* load new values */
348                          }
349                          if (rval < 0)
350                                  error(SYSTEM, "cannot fork child for persist function");
351 <                        pfdetach();             /* parent exits */
351 >                        pfdetach();             /* parent will run then exit */
352                  }
353          }
354   runagain:
# Line 374 | Line 356 | runagain:
356                  dupheader();                    /* send header to stdout */
357   #endif
358                                          /* trace rays */
359 <        rtrace(NULL);
359 >        rtrace(NULL, nproc);
360                                          /* flush ambient file */
361          ambsync();
362   #ifdef  PERSIST
# Line 389 | Line 371 | runagain:
371                  }
372          }
373          if (persist == PCHILD) {        /* wait for a signal then go again */
392                close(duped1);                  /* release output handle */
374                  pfhold();
375                  raynum = nrays = 0;             /* reinitialize */
376                  goto runagain;
377          }
378   #endif
379 +
380 +        ray_done_pmap();           /* PMAP: free photon maps */
381 +        
382          quit(0);
383  
384   badopt:
385          sprintf(errmsg, "command line error at '%s'", argv[i]);
386          error(USER, errmsg);
387 +        return 1; /* pro forma return */
388  
389   #undef  check
390 < #undef  bool
390 > #undef  check_bool
391   }
392  
393  
394   void
395 < wputs(s)                                /* warning output function */
396 < char    *s;
395 > wputs(                          /* warning output function */
396 >        char    *s
397 > )
398   {
399          int  lasterrno = errno;
400          eputs(s);
# Line 417 | Line 403 | char   *s;
403  
404  
405   void
406 < eputs(s)                                /* put string to stderr */
407 < register char  *s;
406 > eputs(                          /* put string to stderr */
407 >        register char  *s
408 > )
409   {
410          static int  midline = 0;
411  
# Line 436 | Line 423 | register char  *s;
423   }
424  
425  
426 < void
427 < onsig(signo)                            /* fatal signal */
428 < int  signo;
426 > static void
427 > onsig(                          /* fatal signal */
428 >        int  signo
429 > )
430   {
431          static int  gotsig = 0;
432  
433          if (gotsig++)                   /* two signals and we're gone! */
434                  _exit(signo);
435  
436 + #ifdef SIGALRM
437          alarm(15);                      /* allow 15 seconds to clean up */
438          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
439 + #endif
440          eputs("signal - ");
441          eputs(sigerr[signo]);
442          eputs("\n");
# Line 454 | Line 444 | int  signo;
444   }
445  
446  
447 < void
448 < sigdie(signo, msg)                      /* set fatal signal */
449 < int  signo;
450 < char  *msg;
447 > static void
448 > sigdie(                 /* set fatal signal */
449 >        int  signo,
450 >        char  *msg
451 > )
452   {
453          if (signal(signo, onsig) == SIG_IGN)
454                  signal(signo, SIG_IGN);
# Line 465 | Line 456 | char  *msg;
456   }
457  
458  
459 < void
460 < printdefaults()                 /* print default values to stdout */
459 > static void
460 > printdefaults(void)                     /* print default values to stdout */
461   {
462          register char  *cp;
463  
464          if (imm_irrad)
465                  printf("-I+\t\t\t\t# immediate irradiance on\n");
466 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
467 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
466 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
467 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
468 >                        vresolu && hresolu ? "x resolution" : "flush interval");
469 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
470          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
471                          "-ld-\t\t\t\t# limit distance off\n");
472 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
473 +                        loadflags & IO_INFO ? "output" : "no");
474          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
475                          inform, outform, formstr(inform), formstr(outform));
476 <        printf("-o%s\t\t\t\t# output", outvals);
476 >        printf("-o%-9s\t\t\t# output", outvals);
477          for (cp = outvals; *cp; cp++)
478                  switch (*cp) {
479 <                case 't': printf(" trace"); break;
479 >                case 't': case 'T': printf(" trace"); break;
480                  case 'o': printf(" origin"); break;
481                  case 'd': printf(" direction"); break;
482 +                case 'r': printf(" reflect_contrib"); break;
483 +                case 'R': printf(" reflect_length"); break;
484 +                case 'x': printf(" unreflect_contrib"); break;
485 +                case 'X': printf(" unreflect_length"); break;
486                  case 'v': printf(" value"); break;
487 +                case 'V': printf(" contribution"); break;
488                  case 'l': printf(" length"); break;
489                  case 'L': printf(" first_length"); break;
490                  case 'p': printf(" point"); break;
# Line 492 | Line 492 | printdefaults()                        /* print default values to stdout */
492                  case 'N': printf(" unperturbed_normal"); break;
493                  case 's': printf(" surface"); break;
494                  case 'w': printf(" weight"); break;
495 +                case 'W': printf(" coefficient"); break;
496                  case 'm': printf(" modifier"); break;
497 +                case 'M': printf(" material"); break;
498 +                case '-': printf(" stroke"); break;
499                  }
500          putchar('\n');
501          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines