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

parseObject.h File Reference

#include <string>

Go to the source code of this file.

Functions

string readFile ( char* filename )
 Reads a text file and parses it Reads a human readable file and parses it into a binary description. More...


Function Documentation

string readFile ( char * filename)

Reads a text file and parses it Reads a human readable file and parses it into a binary description.

Author(s):
xandi , stonedbones
Parameters:
filename   the file to read the data from

Definition at line 25 of file parseObject.cpp.

00025 {
00026     ifstream f(filename);
00027 
00028     char* str = new char[12500];
00029 
00030     float   tempF;
00031     int     tempI;
00032     char    tempC;
00033     int     pos;
00034 
00035     strcpy ( str, filename);
00036 
00037     pos = 64;  // position in output string,after header, where data starts
00038 
00039     f >> tempI; // read number of vertices
00040 
00041 
00042     memcpy ( str+pos, &tempI, sizeof(int) ); // update output string with data
00043     pos = pos + sizeof(int);                 // update position variable
00044 
00045     int i,ii,jj;
00046     float vertex[3];
00047     ii = tempI;
00048     for ( i = 0; i < ii; i++ ) {  // read in coordinates for vertices
00049         f >> vertex[0];      // read X coordinate
00050         f >> vertex[1];      // read Y coordinate
00051         f >> vertex[2];      // read Z coordinate
00052 
00053     // update output string with numbner of points and update position variable
00054         tempI = i+1;
00055         memcpy ( str+pos, &tempI, sizeof(int) );
00056         pos = pos + sizeof(int);
00057 
00058     // update output string with x coordinate and update position variable
00059         tempF = vertex[0];
00060         memcpy ( str+pos, &tempF, sizeof(float) );
00061         pos = pos + sizeof(float);
00062 
00063     // update output string with y coordinate and update position variable
00064         tempF = vertex[1];
00065         memcpy ( str+pos, &tempF, sizeof(float) );
00066         pos = pos + sizeof(float);
00067 
00068     // update output string with z coordinate and update position variable
00069         tempF = vertex[2];
00070         memcpy ( str+pos, &tempF, sizeof(float) );
00071         pos = pos + sizeof(float);
00072 
00073     #ifdef DEBUG
00074     cerr << "Vertex " << tempI << ": " << vertex[0] << ", " << vertex[1] << ", " << vertex[2] << "\n";
00075     #endif
00076     }
00077 
00078 
00079     // update output string with number of polygons and update position variable
00080     f >> tempI;     // read number of polygons
00081     memcpy ( str+pos, &tempI, sizeof(int) );
00082     pos = pos + sizeof(int);
00083 
00084     ii = tempI;
00085     for ( i = 1; i <= ii; i++) {
00086 
00087     // update output string with polygons number and update position variable
00088         f >> tempI; // read in polygon number
00089         memcpy ( str+pos, &tempI, sizeof(int) );
00090         pos = pos + sizeof(int);
00091 
00092     // update output string with polygons type and update position variable
00093         tempC = 1;   // define polygon type
00094         memcpy ( str+pos, &tempC, sizeof(char) );
00095         pos = pos + sizeof(char);
00096 
00097     // update output string with polygons color and update position variable
00098         f >> tempF;  // first color part
00099         memcpy ( str+pos, &tempF, sizeof(float) );
00100         pos = pos + sizeof(float);
00101 
00102         f >> tempF;  // second color part
00103         memcpy ( str+pos, &tempF, sizeof(float) );
00104         pos = pos + sizeof(float);
00105 
00106         f >> tempF;  // third color part
00107         memcpy ( str+pos, &tempF, sizeof(float) );
00108         pos = pos + sizeof(float);
00109 
00110         f >> tempF;  // fourth color part
00111         memcpy ( str+pos, &tempF, sizeof(float) );
00112         pos = pos + sizeof(float);
00113 
00114     // update output string with number of vertice in the present polygons
00115    //  and updates position variable
00116         f >> tempI; // read number of vertices in polygon
00117         memcpy ( str+pos, &tempI, sizeof(int) );
00118         pos = pos + sizeof(int);
00119 
00120         #ifdef DEBUG
00121         cerr << "Poly " << i << ": ";
00122         #endif
00123 
00124     // update output string with vertice indexes in present polygon
00125     // and updates position variable
00126         jj = tempI;
00127         for (int j = 1; j <= jj; j++) {
00128 
00129             f >> tempI;
00130             memcpy ( str+pos, &tempI, sizeof(int) );
00131                 pos = pos + sizeof(int);
00132             #ifdef DEBUG
00133             cerr << tempI << " ";
00134             #endif
00135         };
00136         #ifdef DEBUG
00137         cerr << "\n";
00138         #endif
00139     };
00140 
00141 
00142     #ifdef DEBUG
00143     fprintf(stderr,"[parser] String is %d long\n", pos );
00144     #endif
00145 
00146     return string ( str, pos );
00147     }

Generated at Sat May 13 13:50:22 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000