All pastes #2099616 Raw Edit

FOR CODY HERE

public text v1 · immutable
#2099616 ·published 2012-01-05 17:07 UTC
rendered paste body
//	------------------------------------------------------------------------------------
//	[--- 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<CPoly> IO::makePoly (vector<Coord> &vert, vector <vector <int> > &face) {
  vector <CPoly> polyList;
  for (int unsigned i = 0; i < face.size(); i++) {
    CPoly tmp = *(new CPoly);
    
    vector<Coord> 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<int>()) );

	    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<string> 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<string> ppmFiles, vector<string> offFiles){
	
	readIn("./bin/0991L.off");
	
	vector<CPoly> tempVec = makePoly(vertList, faceList);
	cout << "tempVec:" << tempVec.size() << endl;
	for(unsigned int x = 0; x < tempVec.size(); x ++){
		printPoly( tempVec[x] );
	}
}