// ------------------------------------------------------------------------------------ // [--- IO Class Implementation File ---] // A class used for Input and Output to the filesystem. // ------------------------------------------------------------------------------------ #include "IO.hpp" IO::IO(){ } IO::~IO(){ } int strToInt(string & strVal){ stringstream ss (stringstream::in | stringstream::out); int returnVal; ss << strVal; ss >> returnVal; return returnVal; } vector IO::makePoly (vector &vert, vector > &face) { vector polyList; for (int unsigned i = 0; i < face.size(); i++) { CPoly tmp = *(new CPoly); vector newBdy; for(unsigned int x = 0; x < face[i].size(); x++) newBdy.push_back( vert[ face[i][x] ] ); tmp.bdy = newBdy; polyList.push_back( tmp ); } return polyList; } void printPoly(CPoly & cpoly){ cout << "CPoly:{"; for(unsigned int x = 0; x < cpoly.bdy.size(); x ++){ cout << " [" << cpoly.bdy[x] << "] "; } cout << "}" << endl; } void IO::readIn(string file) { ifstream f (file.c_str()); if ( !f.good() ) { cout << "BAD FILE:" << file.c_str() << endl; return; } if (f.is_open()) { while (!f.eof()) { string tmp; string garbage; getline (f,tmp); int vert, face, edge; f>> vert; f>> face; f>> edge; cout << "Vert:" << vert << " "; cout << "Face:" << face << endl;; for (int i = 0; i < vert; i++) { double x = 0, y = 0, z = 0; f>>x; f>>y; f>>z; Coord temp(x,y); vertList.push_back( temp ); } int numCoords = 0; for (int k = 0; k < face; k++) { f >> garbage; numCoords = strToInt(garbage); faceList.push_back( *(new vector()) ); for (int j = 0; j< numCoords; j++) { f >> garbage; int corIndex = strToInt(garbage); faceList[k].push_back(corIndex); } } } f.close(); } } void IO::writeOut( string outputFileName ){ //Insert Code Here } FileName IO::findFile( string & filename ){ string path = ""; string fullPath = ""; vector placesToLook; placesToLook.push_back(""); placesToLook.push_back("./bin/"); placesToLook.push_back("./data/ppmFiles/"); placesToLook.push_back("./data/offFiles/"); //Find out which of the elements of placesToLook is the directory that //~ filename is located in. bool fileFound = false; for(unsigned int x = 0; x < placesToLook.size(); x ++){ path = placesToLook[x]; fullPath = path + filename; ifstream f( fullPath.c_str() ); //If this file is good, we've found where it's located if( f.good() ){ fileFound = true; break; } } FileName f; //If the file has not been found after we looked through all possible //~ directories, assume it does not exist. if( !fileFound ){ cout << "Bad File:\"" << filename << "\" not found anywhere."; return f; } //If the file has been found, construct a proper FileName to return. else{ } return f; } void IO::loadFiles(vector ppmFiles, vector offFiles){ readIn("./bin/0991L.off"); vector tempVec = makePoly(vertList, faceList); cout << "tempVec:" << tempVec.size() << endl; for(unsigned int x = 0; x < tempVec.size(); x ++){ printPoly( tempVec[x] ); } }