Back to index

radiance  4R0+20100331
renderopts.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: renderopts.c,v 2.13 2006/04/05 06:22:56 greg Exp $";
00003 #endif
00004 /*
00005  *  renderopts.c - process common rendering options
00006  *
00007  *  External symbols declared in ray.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include  "ray.h"
00013 #include  "paths.h"
00014 
00015 
00016 extern int
00017 getrenderopt(        /* get next render option */
00018        int  ac,
00019        char  *av[]
00020 )
00021 {
00022 #define        check(ol,al)        if (av[0][ol] || \
00023                             badarg(ac-1,av+1,al)) \
00024                             return(-1)
00025 #define        bool(olen,var)             switch (av[0][olen]) { \
00026                             case '\0': var = !var; break; \
00027                             case 'y': case 'Y': case 't': case 'T': \
00028                             case '+': case '1': var = 1; break; \
00029                             case 'n': case 'N': case 'f': case 'F': \
00030                             case '-': case '0': var = 0; break; \
00031                             default: return(-1); }
00032        static char  **amblp;              /* pointer to build ambient list */
00033        int    rval;
00034                                    /* is it even an option? */
00035        if (ac < 1 || av[0] == NULL || av[0][0] != '-')
00036               return(-1);
00037                                    /* check if it's one we know */
00038        switch (av[0][1]) {
00039        case 'u':                          /* uncorrelated sampling */
00040               bool(2,rand_samp);
00041               return(0);
00042        case 'b':                          /* back face vis. */
00043               if (av[0][2] == 'v') {
00044                      bool(3,backvis);
00045                      return(0);
00046               }
00047               break;
00048        case 'd':                          /* direct */
00049               switch (av[0][2]) {
00050               case 't':                          /* threshold */
00051                      check(3,"f");
00052                      shadthresh = atof(av[1]);
00053                      return(1);
00054               case 'c':                          /* certainty */
00055                      check(3,"f");
00056                      shadcert = atof(av[1]);
00057                      return(1);
00058               case 'j':                          /* jitter */
00059                      check(3,"f");
00060                      dstrsrc = atof(av[1]);
00061                      return(1);
00062               case 'r':                          /* relays */
00063                      check(3,"i");
00064                      directrelay = atoi(av[1]);
00065                      return(1);
00066               case 'p':                          /* pretest */
00067                      check(3,"i");
00068                      vspretest = atoi(av[1]);
00069                      return(1);
00070               case 'v':                          /* visibility */
00071                      bool(3,directvis);
00072                      return(0);
00073               case 's':                          /* size */
00074                      check(3,"f");
00075                      srcsizerat = atof(av[1]);
00076                      return(1);
00077               }
00078               break;
00079        case 's':                          /* specular */
00080               switch (av[0][2]) {
00081               case 't':                          /* threshold */
00082                      check(3,"f");
00083                      specthresh = atof(av[1]);
00084                      return(1);
00085               case 'j':                          /* jitter */
00086                      check(3,"f");
00087                      specjitter = atof(av[1]);
00088                      return(1);
00089               }
00090               break;
00091        case 'l':                          /* limit */
00092               switch (av[0][2]) {
00093               case 'r':                          /* recursion */
00094                      check(3,"i");
00095                      maxdepth = atoi(av[1]);
00096                      return(1);
00097               case 'w':                          /* weight */
00098                      check(3,"f");
00099                      minweight = atof(av[1]);
00100                      return(1);
00101               }
00102               break;
00103        case 'i':                          /* irradiance */
00104               bool(2,do_irrad);
00105               return(0);
00106        case 'a':                          /* ambient */
00107               switch (av[0][2]) {
00108               case 'v':                          /* value */
00109                      check(3,"fff");
00110                      setcolor(ambval, atof(av[1]),
00111                                    atof(av[2]),
00112                                    atof(av[3]));
00113                      return(3);
00114               case 'w':                          /* weight */
00115                      check(3,"i");
00116                      ambvwt = atoi(av[1]);
00117                      return(1);
00118               case 'a':                          /* accuracy */
00119                      check(3,"f");
00120                      ambacc = atof(av[1]);
00121                      return(1);
00122               case 'r':                          /* resolution */
00123                      check(3,"i");
00124                      ambres = atoi(av[1]);
00125                      return(1);
00126               case 'd':                          /* divisions */
00127                      check(3,"i");
00128                      ambdiv = atoi(av[1]);
00129                      return(1);
00130               case 's':                          /* super-samp */
00131                      check(3,"i");
00132                      ambssamp = atoi(av[1]);
00133                      return(1);
00134               case 'b':                          /* bounces */
00135                      check(3,"i");
00136                      ambounce = atoi(av[1]);
00137                      return(1);
00138               case 'i':                          /* include */
00139               case 'I':
00140                      check(3,"s");
00141                      if (ambincl != 1) {
00142                             ambincl = 1;
00143                             amblp = amblist;
00144                      }
00145                      if (av[0][2] == 'I') {      /* file */
00146                             rval = wordfile(amblp,
00147                                    getpath(av[1],getrlibpath(),R_OK));
00148                             if (rval < 0) {
00149                                    sprintf(errmsg,
00150                      "cannot open ambient include file \"%s\"", av[1]);
00151                                    error(SYSTEM, errmsg);
00152                             }
00153                             amblp += rval;
00154                      } else {
00155                             *amblp++ = savqstr(av[1]);
00156                             *amblp = NULL;
00157                      }
00158                      return(1);
00159               case 'e':                          /* exclude */
00160               case 'E':
00161                      check(3,"s");
00162                      if (ambincl != 0) {
00163                             ambincl = 0;
00164                             amblp = amblist;
00165                      }
00166                      if (av[0][2] == 'E') {      /* file */
00167                             rval = wordfile(amblp,
00168                                    getpath(av[1],getrlibpath(),R_OK));
00169                             if (rval < 0) {
00170                                    sprintf(errmsg,
00171                      "cannot open ambient exclude file \"%s\"", av[1]);
00172                                    error(SYSTEM, errmsg);
00173                             }
00174                             amblp += rval;
00175                      } else {
00176                             *amblp++ = savqstr(av[1]);
00177                             *amblp = NULL;
00178                      }
00179                      return(1);
00180               case 'f':                          /* file */
00181                      check(3,"s");
00182                      ambfile = savqstr(av[1]);
00183                      return(1);
00184               }
00185               break;
00186        case 'm':                          /* medium */
00187               switch (av[0][2]) {
00188               case 'e':                          /* extinction */
00189                      check(3,"fff");
00190                      setcolor(cextinction, atof(av[1]),
00191                                    atof(av[2]),
00192                                    atof(av[3]));
00193                      return(3);
00194               case 'a':                          /* albedo */
00195                      check(3,"fff");
00196                      setcolor(salbedo, atof(av[1]),
00197                                    atof(av[2]),
00198                                    atof(av[3]));
00199                      return(3);
00200               case 'g':                          /* eccentr. */
00201                      check(3,"f");
00202                      seccg = atof(av[1]);
00203                      return(1);
00204               case 's':                          /* sampling */
00205                      check(3,"f");
00206                      ssampdist = atof(av[1]);
00207                      return(1);
00208               }
00209               break;
00210        }
00211        return(-1);          /* unknown option */
00212 
00213 #undef check
00214 #undef bool
00215 }
00216 
00217 
00218 extern void
00219 print_rdefaults(void)              /* print default render values to stdout */
00220 {
00221        printf(do_irrad ? "-i+\t\t\t\t# irradiance calculation on\n" :
00222                      "-i-\t\t\t\t# irradiance calculation off\n");
00223        printf(rand_samp ? "-u+\t\t\t\t# uncorrelated Monte Carlo sampling\n" :
00224                      "-u-\t\t\t\t# correlated quasi-Monte Carlo sampling\n");
00225        printf(backvis ? "-bv+\t\t\t\t# back face visibility on\n" :
00226                      "-bv-\t\t\t\t# back face visibility off\n");
00227        printf("-dt %f\t\t\t# direct threshold\n", shadthresh);
00228        printf("-dc %f\t\t\t# direct certainty\n", shadcert);
00229        printf("-dj %f\t\t\t# direct jitter\n", dstrsrc);
00230        printf("-ds %f\t\t\t# direct sampling\n", srcsizerat);
00231        printf("-dr %-9d\t\t\t# direct relays\n", directrelay);
00232        printf("-dp %-9d\t\t\t# direct pretest density\n", vspretest);
00233        printf(directvis ? "-dv+\t\t\t\t# direct visibility on\n" :
00234                      "-dv-\t\t\t\t# direct visibility off\n");
00235        printf("-sj %f\t\t\t# specular jitter\n", specjitter);
00236        printf("-st %f\t\t\t# specular threshold\n", specthresh);
00237        printf("-av %f %f %f\t# ambient value\n", colval(ambval,RED),
00238                      colval(ambval,GRN), colval(ambval, BLU));
00239        printf("-aw %-9d\t\t\t# ambient value weight\n", ambvwt);
00240        printf("-ab %-9d\t\t\t# ambient bounces\n", ambounce);
00241        printf("-aa %f\t\t\t# ambient accuracy\n", ambacc);
00242        printf("-ar %-9d\t\t\t# ambient resolution\n", ambres);
00243        printf("-ad %-9d\t\t\t# ambient divisions\n", ambdiv);
00244        printf("-as %-9d\t\t\t# ambient super-samples\n", ambssamp);
00245        printf("-me %.2e %.2e %.2e\t# mist extinction coefficient\n",
00246                      colval(cextinction,RED),
00247                      colval(cextinction,GRN),
00248                      colval(cextinction,BLU));
00249        printf("-ma %f %f %f\t# mist scattering albedo\n", colval(salbedo,RED),
00250                      colval(salbedo,GRN), colval(salbedo,BLU));
00251        printf("-mg %f\t\t\t# mist scattering eccentricity\n", seccg);
00252        printf("-ms %f\t\t\t# mist sampling distance\n", ssampdist);
00253        printf("-lr %-9d\t\t\t# limit reflection%s\n", maxdepth,
00254                      maxdepth<=0 ? " (Russian roulette)" : "");
00255        printf("-lw %.2e\t\t\t# limit weight\n", minweight);
00256 }