Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Readers.cc

Go to the documentation of this file.
00001 /*
00002     File:       Readers.cc
00003 
00004     Function:   Support for reading in various scene file formats
00005 
00006     Author:     Andrew Willmott
00007 
00008     Notes:      
00009 */
00010 
00011 #include "gcl/Readers.h"
00012 
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <unistd.h>
00016 #include <stdlib.h>
00017 #include "gcl/GCLConfig.h"
00018 
00019 #ifdef DEBUG
00020 #define DBG_COUT if (1) cerr
00021 #else
00022 #define DBG_COUT if (0) cerr
00023 #endif
00024 
00025 #define INFO_COUT cerr
00026 
00027 typedef scScenePtr (*SceneParser)(const Char *filename);
00028 
00029 struct SceneParserEntry
00030 {
00031     StrConst        extension;
00032     SceneParser     parser;
00033     StrConst        description;
00034 };
00035 
00036 scScenePtr ParseObjFile(const Char *filename);
00037 scScenePtr ParseSLFile(const Char *filename);
00038 scScenePtr ParseSCFile(const Char *filename);
00039 scScenePtr ParseMGFFile(const Char *filename);
00040 scScenePtr ParseMMFFile(const Char *filename);
00041 scScenePtr ParseMSDLFile(const Char *filename);
00042 scScenePtr ParsePLYFile(const Char *filename);
00043 
00044 static StrConst kSceneFileExtensions[] = 
00045 {
00046     "sl",
00047     "obj",
00048     "msh",
00049     "smf",
00050     "mrb",
00051     "mmf",
00052     "cmf",
00053 #ifdef GCL_PARSE_SC
00054     "sc",
00055 #endif
00056 #ifdef GCL_MGF
00057     "mgf",
00058 #endif
00059 #ifdef GCL_MSDL
00060     "msdl",
00061 #endif
00062     "ply",
00063     0
00064 };
00065 
00066 static SceneParserEntry kSceneParserTable[] = 
00067 {
00068     "sl",   ParseSLFile,        "GCL's scene language.",
00069     "obj",  ParseObjFile,       "Wavefront .obj text format",
00070     "msh",  ParseObjFile,       ".msh file",
00071     "smf",  ParseObjFile,       "Garland's .smf format (obj-like)",
00072     "mrb",  ParseMMFFile,       "binary multi-res model format",
00073     "mmf",  ParseMMFFile,       "ascii multi-res model",
00074     "cmf",  ParseMMFFile,       "ascii face cluster model",
00075 #ifdef GCL_PARSE_SC
00076     "sc",   ParseSCFile,        "Heckbert's .sc format",
00077 #endif
00078 #ifdef GCL_MGF
00079     "mgf",  ParseMGFFile,       "Ward et al.'s .mgf format",
00080 #endif
00081 #ifdef GCL_MSDL
00082     "msdl", ParseMSDLFile,      "Manchester Scene Description Language",
00083 #endif
00084     "ply",  ParsePLYFile,       "PLY format (cyberware etc.)",
00085     0
00086 };
00087 
00088 Void SceneReader::PrintSupportedFormats(ostream &s)
00089 {
00090     SceneParserEntry *sp = kSceneParserTable;
00091     Int     i;
00092 
00093     s << "Supported scene file extensions: " << endl;
00094 
00095     while (sp->extension)
00096     {
00097         s << "  " << sp->extension;
00098         for (i = 0; i < 4 - strlen(sp->extension); i++)
00099             s << ' ';
00100         s << "    " << sp->description << endl;
00101         sp++;
00102     }
00103 #ifdef CL_GZIP
00104     s << "gzipped versions of these files are also acceptable." << endl;
00105 #endif
00106 }
00107 
00108 scScenePtr SceneReader::Load(FileName &sceneFile)
00115 {
00116     scScenePtr          result;
00117     String              gunzipFile, origFile;
00118     Bool                gzipFile = false;
00119     SceneParserEntry    *sp;
00120     FileName            filename(sceneFile);
00121     Int                 fileExt;
00122 
00123     fileExt = filename.FindFileExtension(kSceneFileExtensions);
00124 
00125     if (fileExt == kFileNotFound)
00126         INFO_COUT << filename.GetPath() << 
00127             " does not exist or is not readable." << endl;
00128     else if (fileExt == kBadExtension)
00129         INFO_COUT << filename.GetPath() << " has an unknown extension." 
00130                   << endl;
00131 
00132     if (fileExt < 0)
00133         return(0);
00134         
00135     sceneFile = filename;   // set sceneFile to the file we actually found
00136 
00137     if (filename.DecompressSetup() != 0)
00138     {
00139         INFO_COUT << "Error while decompressing " << origFile << endl;
00140         return(0);
00141     }
00142     INFO_COUT << "Reading " << filename.GetPath() << endl;
00143     result = (kSceneParserTable[fileExt].parser)(filename.GetPath());
00144     filename.DecompressCleanup();
00145     
00146     return(result);
00147 }

Generated at Sat Aug 5 00:17:02 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000