home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / options.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-27  |  5.0 KB  |  195 lines

  1. /*
  2.  * Options.C
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #include <stdlib.h>
  19. #include "Options.h"
  20. #include "Expression.h"
  21. #include "Hull.h"
  22.  
  23. //___________________________________________________________ Options
  24.  
  25. static void usage(const rcString&);
  26. Options theOptions;
  27.  
  28. Options::Options()
  29. : iname("cin"), oname("cout"), optionsForCPP(" "),
  30.   resX(400), resY(400),
  31.   eye(0,1,0), lookat(0,0,0), up(0,0,1), fov(45.0)
  32. {
  33. #ifdef SUPPORT_X11
  34.   drivername = "x11simple";
  35. #else
  36.   drivername = "example";
  37. #endif
  38.  
  39.   verbose        = 0;
  40.   quiet          = 0;
  41.   printlsys      = 0;
  42.   printModules   = 0;
  43.   deleteModules  = 0;
  44.   autoscale      = 1;
  45.   coneSpheres    = 0;
  46.   showHulls      = 0;
  47.  
  48.   coneResolution   = -1; // use default resolutions
  49.   sphereResolution = -1;
  50.  
  51.   defaultForward = 10;
  52.   defaultPitch   = dtor(45);
  53.   defaultTurn    = dtor(45);
  54.   defaultRoll    = dtor(45);
  55.  
  56.   tropismX = NULL;
  57.   tropismY = NULL;
  58.   tropismZ = NULL;
  59.   weight   = NULL;
  60.   hulls    = NULL;
  61. }
  62.  
  63. void parseOptions(int argc, char** argv)
  64. {
  65.   rcString progname = argv[0];
  66.  
  67.   while (--argc) {
  68.     argv++;  
  69.  
  70.     if (argv[0][0] != '-')
  71.       break;
  72.  
  73.     switch(argv[0][1]) {
  74.     case 'O':
  75.       if (argc < 2) usage(progname);
  76.       theOptions.oname = argv[1];
  77.       argv++;
  78.       argc--;
  79.       break;
  80.     case 'D':
  81.       theOptions.optionsForCPP = theOptions.optionsForCPP 
  82.                                  + " " + argv[0];
  83.       break;
  84.     case 'd':
  85.       if (argc < 2) usage(progname);
  86.       theOptions.drivername = argv[1];
  87.       argv++;
  88.       argc--;
  89.       break;
  90.     case 'v':
  91.       theOptions.verbose = 1;
  92.       break;
  93.     case 'q':
  94.       theOptions.quiet = 1;
  95.       theOptions.verbose = 0;
  96.       theOptions.printlsys = 0;
  97.       theOptions.printModules = 0;
  98.       break;
  99.     case 'l':
  100.       theOptions.printlsys = 1;
  101.       break;
  102.     case 'p':
  103.       theOptions.printModules = 1;
  104.       break;
  105.     case 'e':
  106.       theOptions.deleteModules = 1;
  107.       break;
  108.     case 'R':
  109.       if (argc < 3) usage(progname);
  110.       theOptions.resX = atoi(argv[1]);
  111.       theOptions.resY = atoi(argv[2]);
  112.       argv += 2;
  113.       argc -= 2;
  114.       break;
  115.     case 'E':
  116.       if (argc < 4) usage(progname);
  117.       theOptions.eye = Vector(atof(argv[1]), atof(argv[2]), atof(argv[3]));
  118.       argv += 3;
  119.       argc -= 3;
  120.       theOptions.autoscale = 0;
  121.       break;
  122.     case 'L':
  123.       if (argc < 4) usage(progname);
  124.       theOptions.lookat = Vector(atof(argv[1]), atof(argv[2]), atof(argv[3]));
  125.       argv += 3;
  126.       argc -= 3;
  127.       theOptions.autoscale = 0;
  128.       break;
  129.     case 'U':
  130.       if (argc < 4) usage(progname);
  131.       theOptions.up = Vector(atof(argv[1]), atof(argv[2]), atof(argv[3]));
  132.       argv += 3;
  133.       argc -= 3;
  134.       break;
  135.     case 'f':
  136.       if (argc < 2) usage(progname);
  137.       theOptions.fov = atoi(argv[1]);
  138.       argv += 1;
  139.       argc -= 1;
  140.       break;
  141.     case 'c':
  142.       theOptions.coneSpheres = 1;
  143.       break;
  144.     case 's':
  145.       theOptions.showHulls = 1;
  146.       break;
  147.     case 'h':
  148.       usage(progname);
  149.       break;
  150.     default:
  151.       cerr << "Unrecognized option " << argv[0] << "\n";
  152.       usage(progname);
  153.     }
  154.   }  
  155.   
  156.   if (argc == 1)
  157.     theOptions.iname = argv[0];
  158.   else if (argc < 0 || argc > 1)
  159.     usage(progname);
  160. }
  161.  
  162. static void usage(const rcString& progname)
  163. {
  164.   cerr << "usage: " << progname << " [options] [filename]\n"
  165.        << "Where options include:\n"
  166.        << "\t-O outfile\t(Set output file name.)\n"
  167.        << "\t-R xres yres\t(Render at given resolution.)\n"
  168.        << "\t-E x y z\t(Set eyepoint vector.)\n"
  169.        << "\t-L x y z\t(Set lookat vector.)\n"
  170.        << "\t-U x y z\t(Set up vector.)\n"
  171.        << "\t-Dname\t\t(Define name as 1 (cpp option).)\n"
  172.        << "\t-Dname=def\t(Define name as \"def\" (cpp option).)\n"
  173.        << "\t-f angle\t(Set field of view.)\n"
  174.        << "\t-d drivername\n"
  175.        << "\t   no\t\t(No turtle interpretation.)\n"
  176.        << "\t   example\t(Example driver.)\n"
  177.        << "\t   bbox\t\t(Calculate bounding box and view parameter.)\n"
  178.        << "\t   rayshade\t(Rayshade driver.)\n"
  179.        << "\t   x11simple\t(Simple line drawing driver for X11.)\n"
  180.        << "\t   x11wire\t(Wire frame driver for X11.)\n"
  181.        << "\t   flat\t\t(Simple z-buffering.)\n"
  182.        << "\t-c\t\t(Toggle cone spheres generation.)\n "
  183.        << "\t-s\t\t(Show definied hulls.)\n "
  184.        << "\t-v\t\t(Verbose output.)\n"
  185.        << "\t-q\t\t(Run quietly.)\n"
  186.        << "\t-l\t\t(Print l-system definition.)\n"
  187.        << "\t-p\t\t(Print resulting module string.)\n"
  188.        << "\t-e\t\t(Erase module after turtle interpretation.)\n"
  189.        << "\t-h\t\t(Print this message.)\n";
  190.         
  191.   exit(1);
  192. }
  193.  
  194.  
  195.