Exemple #1
0
void Utils::writeCrashLog(std::string path)
{
	string line;
	ifstream myfile;		
	vector<string> cam;
	myfile.open( getAssetPath(path).c_str(), ifstream::in);

	int value = 0;
	
	if (myfile.is_open())
	{
			while ( myfile.good() )
			{
				getline (myfile,line);
				cam.push_back(line);						
			}
			myfile.close();	

		 value = ::atoi(cam[0].c_str());
	}

	value++;

	ofstream myfile1 (getAssetPath(path).c_str());
	if (myfile1.is_open())
	{
		myfile1 << value;		
		myfile.close();
	}
	 

}
void Make_log1(int frame_counter,std::vector <std::vector <int> > pos,int pos_counter){

	std::ofstream fout("log1.txt",std::ios_base::app); //write
	std::fstream myfile1("log1.txt",std::ios_base::in); //read
	std::string read1;
	int value;
	bool has_non_absolute = false; //check if each centre has a non-absolute value, if not then put -1 into its position except the first frame
	std::vector< std::vector<int> > log1_(2, std::vector<int>(10));
	int log1_counter = 0;
	int value1 = 0;
	int value2 = 0;

	for(int i = 0; i <= pos_counter - 1;i++){
		log1_ = Calculate_dimens(pos[i][0],pos[i][1],pos[i][2],pos[i][3],log1_,log1_counter);
		log1_counter += 2;
	}

	int kalimera = 5;
	if(fout.is_open()){
		if(frame_counter == 1){ //first frame
			int i = 0;
			while(i < log1_counter){
				fout << log1_[1][i++];
				fout << " ";
				fout << log1_[1][i++];
				fout << " ";
			}
			fout << "|";
			fout << " ";
			fout << "|";
			fout << " ";
		}
		else{ //rest of the frames
			int counter1 = 1;
			int counter2 = 1;
			int position1 = 0;
			while(true){
				myfile1 >> read1;
				if(read1.compare("|") != 0 && counter2 == frame_counter - 1){ //in the absolute position values in one frame before the one that we are now
					value = std::stoi(read1);
					log1_[0][position1++] = value; 
				}
				else if(read1.compare("|") == 0 && counter2 == frame_counter){ //if it is a bracket and we one frame before the one that we are now
					break;
				}
				else if(read1.compare("|") == 0){ //we are not on the one frame before the last
					if(counter1 > counter2){
						counter2++;
					}
					else{
						counter1++;
					}
				}
			}
			int i = 0;
			if(log1_counter > 0){
				while(i < log1_counter){ //put the new absolute values to txt
					fout <<  log1_[1][i++];
					fout << " ";
					fout <<  log1_[1][i++];
					fout << " ";
				}
			}
			fout << "|";
			fout << " ";
			for(int i = 0;i < log1_counter;i++){ //find if two centres are closer than 5 pixel in x axis
				for(int j = 0;j < position1;j++){
					value1 = log1_[1][i];
					value2 = log1_[0][j];

					if(i % 2 == 0 || i == 0){ // if we are on a x-axis position
						if(j % 2 == 0 || j == 0){
							if(value1 >  value2){ //check so that we don't have to check between positive and negative numbers
								int temp = value1 -  value2;
								int bla = 5;
								if(temp < 10){
									fout << temp;
									fout << " ";
									has_non_absolute = true;
									break;
								}
							}
							else if(value1 <  value2){
								int temp = value2 -  value1;
								int bla = 5;
								if(temp < 10){
									fout << temp;
									fout << " ";
									has_non_absolute = true;
									break;
								}
							}
							else{
								continue;
							}
						}
					}
					else if (i % 2 == 1){
						if(j % 2 == 1){
							if(value1 >  value2){ //check so that we don't have to check between positive and negative numbers
								int temp = value1 -  value2;
								if(temp < 10){
									fout << temp;
									fout << " ";
									has_non_absolute = true;
									break;
								}
							}
							else if(value1 <  value2){
								int temp = value2 -  value1;
								int bla = 5;
								if(temp < 10){
									fout << temp;
									fout << " ";
									has_non_absolute = true;
									break;
								}
							}
							else{
								continue;
							}
						}
					}
				}
				if(has_non_absolute == false){ //if a centre has no non-absolute values then put -1 except first frame
					fout << 0;
					fout << " ";
				}
				else{
					has_non_absolute = false;
				}
				value1 = 0;
				value2 = 0;
			}
			fout << "|";
			fout << " ";
		}
	}
}
void Simulation::setupFromFile(std::string centroid, std::string voronoi)
{
    int vertexNumber = -1;
    int faceNumber = -1;
    bool vertex = false;
    bool face = false;
    std::string line;
    int compteur = 0;
    int skip = 2;
    // Cellule correspondant en fait au bord
    Cellule* border = new Cellule(0);
    CELLULES[border->getID()] = border;
    std::vector<std::string> tmp;
    // On test déjà quelles cellules vont être gardés

    ifstream myfile1(voronoi.c_str());
    compteur = 0;
    skip = 1;
    tmp.clear();
    //std::istringstream* iss;
    std::set<int> goodCells;
    if (myfile1.is_open())
    {

        while ( myfile1.good() )
        {

            for(int s = 0; s<=skip; s++) {
                getline (myfile1,line);
            }
            compteur++;
            if(compteur > nombreCellules) break;
            if(compteur == 1 && !vertex) {
                tmp.clear();
                StringWorker::Split(line,tmp," ");
                std::istringstream iss(tmp[0]);
                // convertir en un int
                iss >> vertexNumber;
                compteur = 0;
                vertex = true;
                skip = vertexNumber;
            } else {
                if(vertex) {
                    skip = 0;
                    tmp.clear();
                    StringWorker::Split(line,tmp," ");
                    bool garde = true;
                    //std::cout<<line<<std::endl;
                    for(unsigned int i=0; i<tmp.size(); i++) {
                        int p;
                        std::istringstream iss(tmp[i]);
                        // convertir en un int
                        iss >> p;
                        //std::cout<<"pt : "<<p<<std::endl;
                        if(p == 0) {
                            garde = false;
                            break;
                        }
                    }
                    if(garde) {
                        //std::cout<<"garde "<<compteur<<std::endl;
                        goodCells.insert(compteur);
                    }
                }
            }
        }
//Function to Read Sequences and Alignment from File and Initiliaze the Corresponding Sequences Object.
//The subtree argument is needed in order to delete all the "All-1" Columns from the OverallHomologies Matrix according to the specified subtree
void PairInitializer::InitSequences() {
    ClearInputStream();

    Seqs = new Sequences();

    /** Read Bare Sequences and Sequence Ids **/
    string line;
    ifstream myfile (BareSequencesFile.c_str());
    string filename = BareSequencesFile;

    stringstream seqId;
    stringstream seqText;
    bool firstLine = true;

    if (myfile.is_open()) {
        while ( myfile.good() ) {
            getline (myfile,line);

            if (line.compare("")==0 || line.compare("\n")==0 || line.compare(" ")==0) continue; //skip empty lines
            if (StartsWith(line, ">") || StartsWith(line,";")) {
                if (!firstLine) {
                    Seqs->AddBareSequence(seqText.str());
                    Seqs->AddSequenceId(seqId.str());
                    seqId.str("");
                    seqText.str("");
                }
                seqId << line;
                firstLine = false;
            } else {
                seqText << line;
            }

        }
        Seqs->AddBareSequence(seqText.str());
        Seqs->AddSequenceId(seqId.str());
    } else cerr << " Unable to open file: "<<filename<<" for reading.";
    myfile.close();

    /** Read Alignment **/
    string line1;
    ifstream myfile1 (AlignedSequencesFile.c_str());
    string filename1 = AlignedSequencesFile;

    stringstream seqText1;
    bool firstLine1 = true;

    if (myfile1.is_open()) {
        while ( myfile1.good() ) {
            getline (myfile1,line1);

            if (line1.compare("")==0 || line1.compare("\n")==0 || line1.compare(" ")==0) continue; //skip empty lines

            if (StartsWith(line1, ">") || StartsWith(line1,";")) {
                if (!firstLine1) {
                    Seqs->AddAlignedSequence(seqText1.str());
                    seqText1.str("");
                }
                firstLine1 = false;
            } else {
                seqText1 << line1;
            }

        }
        Seqs->AddAlignedSequence(seqText1.str());
    } else cerr << " Unable to open file: "<<filename1<<" for reading.";
    myfile1.close();

    Seqs->SetIndicesFromAlignment();
}