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.38 by greg, Wed Oct 19 21:25:20 2022 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(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 */
96 < extern int  inform;                     /* input format */
97 < extern int  outform;                    /* output format */
98 < extern char  *outvals;                  /* output values */
48 > extern int  castonly;                   /* 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();
111 < 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 + #ifdef PERSIST
70 + #define RTRACE_FEATURES "Persist\nParallelPersist\nMultiProcessing\n" \
71 +                        "IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \
72 +                        "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n"
73 + #else
74 + #define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \
75 +                        "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n"
76 + #endif
77 +
78 +
79   int
80 < main(argc, argv)
116 < int  argc;
117 < char  *argv[];
80 > main(int  argc, char  *argv[])
81   {
82   #define  check(ol,al)           if (argv[i][ol] || \
83                                  badarg(argc-i-1,argv+i+1,al)) \
84                                  goto badopt
85 < #define  bool(olen,var)         switch (argv[i][olen]) { \
85 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
86                                  case '\0': var = !var; break; \
87                                  case 'y': case 'Y': case 't': case 'T': \
88                                  case '+': case '1': var = 1; break; \
89                                  case 'n': case 'N': case 'f': case 'F': \
90                                  case '-': case '0': var = 0; break; \
91                                  default: goto badopt; }
92 <        int  loadflags = ~IO_FILES;
92 >        extern char  *octname;
93          int  persist = 0;
94 <        char  **tralp;
95 <        int  duped1;
94 >        char  *octnm = NULL;
95 >        char  **tralp = NULL;
96 >        int  duped1 = -1;
97          int  rval;
98          int  i;
99                                          /* global program name */
100          progname = argv[0] = fixargv0(argv[0]);
101 +                                        /* feature check only? */
102 +        strcat(RFeatureList, RTRACE_FEATURES);
103 +        if (!strcmp(argv[1], "-features"))
104 +                return feature_status(argc-2, argv+2);
105 +                                        /* add trace notify function */
106 +        for (i = 0; addobjnotify[i] != NULL; i++)
107 +                ;
108 +        addobjnotify[i] = tranotify;
109                                          /* option city */
110          for (i = 1; i < argc; i++) {
111                                                  /* expand arguments */
# Line 160 | Line 132 | char  *argv[];
132                          continue;
133                  }
134                  switch (argv[i][1]) {
135 +                case 'n':                               /* number of cores */
136 +                        check(2,"i");
137 +                        nproc = atoi(argv[++i]);
138 +                        if (nproc <= 0)
139 +                                error(USER, "bad number of processes");
140 +                        break;
141                  case 'x':                               /* x resolution */
142                          check(2,"i");
143                          hresolu = atoi(argv[++i]);
# Line 170 | Line 148 | char  *argv[];
148                          break;
149                  case 'w':                               /* warnings */
150                          rval = erract[WARNING].pf != NULL;
151 <                        bool(2,rval);
151 >                        check_bool(2,rval);
152                          if (rval) erract[WARNING].pf = wputs;
153                          else erract[WARNING].pf = NULL;
154                          break;
# Line 181 | Line 159 | char  *argv[];
159                  case 'l':                               /* limit distance */
160                          if (argv[i][2] != 'd')
161                                  goto badopt;
162 <                        bool(3,lim_dist);
162 >                        check_bool(3,lim_dist);
163                          break;
164                  case 'I':                               /* immed. irradiance */
165 <                        bool(2,imm_irrad);
165 >                        check_bool(2,imm_irrad);
166                          break;
167                  case 'f':                               /* format i/o */
168                          switch (argv[i][2]) {
# Line 216 | Line 194 | char  *argv[];
194                          break;
195                  case 'h':                               /* header output */
196                          rval = loadflags & IO_INFO;
197 <                        bool(2,rval);
197 >                        check_bool(2,rval);
198                          loadflags = rval ? loadflags | IO_INFO :
199                                          loadflags & ~IO_INFO;
200                          break;
# Line 230 | Line 208 | char  *argv[];
208                                          tralp = tralist;
209                                  }
210                                  if (argv[i][2] == 'I') {        /* file */
211 <                                        rval = wordfile(tralp,
212 <                                        getpath(argv[++i],getlibpath(),R_OK));
211 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
212 >                                        getpath(argv[++i],getrlibpath(),R_OK));
213                                          if (rval < 0) {
214                                                  sprintf(errmsg,
215                                  "cannot open trace include file \"%s\"",
# Line 252 | Line 230 | char  *argv[];
230                                          tralp = tralist;
231                                  }
232                                  if (argv[i][2] == 'E') {        /* file */
233 <                                        rval = wordfile(tralp,
234 <                                        getpath(argv[++i],getlibpath(),R_OK));
233 >                                        rval = wordfile(tralp, MAXMODLIST-(tralp-tralist),
234 >                                        getpath(argv[++i],getrlibpath(),R_OK));
235                                          if (rval < 0) {
236                                                  sprintf(errmsg,
237                                  "cannot open trace exclude file \"%s\"",
# Line 286 | Line 264 | char  *argv[];
264                          goto badopt;
265                  }
266          }
267 +        if (nproc > 1 && persist)
268 +                error(USER, "multiprocessing incompatible with persist file");
269                                          /* initialize object types */
270          initotypes();
271                                          /* initialize urand */
272 <        initurand(2048);
272 >        if (rand_samp) {
273 >                srandom((long)time(0));
274 >                initurand(0);
275 >        } else {
276 >                srandom(0L);
277 >                initurand(2048);
278 >        }
279                                          /* set up signal handling */
280          sigdie(SIGINT, "Interrupt");
281 + #ifdef SIGHUP
282          sigdie(SIGHUP, "Hangup");
283 + #endif
284          sigdie(SIGTERM, "Terminate");
285 + #ifdef SIGPIPE
286          sigdie(SIGPIPE, "Broken pipe");
287 + #endif
288 + #ifdef SIGALRM
289          sigdie(SIGALRM, "Alarm clock");
290 + #endif
291   #ifdef  SIGXCPU
292          sigdie(SIGXCPU, "CPU limit exceeded");
293          sigdie(SIGXFSZ, "File size exceeded");
# Line 315 | Line 307 | char  *argv[];
307   #endif
308                                          /* get octree */
309          if (i == argc)
310 <                octname = NULL;
310 >                octnm = NULL;
311          else if (i == argc-1)
312 <                octname = argv[i];
312 >                octnm = argv[i];
313          else
314                  goto badopt;
315 <        if (octname == NULL)
315 >        if (octnm == NULL)
316                  error(USER, "missing octree argument");
317                                          /* set up output */
318   #ifdef  PERSIST
# Line 329 | Line 321 | char  *argv[];
321                  openheader();
322          }
323   #endif
332 #ifdef  MSDOS
324          if (outform != 'a')
325 <                setmode(fileno(stdout), O_BINARY);
326 <        if (octname == NULL)
327 <                setmode(fileno(stdin), O_BINARY);
337 < #endif
338 <        readoct(octname, loadflags, &thescene, NULL);
325 >                SET_FILE_BINARY(stdout);
326 >        rval = setrtoutput();
327 >        readoct(octname = octnm, loadflags, &thescene, NULL);
328          nsceneobjs = nobjects;
329  
330          if (loadflags & IO_INFO) {      /* print header */
331                  printargs(i, argv, stdout);
332                  printf("SOFTWARE= %s\n", VersionID);
333                  fputnow(stdout);
334 +                if (rval > 0)           /* saved from setrtoutput() call */
335 +                        printf("NCOMP=%d\n", rval);
336 +                if ((outform == 'f') | (outform == 'd'))
337 +                        fputendian(stdout);
338                  fputformat(formstr(outform), stdout);
339                  putchar('\n');
340          }
341  
342 <        marksources();                  /* find and mark sources */
342 >        if (!castonly) {        /* any actual ray traversal to do? */
343  
344 <        setambient();                   /* initialize ambient calculation */
344 >                ray_init_pmap();        /* PMAP: set up & load photon maps */
345 >                
346 >                marksources();          /* find and mark sources */
347  
348 +                setambient();           /* initialize ambient calculation */
349 +        } else
350 +                distantsources();       /* else mark only distant sources */
351 +
352 +        fflush(stdout);                 /* in case we're duplicating header */
353 +
354   #ifdef  PERSIST
355          if (persist) {
355                fflush(stdout);
356                                                  /* reconnect stdout */
357                  dup2(duped1, fileno(stdout));
358                  close(duped1);
# Line 363 | Line 363 | char  *argv[];
363                          while ((rval=fork()) == 0) {    /* keep on forkin' */
364                                  pflock(1);
365                                  pfhold();
366 +                                ambsync();              /* load new values */
367                          }
368                          if (rval < 0)
369                                  error(SYSTEM, "cannot fork child for persist function");
370 <                        pfdetach();             /* parent exits */
370 >                        pfdetach();             /* parent will run then exit */
371                  }
372          }
373   runagain:
# Line 374 | Line 375 | runagain:
375                  dupheader();                    /* send header to stdout */
376   #endif
377                                          /* trace rays */
378 <        rtrace(NULL);
378 >        rtrace(NULL, nproc);
379                                          /* flush ambient file */
380          ambsync();
381   #ifdef  PERSIST
# Line 389 | Line 390 | runagain:
390                  }
391          }
392          if (persist == PCHILD) {        /* wait for a signal then go again */
392                close(duped1);                  /* release output handle */
393                  pfhold();
394                  raynum = nrays = 0;             /* reinitialize */
395                  goto runagain;
396          }
397   #endif
398 +
399 +        ray_done_pmap();           /* PMAP: free photon maps */
400 +        
401          quit(0);
402  
403   badopt:
404          sprintf(errmsg, "command line error at '%s'", argv[i]);
405          error(USER, errmsg);
406 +        return 1; /* pro forma return */
407  
408   #undef  check
409 < #undef  bool
409 > #undef  check_bool
410   }
411  
412  
413   void
414 < wputs(s)                                /* warning output function */
415 < char    *s;
414 > wputs(                          /* warning output function */
415 >        char    *s
416 > )
417   {
418          int  lasterrno = errno;
419          eputs(s);
# Line 417 | Line 422 | char   *s;
422  
423  
424   void
425 < eputs(s)                                /* put string to stderr */
426 < register char  *s;
425 > eputs(                          /* put string to stderr */
426 >        char  *s
427 > )
428   {
429          static int  midline = 0;
430  
# Line 436 | Line 442 | register char  *s;
442   }
443  
444  
445 < void
446 < onsig(signo)                            /* fatal signal */
447 < int  signo;
445 > static void
446 > onsig(                          /* fatal signal */
447 >        int  signo
448 > )
449   {
450          static int  gotsig = 0;
451  
452          if (gotsig++)                   /* two signals and we're gone! */
453                  _exit(signo);
454  
455 + #ifdef SIGALRM
456          alarm(15);                      /* allow 15 seconds to clean up */
457          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
458 + #endif
459          eputs("signal - ");
460          eputs(sigerr[signo]);
461          eputs("\n");
# Line 454 | Line 463 | int  signo;
463   }
464  
465  
466 < void
467 < sigdie(signo, msg)                      /* set fatal signal */
468 < int  signo;
469 < char  *msg;
466 > static void
467 > sigdie(                 /* set fatal signal */
468 >        int  signo,
469 >        char  *msg
470 > )
471   {
472          if (signal(signo, onsig) == SIG_IGN)
473                  signal(signo, SIG_IGN);
# Line 465 | Line 475 | char  *msg;
475   }
476  
477  
478 < void
479 < printdefaults()                 /* print default values to stdout */
478 > static void
479 > printdefaults(void)                     /* print default values to stdout */
480   {
481 <        register char  *cp;
481 >        char  *cp;
482  
483          if (imm_irrad)
484                  printf("-I+\t\t\t\t# immediate irradiance on\n");
485 <        printf("-x  %-9d\t\t\t# x resolution\n", hresolu);
486 <        printf("-y  %-9d\t\t\t# y resolution\n", vresolu);
485 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
486 >        printf("-x %-9d\t\t\t# %s\n", hresolu,
487 >                        vresolu && hresolu ? "x resolution" : "flush interval");
488 >        printf("-y %-9d\t\t\t# y resolution\n", vresolu);
489          printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
490                          "-ld-\t\t\t\t# limit distance off\n");
491 +        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-',
492 +                        loadflags & IO_INFO ? "output" : "no");
493          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
494                          inform, outform, formstr(inform), formstr(outform));
495 <        printf("-o%s\t\t\t\t# output", outvals);
495 >        printf("-o%-9s\t\t\t# output", outvals);
496          for (cp = outvals; *cp; cp++)
497                  switch (*cp) {
498 <                case 't': printf(" trace"); break;
498 >                case 't': case 'T': printf(" trace"); break;
499                  case 'o': printf(" origin"); break;
500                  case 'd': printf(" direction"); break;
501 +                case 'r': printf(" reflect_contrib"); break;
502 +                case 'R': printf(" reflect_length"); break;
503 +                case 'x': printf(" unreflect_contrib"); break;
504 +                case 'X': printf(" unreflect_length"); break;
505                  case 'v': printf(" value"); break;
506 +                case 'V': printf(" contribution"); break;
507                  case 'l': printf(" length"); break;
508                  case 'L': printf(" first_length"); break;
509                  case 'p': printf(" point"); break;
# Line 492 | Line 511 | printdefaults()                        /* print default values to stdout */
511                  case 'N': printf(" unperturbed_normal"); break;
512                  case 's': printf(" surface"); break;
513                  case 'w': printf(" weight"); break;
514 +                case 'W': printf(" coefficient"); break;
515                  case 'm': printf(" modifier"); break;
516 +                case 'M': printf(" material"); break;
517 +                case '~': printf(" tilde"); break;
518                  }
519          putchar('\n');
520          printf(erract[WARNING].pf != NULL ?

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines