void PLYParser::importFile(std::string sFilePath) { std::cout << "Parsing started" << std::endl ; fileImported = sFilePath ; char str1[SIZE], str2[SIZE] ; unsigned int iTemp = 0; char buffer[SIZE]; FILE * fileReadPointer = fopen ( sFilePath.c_str(), "r" ); if( NULL == fileReadPointer ) { puts("Error : File not opened for reading."); return; } while ( NULL != fgets( buffer , SIZE , fileReadPointer) ) { if( EOF == buffer[0] ) { break; } else { sscanf( buffer, "%s %s %d", &str1 , &str2, &iTemp ); if( 0 == strcmp( "end_header", str1 ) ) break; else if( 0 == strcmp( "element", str1 ) && 0 == strcmp( "vertex", str2 ) ) objMesh.setNumberOfVertices(iTemp); else if( 0 == strcmp( "element", str1 ) && 0 == strcmp( "face", str2 ) ) objMesh.setNumberOfFaces(iTemp); } } unsigned int count = 0; double x=0, y=0, z=0 ; for( ; count < objMesh.totalVertices() ; ++count ) { fgets( buffer , SIZE , fileReadPointer); sscanf( buffer, "%lf %lf %lf", &x , &y, &z ); Vertex tempVertex(x,y,z); objMesh.getVertexList().push_back(tempVertex); } count = 0; int v1=0, v2=0, v3=0, v4=0, v5=0 ; for( count = 0 ; count < objMesh.totalFaces() ; ++count ) { fgets( buffer , SIZE , fileReadPointer); sscanf( buffer, "%d %d %d %d %d %d", &iTemp, &v1 , &v2, &v3, &v4, &v5 ); // Triangulate the quads if( 3 == iTemp ) { Face objFace; objFace.getBoundingVerticesList().push_back( v1 ); objFace.getBoundingVerticesList().push_back( v2 ); objFace.getBoundingVerticesList().push_back( v3 ); objMesh.getFaceList().push_back(objFace); if( !objMesh.getParsingStatus() ) objMesh.getControlMeshFaceList().push_back(objFace); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v2); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v2].getNeighboringVerticesList().push_back(v1); objMesh.getVertexList()[v2].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v2); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v1); } else if( 4 == iTemp ) { Face objFace1; objFace1.getBoundingVerticesList().push_back( v1 ); objFace1.getBoundingVerticesList().push_back( v2 ); objFace1.getBoundingVerticesList().push_back( v3 ); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v2); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v2].getNeighboringVerticesList().push_back(v1); objMesh.getVertexList()[v2].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v2); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v1); Face objFace2; objFace2.getBoundingVerticesList().push_back( v3 ); objFace2.getBoundingVerticesList().push_back( v4 ); objFace2.getBoundingVerticesList().push_back( v1 ); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v4); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v4].getNeighboringVerticesList().push_back(v1); objMesh.getVertexList()[v4].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v4); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v1); objMesh.getFaceList().push_back(objFace1); objMesh.getFaceList().push_back(objFace2); if( !objMesh.getParsingStatus() ) { objMesh.getControlMeshFaceList().push_back(objFace1); objMesh.getControlMeshFaceList().push_back(objFace2); } } else if( 5 == iTemp ) { Face objFace1; objFace1.getBoundingVerticesList().push_back( v1 ); objFace1.getBoundingVerticesList().push_back( v2 ); objFace1.getBoundingVerticesList().push_back( v3 ); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v2); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v2].getNeighboringVerticesList().push_back(v1); objMesh.getVertexList()[v2].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v2); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v1); Face objFace2; objFace2.getBoundingVerticesList().push_back( v3 ); objFace2.getBoundingVerticesList().push_back( v4 ); objFace2.getBoundingVerticesList().push_back( v5 ); objMesh.getVertexList()[v4].getNeighboringVerticesList().push_back(v5); objMesh.getVertexList()[v4].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v5].getNeighboringVerticesList().push_back(v4); objMesh.getVertexList()[v5].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v4); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v5); Face objFace3; objFace3.getBoundingVerticesList().push_back( v5 ); objFace3.getBoundingVerticesList().push_back( v1 ); objFace3.getBoundingVerticesList().push_back( v3 ); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v5); objMesh.getVertexList()[v1].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v5].getNeighboringVerticesList().push_back(v1); objMesh.getVertexList()[v5].getNeighboringVerticesList().push_back(v3); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v5); objMesh.getVertexList()[v3].getNeighboringVerticesList().push_back(v1); objMesh.getFaceList().push_back(objFace1); objMesh.getFaceList().push_back(objFace2); objMesh.getFaceList().push_back(objFace3); if( !objMesh.getParsingStatus() ) { objMesh.getControlMeshFaceList().push_back(objFace1); objMesh.getControlMeshFaceList().push_back(objFace2); objMesh.getControlMeshFaceList().push_back(objFace3); } } else { std::cerr << "Error: Found a face with for than 5 sides" << std::endl ; } } if( !objMesh.getParsingStatus() ) for( unsigned int i =0 ; i < objMesh.getVertexList().size() ; ++ i ) objMesh.getControlMeshVertexList().push_back(objMesh.getVertexList()[i]); updateMetaInformation(); }
void scoring::ScoreCache::read(std::string filename) { network = new datastructures::BayesianNetwork(); std::ifstream in(filename.c_str()); std::vector<std::string> tokens; std::string line; // read meta information until we hit the first variable while (!in.eof()) { std::getline(in, line); // skip empty lines and comments if (line.size() == 0 || line.compare(0, 1, "#") == 0) { continue; } // check if we reached the first variable if (contains(line, "variable ")) break; // make sure this is a meta line if (!contains(line, "meta")) { throw std::runtime_error("Error while parsing META information of network. Expected META line or Variable. Line: '" + line + "'"); } tokens = parseMetaInformation(line); if (tokens.size() != 2) { throw std::runtime_error("Error while parsing META information of network. Too many tokens. Line: '" + line + "'"); } boost::trim(tokens[0]); boost::trim(tokens[1]); updateMetaInformation(tokens[0], tokens[1]); } // line currently points to a variable name tokens = parse(line, 0, " "); datastructures::Variable *v = network->addVariable(tokens[1]); // read in the variable names while (!in.eof()) { std::getline(in, line); // skip empty lines and comments if (line.size() == 0 || line.compare(0, 1, "#") == 0) { continue; } if (contains(line, "meta")) { tokens = parseMetaInformation(line); if (contains(tokens[0], "arity")) { v->setArity(atoi(tokens[1].c_str())); } else if (contains(tokens[0], "values")) { std::vector<std::string> values = parseVariableValues(tokens[1]); v->setValues(values); } else { boost::trim(tokens[0]); boost::trim(tokens[1]); v->updateMetaInformation(tokens[0], tokens[1]); } } if (contains(line, "variable ")) { tokens = parse(line, 0, " "); v = network->addVariable(tokens[1]); } } in.close(); setVariableCount(network->size()); // now that we have the variable names, read in the parent sets in.open(filename.c_str()); while (!in.eof()) { std::getline(in, line); if (line.size() == 0 || line.compare(0, 1, "#") == 0 || contains(line, "meta")) { continue; } tokens = parse(line, 0, " "); if (contains(line, "variable ")) { v = network->get(tokens[1]); continue; } // then parse the score for the current variable VARSET_NEW(parents, network->size()); float score = -1 * atof(tokens[0].c_str()); // multiply by -1 to minimize for (int i = 1; i < tokens.size(); i++) { int index = network->getVariableIndex(tokens[i]); VARSET_SET(parents, index); } putScore(v->getIndex(), parents, score); } in.close(); }