ReadData::MatrixType ReadData ::OpenKernel(std::string FilePath) { std::ifstream file(FilePath); std::string line; int NbLines = 0; while (std::getline(file, line)) { ++NbLines; } file.clear(); file.seekg(00, std::ios::beg); MatrixType Kernel(NbLines, 1827, 0); if (file.is_open()) { std::string line; int i = 0; while (std::getline(file, line)) { int j = 0; std::stringstream LineStream(line); std::string cell; while (std::getline(LineStream, cell, ',')) { auto a = std::stold(cell); if (fabs(a) < 10e-13) { Kernel(i, j) = 0; } else { Kernel(i, j) = std::stold(cell); } ++j; } ++i; } } else { std::cout << "Unable to open the kernel located in " + FilePath; } return Kernel; }
TextQuery::TextQuery( std::ifstream & ac_Input ) : mc_xLines( std::make_shared< std::vector< std::string > >() ) { mt_uLineNum uLineNum( 0 ); for ( std::string sLine ; std::getline( ac_Input , sLine ); ++uLineNum ) { mc_xLines->push_back( sLine ); std::istringstream LineStream( sLine ); for ( std::string sText, sWord ; LineStream >> sText ; sWord.clear() ) { std::remove_copy_if( sText.begin(), sText.end(), std::back_inserter(sWord), std::ispunct ); auto& xCount = mc_Results[ sWord ]; if ( xCount ){ xCount->insert( uLineNum ); } else { xCount.reset( new std::set<mt_uLineNum>{uLineNum} ); } } } }
bool Mesh::LoadObj(std::string name) { bool check = false; int kV,kVT,kVN,kF; std::ifstream File(name.c_str()); string Line; string Name; cout<<"Begin parsing"<<endl; while(std::getline(File, Line)){ if(Line == "" || Line[0] == '#')// Skip everything and continue with the next line continue; std::istringstream LineStream(Line); LineStream >> Name; if(Name == "v"){// Vertex cout<<"Vertices parsed"<<endl; kV++; float Vertex[3]; QVector<float> TempVertices; sscanf(Line.c_str(), "%*s %f %f %f", &Vertex[0], &Vertex[1], &Vertex[2]); TempVertices.push_back(Vertex[0]); TempVertices.push_back(Vertex[1]); TempVertices.push_back(Vertex[2]); geometry.push_back(TempVertices); } if(Name == "vn"){// Normales kVN++; float Vertex[3]; QVector<float> TempNormals; sscanf(Line.c_str(), "%*s %f %f %f", &Vertex[0], &Vertex[1], &Vertex[2]); TempNormals.push_back(Vertex[0]); TempNormals.push_back(Vertex[1]); TempNormals.push_back(Vertex[2]); normals.push_back(TempNormals); } if(Name == "vt"){// Textures kVT++; float Vertex[2]; QVector<float> TempTextures; sscanf(Line.c_str(), "%*s %f %f", &Vertex[0], &Vertex[1]); TempTextures.push_back(Vertex[0]); TempTextures.push_back(Vertex[1]); TempTextures.push_back(Vertex[2]); textures.push_back(TempTextures); } if(Name == "f"){// Faces kF++; float Vertex[3][3]; QVector<int> TempTopology; sscanf(Line.c_str(), "%*s %f/%f/%f %f/%f/%f %f/%f/%f", &Vertex[0][0], &Vertex[0][1], &Vertex[0][2], &Vertex[1][0], &Vertex[1][1], &Vertex[1][2], &Vertex[2][0], &Vertex[2][1], &Vertex[2][2]); TempTopology.push_back(Vertex[0][0]);TempTopology.push_back(Vertex[0][1]);TempTopology.push_back(Vertex[0][2]); topo.push_back(TempTopology); TempTopology.clear(); TempTopology.push_back(Vertex[1][0]);TempTopology.push_back(Vertex[1][1]);TempTopology.push_back(Vertex[1][2]); topo.push_back(TempTopology); TempTopology.clear(); TempTopology.push_back(Vertex[2][0]);TempTopology.push_back(Vertex[2][1]);TempTopology.push_back(Vertex[2][2]); topo.push_back(TempTopology); } }; cout<<"End parsing"<<endl; if(kV==geometry.size() && kVT==textures.size() && kVN==normals.size() && kF==topo.size()) check = true; return check; }
Observations ReadData ::ReadObservations(DataSettings &DS) { Observations Obs; std::ifstream IndivID(DS.GetPathToGroup()); std::ifstream TimePointsFile(DS.GetPathToTimepoints()); std::ifstream LandmarksFile(DS.GetPathToLandmarks()); std::ifstream CognitiveScoresFile(DS.GetPathToCognitiveScores()); std::string GroupLine, TimePointsLine, LandmarksLine, CognitiveScoresLine; unsigned int CurrentSubjectID = -1; VectorType TimePoints; std::vector<VectorType> Landmarks; std::vector<VectorType> CognitiveScores; while(getline(IndivID, GroupLine)) { if(CurrentSubjectID == -1) CurrentSubjectID = std::stoi(GroupLine); unsigned int NewSubjectID = std::stoi(GroupLine); getline(TimePointsFile, TimePointsLine); if(DS.LandmarkPresence()) getline(LandmarksFile, LandmarksLine); if(DS.CognitiveScoresPresence()) getline(CognitiveScoresFile, CognitiveScoresLine); /// New subject if(NewSubjectID != CurrentSubjectID) { IndividualObservations Individual(TimePoints); if(DS.LandmarkPresence()) Individual.AddLandmarks(Landmarks); if(DS.CognitiveScoresPresence()) Individual.AddCognitiveScores(CognitiveScores); Obs.AddIndividualData(Individual); CurrentSubjectID = NewSubjectID; TimePoints.clear(); Landmarks.clear(); CognitiveScores.clear(); } TimePoints.push_back(stod(TimePointsLine)); if(DS.LandmarkPresence()) { VectorType NewObs(DS.GetLandmarksDimension()); int i = 0; std::stringstream LineStream(LandmarksLine); std::string cell; while(std::getline(LineStream, cell, ',')) { NewObs(i) = std::stod(cell); ++i; } Landmarks.push_back(NewObs); } if(DS.CognitiveScoresPresence()) { VectorType NewObs(DS.GetCognitiveScoresDimension()); int i = 0; std::stringstream LineStream(CognitiveScoresLine); std::string cell; while(std::getline(LineStream, cell, ',')) { NewObs(i) = std::stod(cell); ++i; } CognitiveScores.push_back(NewObs); } } IndividualObservations Individual(TimePoints); if(DS.LandmarkPresence()) Individual.AddLandmarks(Landmarks); if(DS.CognitiveScoresPresence()) Individual.AddCognitiveScores(CognitiveScores); Obs.AddIndividualData(Individual); return Obs; }