ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rvmain.c
(Generate patch)

Comparing ray/src/rt/rvmain.c (file contents):
Revision 2.1 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.26 by greg, Fri Jun 20 16:34:23 2025 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  rvmain.c - main for rview interactive viewer
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 > #include  <time.h>
12  
13 + #include  "platform.h"
14 + #include  "ray.h"
15   #include  "source.h"
68
16   #include  "ambient.h"
17 <
17 > #include  "rpaint.h"
18   #include  "random.h"
72
73 #include  "paths.h"
74
75 #include  <signal.h>
76
19   #include  "view.h"
20 + #include  "pmapray.h"
21  
22 < char  *progname;                        /* argv[0] */
22 > VIEW  ourview = STDVIEW;                /* viewing parameters */
23 > int  hresolu, vresolu;                  /* image resolution */
24  
25 < char  *octname;                         /* octree name */
25 > int  psample = 8;                       /* pixel sample size */
26 > double  maxdiff = .15;                  /* max. sample difference */
27  
28 < char  *sigerr[NSIG];                    /* signal error messages */
28 > int  greyscale = 0;                     /* map colors to brightness? */
29 > char  *dvcname = dev_default;           /* output device name */
30  
31 < char  *shm_boundary = NULL;             /* boundary of shared memory */
31 > double  exposure = 1.0;                 /* exposure for scene */
32  
33 < char  *errfile = NULL;                  /* error output file */
33 > int  newparam = 1;                      /* parameter setting changed */
34 >
35 > struct driver  *dev = NULL;             /* driver functions */
36  
37 < extern int  greyscale;                  /* map colors to brightness? */
90 < extern char  *dvcname;                  /* output device name */
91 < extern double  exposure;                /* exposure compensation */
37 > char  rifname[128];                     /* rad input file name */
38  
39 < extern VIEW  ourview;                   /* viewing parameters */
39 > VIEW  oldview;                          /* previous view parameters */
40  
41 < extern char  rifname[];                 /* rad input file name */
41 > PNODE  ptrunk;                          /* the base of our image */
42 > RECT  pframe;                           /* current frame boundaries */
43 > int  pdepth;                            /* image depth in current frame */
44  
45 < extern int  hresolu;                    /* horizontal resolution */
98 < extern int  vresolu;                    /* vertical resolution */
45 > char  *errfile = NULL;                  /* error output file */
46  
47 < extern int  psample;                    /* pixel sample size */
101 < extern double  maxdiff;                 /* max. sample difference */
47 > int  nproc = 1;                         /* number of processes */
48  
49 < void    onsig();
104 < void    sigdie();
105 < void    printdefaults();
49 > char  *sigerr[NSIG];                    /* signal error messages */
50  
51 + static void onsig(int  signo);
52 + static void sigdie(int  signo, char  *msg);
53 + static void printdefaults(void);
54  
55 + static void
56 + set_defaults(void)
57 + {
58 +        shadthresh = .1;
59 +        shadcert = .25;
60 +        directrelay = 0;
61 +        vspretest = 128;
62 +        srcsizerat = 0.;
63 +        specthresh = .3;
64 +        specjitter = 1.;
65 +        maxdepth = 6;
66 +        minweight = 1e-3;
67 +        ambacc = 0.3;
68 +        ambres = 32;
69 +        ambdiv = 256;
70 +        ambssamp = 64;
71 + }
72 +
73   int
74 < main(argc, argv)
110 < int  argc;
111 < char  *argv[];
74 > main(int argc, char *argv[])
75   {
76   #define  check(ol,al)           if (argv[i][ol] || \
77                                  badarg(argc-i-1,argv+i+1,al)) \
78                                  goto badopt
79 < #define  bool(olen,var)         switch (argv[i][olen]) { \
79 > #define  check_bool(olen,var)           switch (argv[i][olen]) { \
80                                  case '\0': var = !var; break; \
81                                  case 'y': case 'Y': case 't': case 'T': \
82                                  case '+': case '1': var = 1; break; \
83                                  case 'n': case 'N': case 'f': case 'F': \
84                                  case '-': case '0': var = 0; break; \
85                                  default: goto badopt; }
86 +        char  *octnm = NULL;
87          char  *err;
88          int  rval;
89          int  i;
90                                          /* global program name */
91          progname = argv[0] = fixargv0(argv[0]);
92 +                                        /* set our defaults */
93 +        set_defaults();
94                                          /* option city */
95          for (i = 1; i < argc; i++) {
96                                                  /* expand arguments */
# Line 160 | Line 126 | char  *argv[];
126                          continue;
127                  }
128                  switch (argv[i][1]) {
129 +                case 'n':                               /* # processes */
130 +                        check(2,"i");
131 +                        nproc = atoi(argv[++i]);
132 +                        if (nproc <= 0)
133 +                                error(USER, "bad number of processes");
134 +                        break;
135                  case 'v':                               /* view file */
136                          if (argv[i][2] != 'f')
137                                  goto badopt;
# Line 178 | Line 150 | char  *argv[];
150                          }
151                          break;
152                  case 'b':                               /* grayscale */
153 <                        bool(2,greyscale);
153 >                        check_bool(2,greyscale);
154                          break;
155                  case 'p':                               /* pixel */
156                          switch (argv[i][2]) {
# Line 202 | Line 174 | char  *argv[];
174                          break;
175                  case 'w':                               /* warnings */
176                          rval = erract[WARNING].pf != NULL;
177 <                        bool(2,rval);
177 >                        check_bool(2,rval);
178                          if (rval) erract[WARNING].pf = wputs;
179                          else erract[WARNING].pf = NULL;
180                          break;
# Line 222 | Line 194 | char  *argv[];
194                          goto badopt;
195                  }
196          }
197 +                                        /* set/check spectral sampling */
198 +        if (setspectrsamp(CNDX, WLPART) <= 0)
199 +                error(USER, "unsupported spectral sampling");
200 +
201          err = setview(&ourview);        /* set viewing parameters */
202          if (err != NULL)
203                  error(USER, err);
204 <                                        /* initialize object types */
229 <        initotypes();
230 <                                        /* initialize urand */
231 <        initurand(2048);
232 <                                        /* set up signal handling */
204 >                                                /* set up signal handling */
205          sigdie(SIGINT, "Interrupt");
234        sigdie(SIGHUP, "Hangup");
206          sigdie(SIGTERM, "Terminate");
207 + #if !defined(_WIN32) && !defined(_WIN64)
208 +        sigdie(SIGHUP, "Hangup");
209          sigdie(SIGPIPE, "Broken pipe");
210          sigdie(SIGALRM, "Alarm clock");
238 #ifdef  SIGXCPU
239        sigdie(SIGXCPU, "CPU limit exceeded");
240        sigdie(SIGXFSZ, "File size exceeded");
211   #endif
212                                          /* open error file */
213          if (errfile != NULL) {
# Line 254 | Line 224 | char  *argv[];
224   #endif
225                                          /* get octree */
226          if (i == argc)
227 <                octname = NULL;
227 >                octnm = NULL;
228          else if (i == argc-1)
229 <                octname = argv[i];
229 >                octnm = argv[i];
230          else
231                  goto badopt;
232 <        if (octname == NULL)
232 >        if (octnm == NULL)
233                  error(USER, "missing octree argument");
234 <                                        /* set up output */
235 < #ifdef  MSDOS
236 <        setmode(fileno(stdout), O_BINARY);
237 < #endif
238 <        readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL);
239 <        nsceneobjs = nobjects;
240 <
271 <        marksources();                  /* find and mark sources */
272 <
273 <        setambient();                   /* initialize ambient calculation */
274 <
234 >                                        /* set up output & start process(es) */
235 >        SET_FILE_BINARY(stdout);
236 >        
237 >        ray_init(octnm);                /* also calls ray_init_pmap() */
238 >        
239 > /* temporary shortcut, until winrview is refactored into a "device" */
240 > #ifndef WIN_RVIEW
241          rview();                        /* run interactive viewer */
242  
277        ambsync();                      /* flush ambient file */
243  
244 +        devclose();                     /* close output device */
245 + #endif
246 +
247 +        /* PMAP: free photon maps */
248 +        ray_done_pmap();
249 +        
250 + #ifdef WIN_RVIEW
251 +        return 1;
252 + #endif
253          quit(0);
254  
255   badopt:
256          sprintf(errmsg, "command line error at '%s'", argv[i]);
257          error(USER, errmsg);
258 +        return 1; /* pro forma return */
259  
260   #undef  check
261 < #undef  bool
261 > #undef  check_bool
262   }
263  
264  
265   void
266 < wputs(s)                                /* warning output function */
267 < char    *s;
266 > wputs(                          /* warning output function */
267 >        const char      *s
268 > )
269   {
270          int  lasterrno = errno;
271 +        if (erract[WARNING].pf == NULL)
272 +                return;         /* called by calcomp or someone */
273          eputs(s);
274          errno = lasterrno;
275   }
276  
277  
278   void
279 < eputs(s)                                /* put string to stderr */
280 < register char  *s;
279 > eputs(                          /* put string to stderr */
280 >        const char  *s
281 > )
282   {
283          static int  midline = 0;
284  
# Line 317 | Line 296 | register char  *s;
296   }
297  
298  
299 < void
300 < onsig(signo)                            /* fatal signal */
301 < int  signo;
299 > static void
300 > onsig(                          /* fatal signal */
301 >        int  signo
302 > )
303   {
304          static int  gotsig = 0;
305  
306          if (gotsig++)                   /* two signals and we're gone! */
307                  _exit(signo);
308  
309 + #if !defined(_WIN32) && !defined(_WIN64)
310          alarm(15);                      /* allow 15 seconds to clean up */
311          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
312 + #endif
313          eputs("signal - ");
314          eputs(sigerr[signo]);
315          eputs("\n");
316 +        devclose();
317          quit(3);
318   }
319  
320  
321 < void
322 < sigdie(signo, msg)                      /* set fatal signal */
323 < int  signo;
324 < char  *msg;
321 > static void
322 > sigdie(                 /* set fatal signal */
323 >        int  signo,
324 >        char  *msg
325 > )
326   {
327          if (signal(signo, onsig) == SIG_IGN)
328                  signal(signo, SIG_IGN);
# Line 346 | Line 330 | char  *msg;
330   }
331  
332  
333 < void
334 < printdefaults()                 /* print default values to stdout */
333 > static void
334 > printdefaults(void)                     /* print default values to stdout */
335   {
336 <        register char  *cp;
353 <
336 >        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
337          printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" :
338                          "-b-\t\t\t\t# greyscale off\n");
339          printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
# Line 359 | Line 342 | printdefaults()                        /* print default values to stdout */
342                          ourview.type==VT_HEM ? "hemispherical" :
343                          ourview.type==VT_ANG ? "angular" :
344                          ourview.type==VT_CYL ? "cylindrical" :
345 +                        ourview.type==VT_PLS ? "planisphere" :
346                          "unknown");
347          printf("-vp %f %f %f\t# view point\n",
348                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines