#include "fstream" #include "iostream" #include #include using namespace std; char mark; //the mark is either v or f struct face { int vertex[3]; int faceId; bool visited; face(int a[3], int b, bool c) { for (int i=0; i<3; i++) vertex[i] = a[i]; faceId = b; visited = c; } }; vector vertexVec; // store the vertex info vector faceVec; //store the face info int vcount=0; //counter for vertex; int fcount=0; //counter for face vector *node; //the array that stores faceVecs which consist faces withs same vertices. //read data file and build vertexVec, faceVec and node. void readFile(char* FileName) { fstream file_op(FileName,ios::in); while(file_op >> mark) { if (mark == 'v'){ double *temp = new double[3]; for(int i=0; i<3; i++) { file_op >> temp[i]; } vertexVec.push_back(temp); vcount++; }//vertexVec if (mark == 'f') { int *temp = new int[3]; for(int i=0; i<3; i++) { file_op >> temp[i]; } faceVec.push_back(face(temp, fcount+1, false)); fcount++; }//faceVec } node = new vector[vcount+1]; for (int i=0; i faceQueue; faceQueue.push(faceVec[0]); faceVec[0].visited = true; while (!faceQueue.empty()) { int temp[3]; for (int i=0; i<3; i++){ temp[i] = faceQueue.front().vertex[i];//temp stores the queue front face } for (int i=0; i<3; i++) { vector tempVec = node[temp[i]];//get the faceVec that stores faces with the same vertex for (unsigned int j=0; j faceQueue; faceQueue.push(faceVec[0]); faceVec[0].visited = true; while (!faceQueue.empty()){ for (unsigned int i=0; i