home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / rayshade.lzh / ray_options.c < prev    next >
Text File  |  1990-09-06  |  7KB  |  266 lines

  1. /*
  2.  * ray_options.c
  3.  *
  4.  * Copyright (C) 1989, Craig E. Kolb
  5.  *
  6.  * This software may be freely copied, modified, and redistributed,
  7.  * provided that this copyright notice is preserved on all copies.
  8.  *
  9.  * There is no warranty or other guarantee of fitness for this software,
  10.  * it is provided solely .  Bug reports or fixes may be sent
  11.  * to the author, who may or may not act on them as he desires.
  12.  *
  13.  * You may not include this software in a program or other software product
  14.  * without supplying the source, or without informing the end-user that the
  15.  * source is available for no extra charge.
  16.  *
  17.  * If you modify this software, you should include a notice giving the
  18.  * name of the person performing the modification, the date of modification,
  19.  * and the reason for such modification.
  20.  *
  21.  * $Id: ray_options.c,v 3.0.1.5 90/02/12 13:28:19 craig Exp $
  22.  *
  23.  * $Log:    ray_options.c,v $
  24.  * Revision 3.0.1.5  90/02/12  13:28:19  craig
  25.  * patch4: Fixed typo in 'W' option error message.
  26.  * 
  27.  * Revision 3.0.1.4  89/12/06  16:33:55  craig
  28.  * patch2: Added calls to new error/warning routines.
  29.  * 
  30.  * Revision 3.0.1.3  89/12/02  16:42:16  craig
  31.  * patch2: Added -F option.
  32.  * 
  33.  * Revision 3.0.1.2  89/11/20  13:02:22  craig
  34.  * patch1: Fixed problems involving overriding values on the command line.
  35.  * 
  36.  * Revision 3.0.1.1  89/11/16  18:28:38  craig
  37.  * patch1: Added -w option.
  38.  * 
  39.  * Revision 3.0  89/10/27  02:06:00  craig
  40.  * Baseline for first official release.
  41.  * 
  42.  */
  43. #include <stdio.h>
  44. #ifdef SYSV
  45. #include <string.h>
  46. #else
  47. #include <strings.h>
  48. #endif
  49. #include "constants.h"
  50. #include "typedefs.h"
  51.  
  52. int Verbose;            /* Blabbering flag */
  53. int TrashBadPoly;        /* Discard even mildly bad polygons */
  54. int Quiet;            /* Don't be so verbose flag */
  55. char *progname;            /* argv[0] */
  56.  
  57. /*
  58.  * Flags indicating that options were set on the command line.
  59.  */
  60. int ResolutionSet, ContrastSet, SamplesSet, CutoffSet, AdaptiveSet, JitteredSet;
  61.  
  62. #ifdef LINDA
  63. int Workers;            /* # of workers */
  64. int VerboseWorker;
  65. #endif
  66.  
  67. parse_options(argc, argv)
  68. int argc;
  69. char **argv;
  70. {
  71.     extern char *infilename;
  72.     extern double RedContrast, GreenContrast, BlueContrast, atof();
  73.     extern int pixel_div, JitSamples, Xres, Yres, Jittered, Cache;
  74.     extern int Stereo, StartLine, Appending, NoShadows, ClearShadows;
  75.     extern int ReportFreq;
  76.     extern double Separation, TreeCutoff;
  77.     extern char outfilename[];
  78.     extern FILE *fstats;
  79.  
  80.     progname = argv[0];
  81.     fstats = stderr;
  82.  
  83.     while(--argc) {
  84.         argv++;
  85.         if(argv[0][0] != '-')
  86.             break;
  87.         switch(argv[0][1]) {
  88.             case 'C':
  89.                 RedContrast = atof(argv[1]);
  90.                 GreenContrast = atof(argv[2]);
  91.                 BlueContrast = atof(argv[3]);
  92.                 ContrastSet = TRUE;
  93.                 argv += 3;
  94.                 argc -= 3;
  95.                 break;
  96.             case 'c':
  97.                 ClearShadows = TRUE;
  98.                 break;
  99.             case 'E':
  100.                 Separation = atof(argv[1]);
  101.                 argc--; argv++;
  102.                 break;
  103.             case 'F':
  104.                 ReportFreq = atoi(argv[1]);
  105.                 if (ReportFreq < 1)
  106.                     ReportFreq = 1;
  107.                 argv++; argc--;
  108.                 break;
  109. #ifdef OSK
  110.            case '?':
  111. #endif
  112.             case 'h':
  113.                 usage();
  114.                 exit(0);
  115.                 break;
  116.             case 'j':
  117.                 Jittered = TRUE;
  118.                 JitteredSet = TRUE;
  119.                 break;
  120.             case 'L':
  121.                 StartLine = atoi(argv[1]);
  122.                 Appending = TRUE;
  123.                 argc--; argv++;
  124.                 break;
  125.             case 'l':
  126.                 Stereo = LEFT;
  127.                 break;
  128.             case 'n':
  129.                 NoShadows = TRUE;
  130.                 break;
  131.             case 'O':
  132.                 strcpy(outfilename, argv[1]);
  133.                 argv++;
  134.                 argc--;
  135.                 break;
  136.             case 'P':
  137.                 pixel_div = atoi(argv[1]);
  138.                 if(pixel_div < 0)
  139.                     pixel_div = 0;
  140.                 AdaptiveSet = TRUE;
  141.                 argv++;
  142.                 argc--;
  143.                 break;
  144.             case 'p':
  145.                 TrashBadPoly = TRUE;
  146.                 break;
  147.             case 'q':
  148.                 Quiet = TRUE;
  149.                 break;
  150.             case 'R':
  151.                 Xres = atoi(argv[1]);
  152.                 Yres = atoi(argv[2]);
  153.                 ResolutionSet = TRUE;
  154.                 argv += 2;
  155.                 argc -= 2;
  156.                 break;
  157.             case 'r':
  158.                 Stereo = RIGHT;
  159.                 break;
  160.             case 'S':
  161.                 JitSamples = atoi(argv[1]);
  162.                 if (JitSamples < 1)
  163.                     JitSamples = 1;
  164.                 SamplesSet = TRUE;
  165.                 argv++; argc--;
  166.                 break;
  167.             case 's':
  168.                 Cache = !Cache;
  169.                 break;
  170.             case 'T':
  171.                 TreeCutoff = atof(argv[1]);
  172.                 CutoffSet = TRUE;
  173.                 argv++; argc--;
  174.                 break;
  175.             case 'v':
  176.                 Verbose = TRUE;
  177.                 break;
  178.             case 'V':
  179.                 Verbose = TRUE;
  180.                 if (argv[1][0] == '-') {
  181.                     /* User probably blew it, and
  182.                      * it's difficult to remove a file
  183.                      * that begins with '-'...
  184.                      */
  185.                     usage();
  186.                     exit(2);
  187.                 }
  188.                 fstats = fopen(argv[1], "w");
  189.                 if (fstats == (FILE *)0) {
  190.                     RSerror("Cannot open stats file %s.\n",
  191.                             argv[0]);
  192.                 }
  193.                 argv++; argc--;
  194.                 break;
  195. #ifdef LINDA
  196.             case 'W':
  197.                 Workers = atoi(argv[1]);
  198.                 if (Workers < 0 || Workers > 17) {
  199.                     RSerror("%d workers?\n",Workers);
  200.                 }
  201.                 argv++; argc--;
  202.                 break;
  203.             case 'w':
  204.                 VerboseWorker = !VerboseWorker;
  205.                 break;
  206. #endif
  207.             default:
  208.                 RSerror("Bad argument: %s\n", argv[0]);
  209.         }
  210.     }
  211.  
  212.     if(argc > 1) {
  213.         usage();
  214.         exit(1);
  215.     } else if(argc == 1)
  216.         infilename = argv[0];
  217.     else
  218.         infilename = (char *)NULL;
  219.  
  220.     /*
  221.      * Although the user may have defined the output file name
  222.      * in the input file, it's best to force them to give a filename
  223.      * on the command line if using the -L option.  This saves situations
  224.      * where they forget to specify an output file to append to but
  225.      * aren't informed of it until startpic() is called (after the
  226.      * entire input file is read).
  227.      */
  228.     if (Appending && *outfilename == (char)NULL) {
  229.         RSerror("The -L option requires the -O option.\n");
  230.     }
  231.  
  232.     if (Stereo && Separation == 0.) {
  233.         RSerror("Stereo mode requires use of -E option.\n");
  234.     }
  235. }
  236.  
  237. usage()
  238. {
  239.     fprintf(stderr,"usage: %s [options] [filename]\n", progname);
  240.     fprintf(stderr,"Where options include:\n");
  241.     fprintf(stderr,"\t-C r g b\t(Set contrast threshold (0. - 1.).)\n");
  242.     fprintf(stderr,"\t-c \t\t(Trace shadow rays through clear objects.)\n");
  243.     fprintf(stderr,"\t-E eye_sep\t(Set eye separation.)\n");
  244.     fprintf(stderr,"\t-F freq\t\t(Frequency, in lines, of status report.)\n");
  245.     fprintf(stderr,"\t-h \t\t(Print this message.)\n");
  246.     fprintf(stderr,"\t-j \t\t(Antialias using jittered sampling.)\n");
  247.     fprintf(stderr,"\t-L line#\t(Begin rendering at specified line.)\n");
  248.     fprintf(stderr,"\t-l \t\t(Render image for left eye view.)\n");
  249.     fprintf(stderr,"\t-n \t\t(Don't compute shadows.)\n");
  250.     fprintf(stderr,"\t-O outfile \t(Specify output file name.)\n");
  251.     fprintf(stderr,"\t-P pixel_divs\t(Set max depth for adaptive supersampling.)\n");
  252.     fprintf(stderr,"\t-p \t\t(Discard polygons with degenerate edges.)\n");
  253.     fprintf(stderr,"\t-q \t\t(Run quietly.)\n");
  254.     fprintf(stderr,"\t-R xres yres\t(Render at given resolution.)\n");
  255.     fprintf(stderr,"\t-r \t\t(Render image for right eye view.)\n");
  256.     fprintf(stderr,"\t-S samples\t(Use samples^2 jittered samples.)\n");
  257.     fprintf(stderr,"\t-s \t\t(Don't cache shadowing information.)\n");
  258.     fprintf(stderr,"\t-T thresh\t(Set adaptive ray tree cutoff value.)\n");
  259.     fprintf(stderr,"\t-V filename \t(Write verbose output to filename.)\n");
  260.     fprintf(stderr,"\t-v \t\t(Verbose output.)\n");
  261. #ifdef LINDA
  262.     fprintf(stderr,"\t-W workers (Specify number of worker processes.)\n");
  263.     fprintf(stderr,"\t-w \t\t(Verbose worker output.)\n");
  264. #endif
  265. }
  266.