Main Page | File List

rt_parse.h

Go to the documentation of this file.
00001 
00025 #ifndef _RT_PARSE_H_
00026 #define _RT_PARSE_H_
00027 
00028 #include "rt_vectors.h"
00029 #include <vector>
00030 
00031 /**********************************************/
00032 /* You need to define and write these classes */
00033 /**********************************************/
00034 class rt_Light;
00035 class rt_Object;
00036 class rt_Group;
00037 class rt_Sphere;
00038 class rt_Triangle;
00039 class rt_Material;
00040 
00041 /* For parsing purposes */
00042 #define MAX_PARSER_TOKEN_LENGTH 100
00043 
00044 class rt_parse
00045 {
00046 public:
00047 
00050     rt_parse();
00051     
00056     rt_parse(const char *filename);
00057 
00060     ~rt_parse();
00061 
00067     Vec3f getBackgroundColor() { return background_color; }
00068 
00074     Vec3f getAmbientLight() { return ambient_light; }
00075 
00078     int getNumLights() { return (int)(lights.size()); }
00079 
00082     int getNumMaterials() { return (int)(materials.size()); }
00083 
00088     rt_Light* getLight(unsigned int i)
00089     {
00090         if((i < 0) || (i >= lights.size()))
00091         {
00092           cout<<"ERROR: request for light "<<i<<", which is outside "<<
00093                 "acceptable indices. There are "<<lights.size()<<" lights.\n";
00094           exit(-1);
00095         }
00096         rt_Light *result = lights[i];
00097         assert(result != NULL);
00098         return result;
00099     }
00100 
00105     rt_Material* getMaterial(unsigned int i)
00106     {
00107         if((i < 0) || (i >= materials.size()))
00108         {
00109           cout<<"ERROR: request for material "<<i<<", which is outside "<<
00110                 "acceptable indices. There are "<<lights.size()<<" lights.\n";
00111           exit(-1);
00112         }
00113         rt_Material *result = materials[i];
00114         assert (result != NULL);
00115         return result;
00116     }
00117 
00122     rt_Group* getGroup()
00123     {
00124         return group;
00125     }
00126 
00127 private:
00128 
00133     void rt_parse_initialize();
00134 
00139     void eatWhitespace(void);
00140 
00143     int getToken(char token[MAX_PARSER_TOKEN_LENGTH]);
00144 
00147     Vec3f readVec3f();
00148 
00151     float readFloat();
00152 
00155     int readInt();
00156 
00159     void parseFile();
00160     
00163     void parseBackground();
00164     
00167     void parseLights();
00168     
00171     void parseMaterials();
00172     
00175     void parseMaterialIndex();
00176     
00180     rt_Group* parseGroup();
00181     
00184     rt_Sphere* parseSphere();
00185     
00188     rt_Triangle* parseTriangle();
00189 
00190     /* Private data members for class rt_parse */
00191     rt_Group *group; 
00193     Vec3f background_color; 
00194     Vec3f ambient_light;    
00196     FILE *file;     
00198     int parse_char; 
00199     int curline;    
00201     std::vector<rt_Light *> lights; 
00202     std::vector<rt_Material *> materials; 
00203     rt_Material *current_material; 
00204 };
00205 
00206 #endif

Generated on Mon Oct 25 15:46:39 2004 for Graphics Project 2 by doxygen 1.3.6