Matrice operator-(Matrice A, Matrice B)
{
    int nlA, ncA, nlB, ncB;
    A.GetSize(nlA, ncA);
    B.GetSize(nlB, ncB);
    Matrice result(nlA, ncB);

    if(ncA!=ncB || nlA!=nlB)
    {
        cout << "- Impossible" << endl;
        return result;
    }
    else
    {
        double** m = new double*[nlA];

        for(int i=0; i<nlA ; i++)
        {
            m[i] = new double[ncB];
            for (int j=0; j<ncB; j++)
                m[i][j] = 0;
        }

        for(int i=0; i<nlA ; i++)
            for(int j=0; j<ncB ; j++)
                m[i][j]=(A.GetValue(i,j))-(B.GetValue(i,j));

        result.Set(m);
        return result;
    }
}
Matrice operator*(Matrice A, Matrice B)
{
    int nlA, ncA, nlB, ncB;
    A.GetSize(nlA, ncA);
    B.GetSize(nlB, ncB);
    if(ncA!=nlB)
    {
        cout << "lol les matrice ça ce multiplies pas comme ça fdp" << endl;
    }
    else
    {
        Matrice result(nlA, ncB);
        double** m = new double*[nlA];
        for(int i=0; i<nlA ; i++)
        {
            m[i] = new double[ncB];
        }
        for(int i=0; i<nlA ; i++)
        {
            for(int j=0; j<ncB ; j++)
            {
                for(int k=0; k<ncA ; k++)
                {
                    m[i][j]+=(A.GetValue(i,k))*(B.GetValue(k,j));
                }
            }
        }
        result.Set(m);
        return resultat;
    }
}
int main()
{
    
    Matrice A(2,2);
    A(0,0)=5;
    A(0,1)=4;
    A(1,1)=1;
    A(1,0)=8;
    Matrice B(A); // Construction par copie.
    Matrice C = A*B;
    
    int nlig = rand()%100;
    
    vector<Matrice> Mat_Vect; // Construction normal.
    vector<Matrice> Mat_Vect2; // Construction par copie.
    vector<Matrice> Mat_Vect3; // Construction par copie d'une multiplication.

    
    for (int i = 0; i < 10; i++){
        Matrice A = Matrice(nlig, nlig);
        A.RandomMatrice();
        Mat_Vect.push_back(A);
    }
    for (int i = 0; i < 10; i++){
        Mat_Vect2.push_back(Mat_Vect[i]);
    }
    for (int i = 0; i < 10; i++){
        Mat_Vect3.push_back(Mat_Vect[i]*Mat_Vect2[9-i]);
    }
    
    return 0;
    
}
//Déclaration de l'opération * entre les matrices
Matrice operator*(Matrice A, Matrice B)
{
    int nlA, ncA, nlB, ncB;
    A.GetSize(nlA, ncA);
    B.GetSize(nlB, ncB);
    Matrice result(nlA, ncB);

    if(ncA!=nlB) // On ne peut pas multiplier n'importe quelles matrices
    {
        cout << "* Impossible" << endl;
        return result;
    }
    else
    {
        double** m = new double*[nlA];

        for(int i=0; i<nlA ; i++)
        {
            m[i] = new double[ncB];
            for (int j=0; j<ncB; j++)
                m[i][j] = 0;
        }

        for(int i=0; i<nlA ; i++)
            for(int j=0; j<ncB ; j++)
                for(int k=0; k<ncA ; k++){
                    m[i][j]+=(A.GetValue(i,k))*(B.GetValue(k,j));}

        result.Set(m);
        return result;
    }
}
Matrice BlinkyBlock::getMatrix(const Vecteur &bs) const {
    Matrice mat;

    double sigma = 0.5*((int)position.pt[2]%2);
    mat.setTranslation((position.pt[0]+sigma)*bs[0],(position.pt[1]+sigma)*bs[1],position.pt[2]*bs[2]*M_SQRT1_2);
    return mat;
}
/****************************************************************************
 * Fonction:	Matrice::operateur/
 * Description: Divise tous les éléments de la matrice par une valeur réelle
 * Paramètres:	Valeur à diviser
 * Retour:		Matrice résultante
 ****************************************************************************/
Matrice Matrice::operator/(double valeur)
{
	Matrice result = Matrice(*this);
	for (int i=0; i<lignes_; i++) {
		for (int j=0; j<colonnes_; j++)
			result.matrice_(i,j) /= valeur;
	}
	return result;
}
/****************************************************************************
 * Fonction:	Matrice::transpose
 * Description: Calcule la matrice transposée
 * Paramètres:	Aucun
 * Retour:		Matrice résultante
 ****************************************************************************/
Matrice Matrice::transpose()
{
	Matrice result = Matrice(colonnes_,lignes_);
	for (int i=0; i<lignes_; i++) {
		for (int j=0; j<colonnes_; j++)
			result.matrice_(j,i) = matrice_(i,j);
	}
	return result;
}
Beispiel #8
0
void testMGD()
{
	Quadruplet pQUAconfig[3];
	pQUAconfig[0] = Quadruplet(PI/2, 2, PI/2, 0);
    pQUAconfig[1] = Quadruplet(0, 0, 0, 1);
	pQUAconfig[2] = Quadruplet(0, 0, 0, 1);

	Matrice m = Robotique::ROBcalculMGD(pQUAconfig, 3);
	m.MATprint();
}
Beispiel #9
0
int main()
{
	Matrice A;
	Element elem1(3,0,0);
	Element elem2(2,1,1);
	Element elem3(1,0,4);
	A.ajouterElement(elem1);
	A.ajouterElement(elem2);
	A.ajouterElement(elem3);
	A.afficher();
	A.afficheCreuse();
	return 0;
}
/****************************************************************************
 * Fonction:	Matrice::operateur-
 * Description: Soustrait deux matrices. Il faut que les deux matrices soient de memes dimensions
 * Paramètres:	Matrice a soustraire
 * Retour:		Matrice resultante
 ****************************************************************************/
Matrice Matrice::operator-(const Matrice& uneMatrice)
{
	Matrice result;
	if (uneMatrice.lignes_ == lignes_ && uneMatrice.colonnes_ == colonnes_) {
        
		result = Matrice(lignes_,colonnes_);
		for (int i=0; i<lignes_; i++) {
			for (int j=0; j<uneMatrice.colonnes_; j++)
				result.matrice_(i,j) = matrice_(i,j) - uneMatrice.matrice_(i,j);
		}
	}
	else {
		cerr	<< "Erreur lors de la soustraction des matrices. Les dimensions doivent etre correctes." << endl
        << "(" << lignes_ << "," << colonnes_ << ") + (" << uneMatrice.lignes_ << "," << uneMatrice.colonnes_ << ")" << endl;
	}
	return result;
}
Beispiel #11
0
void DrImage::Cut(){
  char cImage[160];
  sprintf(cImage,"Small.png");
  double pixel[4];
  double xBound[2] = {.5,.75};
  double yBound[2] = {.2,.45};
  int xNBound[2];
  int yNBound[2];
  for(int d=0;d<2;d++){
    xNBound[d] = (int)(xBound[d]*NWidth);
    yNBound[d] = (int)(yBound[d]*NHeight);
    printf("%d %d %d %d\n",xNBound[d],NWidth,yNBound[d],NHeight);
  }
  int Dx = xNBound[1]-xNBound[0];
  int Dy = yNBound[1]-yNBound[0];
  double *Plot = new double[Dx*Dy];
  Matematica *Mat = new Matematica;
  //VarData *Var = new VarData;
  Matrice *ImIn = new Matrice(Dx,Dy);
  pngwriter ImageOut(xNBound[1]-xNBound[0],yNBound[1]-yNBound[0],1.0,cImage);
  double Average = 0.;
  double Count = 0.;
  for(int h=yNBound[0];h<yNBound[1];h++){
    for(int w=xNBound[0];w<xNBound[1];w++){
      int hh = h -yNBound[0];
      int ww = w -xNBound[0];
      double Sum = data[0][h*NWidth+w]+data[1][h*NWidth+w]+data[2][h*NWidth+w];
      //Sum *= .5;
      // ImageOut.plot(ww,hh,data[0][h*NWidth+w],data[1][h*NWidth+w],data[2][h*NWidth+w]);
      ImIn->Set(ww,hh,Sum);
      Plot[hh*Dx+ww] = Sum;
    }
  }


  for(int h=0;h<Dy;h++){
    for(int w=0;w<Dx;w++){
      //if(ImIn->Val(w,h) >= 0.)
      ImageOut.plot(w,h,10.*ImIn->Val(w,h),ImIn->Val(w,h),ImIn->Val(w,h));
    }
  }
  ImageOut.close();
  delete [] Plot;
}
/****************************************************************************
 * Fonction:	Matrice::Matrice
 * Description: Constructeur par copie
 * Paramètres:	Matrice à copier
 * Retour:		aucun
 ****************************************************************************/
Matrice::Matrice(const Matrice& uneMatrice)
{
	lignes_ = uneMatrice.lignes_;
	colonnes_ = uneMatrice.colonnes_;
	matrice_.setbounds(0,lignes_-1,0,colonnes_-1);
	for (unsigned int i=0; i<lignes_; i++)
	{
		for (unsigned int j=0; j<colonnes_; j++)
			matrice_(i,j) = uneMatrice.matrice_(i,j);
	}
}
Beispiel #13
0
bool operator== (const Matrice<char> &a, const Matrice<char> &b)
{
	for (int i = 0; i < a.GetNbLignes(); i++)
	{
		if (a[i] != b[i])
		{
			return false;
		}
	}
	return true;
}
Beispiel #14
0
/*
 * La fonction inverse utilise l'élimination de Gauss-Jordan pour générer une matrice inverse :
 * pour cela on utilise le pseudo-code trouver à cette adresse : http://fr.wikipedia.org/wiki/%C3%89limination_de_Gauss-Jordan#Pseudocode
 * On effectue les opérations sur la matrice à inverser et sur une matrice identité de même dimension.
 * Lorsque l'algorithme est terminé, la matrice identité a pris les valeurs de la matrice inverse.
 * La matrice à inverser a pris les valeurs de sa matrice échelonnée réduite.
 */ 
Matrice Matrice::Inverse() const
{
	int r = -1; //Attention au indices décalés dans notre logiciel (0 -> -1)
	Matrice inversible(*this);
	Matrice resultat = Identite();
	
	for(int j = 0; j < m_colonnes; j++)
	{
		//Recherche du maximum
		int k = r + 1; //<Position du maximum
		for(int i = k + 1; i < m_lignes; i++) // pas besoin de comparer la case de la ligne k avec elle-même
		{
			if(fabs(inversible.ObtenirValeur(i, j)) > fabs(inversible.ObtenirValeur(k, j)))
				k = i;
		}
		
		if(inversible.ObtenirValeur(k, j) != 0.f) //Si le max est != de 0
		{
			//Incrémentation de r
			r++;
			
			//Echange des lignes k et r
			inversible = inversible.InversionLignes(r, k);
			resultat = resultat.InversionLignes(r, k);
			
			//Division de la ligne r par A[r,j]
			float coeff = inversible.ObtenirValeur(r, j); //< A[r,j]
			//On stocke la valeur avant dans la variable coeff car elle est susceptible d'être modifiée par la division
			for(int l = 0; l < m_colonnes; l++)
			{
				inversible.FixerValeur(r, l, inversible.ObtenirValeur(r, l) / coeff);
				resultat.FixerValeur(r, l, resultat.ObtenirValeur(r, l) / coeff);
			}
			
			//On parcourt toutes lignes
			for(int i = 0; i < m_lignes; i++)
			{
				if(i == r) //sauf la ligne r
					continue;
				
				//Soustraction de la ligne i par la ligne r multipliée par le coeff i;j
				float coeffIJ = inversible.ObtenirValeur(i, j); //< A[i,j]
				//Pour les mêmes raisons que l'on garde A[r,j] dans coeff, on garde A[i,j] dans coeffIJ.
				for(int l = 0; l < m_colonnes; l++)
				{
					inversible.FixerValeur(i, l, inversible.ObtenirValeur(i, l) - inversible.ObtenirValeur(r, l) * coeffIJ);
					resultat.FixerValeur(i, l, resultat.ObtenirValeur(i, l) - resultat.ObtenirValeur(r, l) * coeffIJ);
				}
			}
		}
	}
	
	return resultat;
}
/****************************************************************************
 * Fonction:	Matrice::operateur*
 * Description: Multiplie la matrice avec celle passée en paramètre en vérifiant les dimensions
 * Paramètres:	Matrice à multiplier
 * Retour:		Matrice résultante
 ****************************************************************************/
Matrice Matrice::operator*(const Matrice& uneMatrice)
{
	Matrice result;
	if (uneMatrice.lignes_ == colonnes_) {
		result = Matrice(lignes_,uneMatrice.colonnes_);
        real_1d_array work; work.setbounds(0,lignes_);
        for (int k=0; k<lignes_; k++) work(k) = 0.0;
        //matrixmatrixmultiply(matrice_,0,lignes_-1,0,colonnes_-1,0,uneMatrice.matrice_,false,uneMatrice.lignes_-1,0,uneMatrice.colonnes_-1,0,1.0,result.matrice_,0,lignes_-1,false,uneMatrice.colonnes_-1,1.0,work);
		//rmatrixgemm(lignes_,uneMatrice.colonnes_,colonnes_,1,matrice_,0,0,0,uneMatrice.matrice_,0,0,0,0,result.matrice_,0,0);
		for (int i=0; i<lignes_; i++) {
			for (int j=0; j<uneMatrice.colonnes_; j++) {
				for (int k=0; k<colonnes_; k++)
					result.matrice_(i,j) += matrice_(i,k)*uneMatrice.matrice_(k,j);
			}
		}
	}
	else {
		cerr	<< "Erreur lors de la multiplication des matrices. Les dimensions doivent etre correctes." << endl
				<< "(" << lignes_ << "," << colonnes_ << ") * (" << uneMatrice.lignes_ << "," << uneMatrice.colonnes_ << ")" << endl;
	}
	return result;
}
Beispiel #16
0
bool Binairo::EstLigneEquilibree(Matrice<char> m, int ligne)
{
	// Compter le nombre de fois que la valeur donnée apparaît dans le Ligne
	compteurLigneZERO = 0, compteurLigneUN = 0;
	for (int j = 0; j < m.GetNbColonnes(); j++)
	{
		if (binairoGrille[ligne][j] == '0')
		{
			compteurLigneZERO++;
		}
		if (binairoGrille[ligne][j] == '1')
		{
			compteurLigneUN++;
		}
	}
	if (compteurLigneZERO != compteurLigneUN)
	{
		return false;
	}
	else
	{
		return true;
	}
}
Beispiel #17
0
bool Binairo::EstColonneEquilibree(Matrice<char> m, int colonne)
{
	// Compter le nombre de fois que la valeur donnée apparaît dans le Colonne
	compteurColonneZERO = 0, compteurColonneUN = 0;
	for (int i = 0; i < m.GetNbLignes(); i++)
	{
		if (binairoGrille[i][colonne] == '0')
		{
			compteurColonneZERO++;
		}
		if (binairoGrille[i][colonne] == '1')
		{
			compteurColonneUN++;
		}
	}
	if (compteurColonneZERO != compteurColonneUN)
	{
		return false;
	}
	else
	{
		return true;
	}
}
Beispiel #18
0
int main()
{
    
    
    cout<<"Welcome to matrix operation program"<<endl;
    
    cout<<"This program is developed for matrix operation, first matrix is read by a file"<<endl;
    
    cout<<"You must give dimensions of second matrice and program will generate a matrix with random values, then you can go to matrix operations."<<endl;
    cout<<endl;
    
    // File handling part
    
    Matrice FileMatrice ;
    
    FileMatrice.readLinesFromFile() ;
    
    cout<< "Here is a matrix with size: "<<FileMatrice.rowSize<<"x"<<FileMatrice.columnSize<<endl;
    
    FileMatrice.printMatrice();
    

    // create a random matrice struct called RandomMatrice
    
    Matrice RandomMatrice ;
    
    // we should get the dimension from the user in this scheme: row x column
    // so I am creating a string with 3 bytes to get it
    
    char getMatriceSize[3] ;
    cout << "Please enter the dimensions of the matrice (e.g. 2x3):" ;
    cin  >> getMatriceSize ;
    cout << "Here is a matrice with size of "<< getMatriceSize << "\n" ;
    //  we can add exception here in case of user enters invalid size
    
    // In order to get the size, I subtsracted ascii value '0' from the char value
    RandomMatrice.rowSize = getMatriceSize[0]-'0';
    //cout << "Row size "<< rowSize << "\n" ;
    
    // Same operation for column size of the matrice
    RandomMatrice.columnSize = getMatriceSize[2]-'0';
    //cout << "Column size "<< columnSize << "\n" ;
    
    // allocate memory for given dimension in random matrice
    RandomMatrice.allocateMemoryForMatriceElements() ;

    // get random values for the matrice
    //for random values
    srand(time(NULL));
    RandomMatrice.getRandomValuesForMatriceElements() ;
    
    
    // print the matrice with new elements
    RandomMatrice.printMatrice() ;

    RandomMatrice.bindMatriceElements() ;
    
       
    
    // Menu
    
    
    bool menuChoice = true;            //  boolean value for menu choice (continue ? (Y or N))
    char operationChoice ;             // char value for menu operations 
    char askIfTheUserWantsToContinueOperations ;
    while (menuChoice){
    
        cout << "\t\t\tMatrice Operation Menu\n" ;
        cout << "Select one of the matrice operations: \n" ;
           
        cout<< "1. Multiply the matrices and print the result to the screen.(M)\n"<<
            "2. Find transpose of the matrices (both) and print them to the screen.(T)\n"<<
            "3. Check if the matrices are symmetric.(S)\n"<<
            "4. Check if the matrices are zero matrix.(Z)\n"<<
            "5. Calculate the determinant of the matrices.(D)\n";
        
        cin>> operationChoice ;
        
        switch (operationChoice) {
            case 'M' | 'm':
                matrixMultiplication(FileMatrice, RandomMatrice);
                break;
            case 'T' | 't':
                //statements
                transpozeOperation(FileMatrice, RandomMatrice);
                break;
            case 'S' | 's':
                //statements
                checkIfSymmetric(FileMatrice, RandomMatrice);
                break;
            case 'Z' | 'z':
                //statements
                checkIfZeroMatrix(FileMatrice, RandomMatrice);
                break;
            case 'D' | 'd':
                //statements
                determinantOperation(FileMatrice, RandomMatrice);
                break;
            default:
                break;
        }
        
        cout<<"Would you like to continue ?(Y or N)\n";
        cin>>askIfTheUserWantsToContinueOperations ;
        
        if(askIfTheUserWantsToContinueOperations == 'Y' || askIfTheUserWantsToContinueOperations == 'y')
            menuChoice = true ;
        else if(askIfTheUserWantsToContinueOperations == 'N' || askIfTheUserWantsToContinueOperations == 'n')
            menuChoice = false ;
        else
            cout<< "Wrong Choice, but operation menu is not terminated by default.\n";
            
    }
    
    
    // Give up the elements allocated from memory
    
    delete [] RandomMatrice.elements ;

    delete [] FileMatrice.elements ;
    
    
    
    
    
    
    return 0;
}
Beispiel #19
0
/*!
 * \fn  void afficheCalcul(std::string& user, const int type)
 * \brief Affiche Le Calcul de matrice
 */
void afficheCalcul(std::string& user, const int type)
{
	int maxChoix = 0, choix1 = 0, choix2 = 0, val = 0;
	double v = 0;
	std::string mat1 = "", mat2 = "", info = "";
	Matrice *A = NULL, *B = NULL;

	maxChoix = afficheSM(type);

	if (type == 1 || type == 2 || type == 3) {
		if(maxChoix > 1)	  std::cout << "  - Veuillez indiquer votre choix (1 à " << maxChoix << ", r, q ou x[choix] pour supprimer) : ";
		else if(maxChoix == 1) std::cout << "  - Veuillez indiquer votre choix (1 , r, q ou x1 pour supprimer) : ";
		else		  std::cout << "  - Veuillez créer des matrices (r ou q) : ";

		getline(std::cin, user);
		choix1 = atoi(user.c_str()); // on change string en int

		std::cout << "  - Veuillez indiquer votre choix pour le squalaire : ";
		getline(std::cin, user);
		if (type == 3) {
			val = atoi(user.c_str());
		}
		else {
			v = atof(user.c_str());
		}
	}
	else if (type == 4 || type == 5 || type == 6 || type == 7) {
		if (maxChoix > 1) {
			std::cout << "  - Veuillez indiquer votre choix comme matrice (1 à " << maxChoix << ", r, q ou x[choix] pour supprimer)" << std::endl;
			std::cout << "  - Veuillez indiquer votre choix pour la première matrice : ";
			getline(std::cin, user);
			choix1 = atoi(user.c_str()); // on change string en int

			if (user[0] != 'x') {
				std::cout << "  - Veuillez indiquer votre choix pour la deuxieme matrice : ";
				getline(std::cin, user);
				choix2 = atoi(user.c_str()); // on change string en int
			}
		}
		else if (maxChoix == 1) {
			std::cout << "  - Veuillez créer des matrices ou le calcul ce fera sur la matrice elle meme (1 , r, q ou x1 pour supprimer) : ";
			getline(std::cin, user);
			choix1 = atoi(user.c_str()); // on change string en int
			choix2 = choix1;
		}
		else {
			std::cout << "  - Veuillez créer des matrices (r ou q)";
		}
	}

	if (user != "q" && user != "r" && user[0] != 'x') {
		if (((type == 1 || type == 2 || type == 3) && choix1 <= maxChoix && choix1 > 0) || ((type == 4 || type == 5 || type == 6 || type == 7) && choix1 <= maxChoix && choix1 > 0 && choix2 <= maxChoix && choix2 > 0)) //Test si le choix est valide
		{
			mat1 = trouveFichier(choix1);
			A = new Matrice("./mat/"+mat1);

			if (type == 4 || type == 5 || type == 6 || type == 7) {
				mat2 = trouveFichier(choix2);
				B = new Matrice("./mat/"+mat2);
			}

			if (type == 1) {
				*A *= v;
			}
			else if (type == 2) {
				*A /= v;
			}
			else if (type == 3) {
				A->Pow(val);
			}
			else if (type == 4) {
				*A += *B;
			}
			else if (type == 5) {
				*A -= *B;
			}
			else if (type == 6) {
				*A *= *B;
			}
			else if (type == 7) {
				A->Hadamard(*B);
			}

			std::cout << std::endl << *A << std::endl << "  - Voulez vous sauvegarder la matrice ? (y, n) : ";
			getline(std::cin, user);

			if (user == "y") {
				std::cout << "  - Veuillez donner un nom à la matrice : ";
				getline(std::cin, user);

				saveBdd(user, A);			
			}

			delete A;
			A = NULL;
			delete B;
			B = NULL;
		}

		else {
			system("clear");
			if(maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
			else if(maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
			else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
		}
	}

	else if (user[0] == 'x') {
		user.erase(0,1); //supprime le x
		choix2 = atoi(user.c_str()); // on change string en int
		if (choix2 <= maxChoix && choix2 > 0) {
			removeSave(trouveFichier(choix2));
			system("clear");
		}
		else {
			system("clear");
			if(maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
			else if(maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
			else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
		}	
	}

	system("clear");
}
Beispiel #20
0
void Forces::FillMatrix(){
  if(!IfFillMatrix) return;
  IntMatrix->Clear();
  double Inter = pEdge(CLat1)/(double)NEdge;//fabs(pPos(1,0) - pPos(0,0));
  SPLINE Weight;
  Weight.a0 = Kf.El[2];
  Weight.a1 = 0./Inter;
  Weight.a2 = Kf.Lap/SQR(Inter);
  Weight.a3 = 0./(Inter*SQR(Inter));
  Weight.a4 = Kf.SLap/(SQR(Inter)*SQR(Inter));
  if(VAR_IF_TYPE(SysShape,SYS_ROD)){
    int NDim = 1;
    Matrice *CoeffMatrix = new Matrice(Weight,NDim);
    CoeffMatrix->Print();
    for(int r=0;r<pNPart();r++){
      if(Pm[r].Typ != 0){ IntMatrix->Set(r,r,1.);continue;}
      if(r >= 2) IntMatrix->Set(r,r-2,CoeffMatrix->Val(2,0));
      if(r >= 1) IntMatrix->Set(r,r-1,CoeffMatrix->Val(2,1));
      if(r < pNPart()-1) IntMatrix->Set(r,r+1,CoeffMatrix->Val(2,3));
      if(r < pNPart()-2) IntMatrix->Set(r,r+2,CoeffMatrix->Val(2,4));
      IntMatrix->Set(r,r,CoeffMatrix->Val(2,2));
    }
    IntMatrix->Invert();
    //IntMatrix->Print();
    delete CoeffMatrix;
  }
  else if(VAR_IF_TYPE(SysShape,SYS_LEAVES)){
    int NDim = 1;
    Matrice *CoeffMatrix = new Matrice(Weight,NDim);
    CoeffMatrix->Print();
    for(int r=0;r<pNPCh();r++){
      if(Pm[r].Typ != 0){ IntMatrix->Set(r,r,1.);continue;}
      if(r >= 2) IntMatrix->Set(r,r-2,CoeffMatrix->Val(2,0));
      if(r >= 1) IntMatrix->Set(r,r-1,CoeffMatrix->Val(2,1));
      if(r < pNPart()-1) IntMatrix->Set(r,r+1,CoeffMatrix->Val(2,3));
      if(r < pNPart()-2) IntMatrix->Set(r,r+2,CoeffMatrix->Val(2,4));
      IntMatrix->Set(r,r,CoeffMatrix->Val(2,2));
    }
    //IntMatrix->Invert();
    IntMatrix->Print();
    delete CoeffMatrix;
  }
  else if(VAR_IF_TYPE(SysShape,SYS_2D)){
    int NDim = 2;
    Matrice *CoeffMatrix = new Matrice(Weight,NDim);
    CoeffMatrix->Print();
    for(int p=0;p<pNPart();p++){
      if(Pm[p].Typ != 0){
	IntMatrix->Set(p,p,1.);
	continue;
      }
      int pym1 = Ln[p].Link[0];
      int pyp1 = Ln[p].Link[1];
      int pym2 = Ln[pym1].Link[0];
      int pyp2 = Ln[pyp1].Link[1];
      int pxm1 = Ln[p].Link[2];
      int pxp1 = Ln[p].Link[3];
      int pxm2 = Ln[pxm1].Link[2];
      int pxp2 = Ln[pxp1].Link[3];
      // printf("%d)\n",p);
      //printf("%d %d %d %d\n",pym2,pym1,pyp1,pyp2);
      // printf("%d %d %d %d\n",pxm2,pxm1,pxp1,pxp2);
      if(PeriodicImage[0]){
	IntMatrix->Set(p,pxm2,CoeffMatrix->Val(2,0));
	IntMatrix->Set(p,pxm1,CoeffMatrix->Val(2,1));
	IntMatrix->Set(p,pxp1,CoeffMatrix->Val(2,3));
	IntMatrix->Set(p,pxp2,CoeffMatrix->Val(2,4));
      }
      else{
	if(pxm2 == p-2*nEdge[1])
	  IntMatrix->Set(p,pxm2,CoeffMatrix->Val(2,0));
	if(pxm1 == p-nEdge[1])
	  IntMatrix->Set(p,pxm1,CoeffMatrix->Val(2,1));
	if(pxp1 == p+nEdge[1])
	  IntMatrix->Set(p,pxp1,CoeffMatrix->Val(2,3));
	if(pxp2 == p+2*nEdge[1])
	  IntMatrix->Set(p,pxp2,CoeffMatrix->Val(2,4));
      }
      IntMatrix->Add(p,p,CoeffMatrix->Val(2,2));
      if(PeriodicImage[1]){
	IntMatrix->Set(p,pym2,CoeffMatrix->Val(2,0));
	IntMatrix->Set(p,pym1,CoeffMatrix->Val(2,1));
	IntMatrix->Set(p,pyp1,CoeffMatrix->Val(2,3));
	IntMatrix->Set(p,pyp2,CoeffMatrix->Val(2,4));
      }
      else{
	if(pym2 == p-2)
	  IntMatrix->Set(p,pym2,CoeffMatrix->Val(2,0));
	if(pym1 == p-1)
	  IntMatrix->Set(p,pym1,CoeffMatrix->Val(2,1));
	if(pyp1 == p+1)
	  IntMatrix->Set(p,pyp1,CoeffMatrix->Val(2,3));
	if(pyp2 == p+2)
	  IntMatrix->Set(p,pyp2,CoeffMatrix->Val(2,4));
      }
    }
    IntMatrix->Invert();
    //IntMatrix->Print();
    delete CoeffMatrix;
  }
  IfFillMatrix = 0;
}
Beispiel #21
0
void DrImage::ConvMatrix(){
  double Average = 0.;
  double Count = 0.;
  Matrice ImIn(NWidth,NHeight);
  for(int h=0;h<NHeight;h++){
    for(int w=0;w<NWidth;w++){
      double Sum = 1.- .3333*(data[0][h*NWidth+w]+data[1][h*NWidth+w]+data[2][h*NWidth+w]);
      //double Sum = 1. - (data[0][h*NWidth+w]+data[1][h*NWidth+w]+data[2][h*NWidth+w]);
      ImIn.Set(w,h,Sum);
      Average += Sum;
      Count += 1.;
    }
  }
  Average /= Count;
  //---------Canny---------------------
  Matematica *Mat = new Matematica;
  Matrice Canny(5,5);
  Canny.FillCanny();
  Canny.Print();
  // Mat->ApplyFilter(&ImIn,&Canny);
  // Mat->ApplyFilter(&ImIn,&Canny);
  //-----------Edge-------------------
  SPLINE Weight;
  Weight.a0 = 0.;
  Weight.a1 = 1.; Weight.a2 = 0.;
  Weight.a3 = 0.; Weight.a4 = 0.;
  Matrice *Mask = new Matrice(Weight,3);
  Mask->Print();
  //Mat->ApplyFilter(&ImIn,Mask);
  // Mask->Transpose();
  // Mat->ApplyFilter(ImIn,Mask);
  //-------------Smooth----------------
  const int NMatSize = 5;
  Matrice GaussEdge(NMatSize,NMatSize);
  GaussEdge.FillGaussian(.5,1.);
  //double LatPos[5] = {.125,-.25,0.,.25,-.125};
  // double LatPos[3] = {-1.,0.,1.};
  // for(int w=0;w<NMatSize;w++){
  //   for(int h=0;h<NMatSize;h++){
  //     GaussEdge.Set(w,h,GaussEdge.Val(w,h)*LatPos[w]);
  //   }
  // }
  GaussEdge.Print();
  //Mat->ApplyFilter(ImIn,&GaussEdge);
  Matrice GaussSmooth(5,5);
  GaussSmooth.FillGaussian(.5,3.);
  // Mat->ApplyFilter(ImIn,&GaussSmooth);
  //------------PixDev------------------
  for(int h=0;h<NHeight;h++){
    for(int w=0;w<NWidth;w++){
      ImIn.Set(w,h,Average-ImIn.Val(w,h));
    }
  }
  int PixelDev = 5;
  double ValStep[3] = {0.,0.,0.};
  int ValNStep[3] = {0,0,0};
  for(int h=0;h<NHeight;h++){
    for(int w=0;w<NWidth;w++){
      ValNStep[0] = w - PixelDev;
      if(ValNStep[0] < 0 ) continue;
      if(ValNStep[0] >= NWidth) continue;
      ValNStep[1] = w;
      ValNStep[2] = w + PixelDev;
      if(ValNStep[2] < 0 ) continue;
      if(ValNStep[2] >= NWidth) continue;
      for(int d=0;d<3;d++){
	ValStep[d] = ImIn.Val(ValNStep[d],h);
 	if(d == 1){
	  ValStep[d] = ValStep[d] > 0. ? ValStep[d] : 0.;
	  continue;
	}
	ValStep[d] = ValStep[d] < 0. ? -ValStep[d] : 0.;
      }
      double Resp = ValStep[0]*ValStep[1]*ValStep[2];
      //double Resp = ValStep[1];
      //ImIn.Set(w,h,Resp);
    } 
  }
  char cImage[160];
  sprintf(cImage,"Canny.png");
  pngwriter ImageOut(NWidth,NHeight,1.0,cImage);
  FILE *Ciccia = fopen("Pos3d.dat","w");
  double NormH = 1./(double)NHeight;
  double NormW = 1./(double)NWidth;
  for(int h=0;h<NHeight;h++){
    for(int w=0;w<NWidth;w++){
      fprintf(Ciccia,"%lf %lf %lf\n",w*NormH,h*NormH,ImIn.Val(w,h));
      ImageOut.plot(w,h,ImIn.Val(w,h),ImIn.Val(w,h),ImIn.Val(w,h));
    }
  }
  fclose(Ciccia);
  ImageOut.close();
}
Beispiel #22
0
/*!
 * \fn  void afficheIM(std::string& user)
 * \brief Affiche Le Menu Information de matrice
 */
void afficheIM(std::string& user)
{
	do
	{
		system("clear");

		int maxChoix = 0, choix = 0;
		std::string mat = "", info = "";
		Matrice* A = NULL;

		maxChoix = afficheSM();

		getline(std::cin, user);
		choix = atoi(user.c_str()); // on change string en int

		if (user != "q" && user != "r" && user[0] != 'x') {
			if (choix <= maxChoix && choix > 0) {
				mat = trouveFichier(choix);

				A = new Matrice("./mat/"+mat);

				system("clear");

				std::cout << std::endl << *A << std::endl << std::endl;

				std::cout << " Nombre de lignes : " << A->getLigne() << std::endl;
				std::cout << " Nombre de colonne : " << A->getColonne() << std::endl << std::endl;

				std::cout << " Matrice nulle? : " << A->Null() << std::endl;
				std::cout << " Matrice creuse? : " << A->Creuse() << std::endl;
				std::cout << " Matrice diagonale? : " << A->Diagonale() << std::endl;
				std::cout << " Matrice carrée? : " << A->Carre() << std::endl << std::endl;

				do {
					std::cout << "  - Que voulez vous faire ? (c = chercher la valeur d'un case, r = retour ou q = quitter): ";
					getline(std::cin, user);

					if (user == "c") {//Cherche la valeur demandé
						int l = 0, c = 0;

						std::cout << "  - Veuillez inserer la ligne : ";
						getline(std::cin, user);
						l = atoi(user.c_str());

						std::cout << "  - Veuillez inserer la colonne : ";
						getline(std::cin, user);
						c = atoi(user.c_str());

						std::cout << jaune << "La valeur de la coordonnée " << Coordonnee(l, c) << " est : " << A->Valeur(l, c) << reset << std::endl;
					}
					else if (user == "r") system("clear"); //Retourner menu precedent
					else if (user == "q"){} //Quitter
					else //Erreur
					{
						system("clear");
						std::cout << rouge << "Veuillez inserer c, r ou q" << reset << std::endl;
					}
				}while (user != "q" && user != "r");

				delete A;
				A = NULL;
			}
			else {
				system("clear");
				if (maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
				else if (maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
				else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
			}
		}

		else if (user[0] == 'x') {
			user.erase(0,1); //supprime le x
			choix = atoi(user.c_str()); // on change string en int
			if (choix <= maxChoix && choix > 0) {
				removeSave(trouveFichier(choix));
				system("clear");
			}
			else {
				system("clear");
				if (maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
				else if (maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
				else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
			}	
		}
	}while (user != "r" && user != "q");

	system("clear");
}
Beispiel #23
0
/*!
 * \fn void afficheCrM(std::string& user)
 * \brief Affiche Le Menu Création de matrice 
 */
void afficheCrM(std::string& user)
{
	system("clear");

	do {
	
		afficheTitreCrM();

		std::cout << "\t\t   1 = Matrice (1 valeur pour toutes les cases)" << std::endl;
		std::cout << "\t\t   2 = Matrice Identitée" << std::endl;
		std::cout << "\t\t   3 = Matrice Personnalisee" << std::endl;
		std::cout << "\t\t   4 = Matrice Aleatoire" << std::endl << std::endl;

		std::cout << "\t\t   r = Retour" << std::endl;
		std::cout << "\t\t   q = Quitter" << std::endl << std::endl;

		std::cout << "  - Veuillez indiquer votre choix (1, 2, 3, 4, r ou q): ";
		getline(std::cin, user);

		system("clear");
		afficheTitreCrM();

		Matrice *A = NULL;

		if (user == "1") {
			A = new Matrice(true);
			user = "******";
		}
		else if (user == "2") {
			std::cout << "  - Veuillez indiquer l'ordre de la matrice identitée: ";
			getline(std::cin, user);

			A = new Matrice(atoi(user.c_str()));
			user = "******";
		}
		else if (user == "3") {
			A = new Matrice(false);
			user = "******";
		}
		else if (user == "4") {
			A = new Matrice();
			user = "******";
		}
		else if (user == "r") system("clear"); //Retourner menu precedent
		else if (user == "q"){} //Quitter
		else //Erreur
		{
			system("clear");
			std::cout << rouge << "             Veuillez inserer 1, 2, r ou q              " << reset << std::endl;
		}

//Sauvegarde et modification de matrice

		if (user == "m") {
			do {
				std::cout << std::endl << *A << std::endl << std::endl << "  - Voulez vous modifier des valeurs de la matrice ? (y = oui, r = retour ou q = quitter): ";
				getline(std::cin, user);

				if(user == "y") {

					double v = 0;
					int l = 0, c = 0;

					std::cout << "  - Veuillez inserer la ligne : ";
					getline(std::cin, user);
					l = atoi(user.c_str());

					std::cout << "  - Veuillez inserer la colonne : ";
					getline(std::cin, user);
					c = atoi(user.c_str());

					std::cout << "  - Veuillez inserer la valeur : ";
					getline(std::cin, user);
					v = atof(user.c_str());

					A->Insert(l, c, v);
				}
				else if (user == "r" || user == "q"){} //Retourner menu precedent ou Quitter
				else //Erreur
				{
					system("clear");
					std::cout << rouge << "             Veuillez inserer y, r ou q              " << reset << std::endl;
				}
			}while (user != "q" && user != "r");

			std::string tmp = "";

			std::cout << "  - Voulez vous sauvegarder la matrice ? (y = oui, n = non) : ";
			getline(std::cin, tmp);

			if (tmp == "y") {
				std::cout << std::endl << "  - Veuillez donner un nom à la matrice : ";
				getline(std::cin, tmp);

				saveBdd(tmp, A);			
			}


			delete A;
			A = NULL;

			system("clear");
		}

	}while (user != "q" && user != "r");

	system("clear");
}
Beispiel #24
0
/*!
 * \fn void afficheMM(std::string& user)
 * \brief Affiche Le Menu Modification de matrice
 */
void afficheMM(std::string& user)
{
	do {
		system("clear");

		int maxChoix = 0, choix = 0;
		std::string mat = "", info = "";
		Matrice* A = NULL;

		maxChoix = afficheSM();

		getline(std::cin, user);
		choix = atoi(user.c_str()); // on change string en int

		if (user != "q" && user != "r" && user[0] != 'x') {
			if (choix <= maxChoix && choix > 0) {
				mat = trouveFichier(choix);

				A = new Matrice("./mat/"+mat);

				do {
					system("clear");
					afficheTitreMM();

					std::cout << std::endl << *A << std::endl << std::endl << "  - Que voulez vous faire ? (m = modifier, s = sous matrice, r ou q): ";
					getline(std::cin, user);

					if (user == "m") {
						double v = 0;
						int l = 0, c = 0;

						std::cout << std::endl << std::endl << "  - Veuillez inserer la ligne : ";
						getline(std::cin, user);
						l = atoi(user.c_str());

						std::cout << "  - Veuillez inserer la colonne : ";
						getline(std::cin, user);
						c = atoi(user.c_str());

						std::cout << "  - Veuillez inserer la valeur : ";
						getline(std::cin, user);
						v = atof(user.c_str());

						A->Insert(l, c, v);
					}
					else if (user == "s") {
						int l1 = 0, l2 = 0, c1 = 0, c2 = 0;

						std::cout << std::endl << std::endl << "  - Veuillez inserer la ligne de depart: ";
						getline(std::cin, user);
						l1 = atoi(user.c_str());

						std::cout << "  - Veuillez inserer la ligne de fin: ";
						getline(std::cin, user);
						l2 = atoi(user.c_str());


						std::cout << std::endl << std::endl << "  - Veuillez inserer la colonne de depart: ";
						getline(std::cin, user);
						c1 = atoi(user.c_str());

						std::cout << "  - Veuillez inserer la colonne de fin: ";
						getline(std::cin, user);
						c2 = atoi(user.c_str());

						A->SousMatrice(l1, l2, c1, c2);
					}
					else if(user == "r") system("clear"); //Retourner menu precedent
					else if(user == "q"){} //Quitter
					else //Erreur
					{
						system("clear");
						std::cout << rouge << "             Veuillez inserer y, r ou q              " << reset << std::endl;
					}
				}while (user != "q" && user != "r");

				std::cout << std::endl << *A << std::endl << "  - Voulez vous sauvegarder la matrice ? (y, n) : ";
				getline(std::cin, info);

				if (info == "y") {
					std::cout << std::endl << *A << std::endl << "  - Veuillez donner un nom à la matrice : ";
					getline(std::cin, info);

					saveBdd(info, A);			
				}

				delete A;
				A = NULL;
			}

			else {
				system("clear");
				if (maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
				else if (maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
				else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
			}
		}

		else if (user[0] == 'x') {
			user.erase(0,1); //supprime le x
			choix = atoi(user.c_str()); // on change string en int
			if (choix <= maxChoix && choix > 0) {
				removeSave(trouveFichier(choix));
				system("clear");
			}

			else {
				system("clear");
				if(maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
				else if(maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
				else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
			}	
		}
	}while (user != "r" && user != "q");

	system("clear");
}
void launchTestsAndExitIfOk()
{
    Tests sessionDeTests("pCiscrea");

    /* 	Test des calculs de propulsion vectorielle	*/

    // Contrôle de la consigne
    AUV auv_ciscrea_test;

    auv_ciscrea_test.setVx(3);
    auv_ciscrea_test.setVy(5);
    auv_ciscrea_test.setVz(-10);
    auv_ciscrea_test.setRz(-31);
    Matrice *vecteurConsigne = auv_ciscrea_test.getVecteurConsigneAUV();

    sessionDeTests.tester((*vecteurConsigne)[0][0] == 3, "enregistrement consigne Vx");
    sessionDeTests.tester((*vecteurConsigne)[1][0] == 5, "enregistrement consigne Vy");
    sessionDeTests.tester((*vecteurConsigne)[2][0] == -10, "enregistrement consigne Vz");
    sessionDeTests.tester((*vecteurConsigne)[3][0] == 0, "enregistrement consigne Rx");
    sessionDeTests.tester((*vecteurConsigne)[4][0] == 0, "enregistrement consigne Ry");
    sessionDeTests.tester((*vecteurConsigne)[5][0] == -31, "enregistrement consigne Rz");

    // Contrôle des forces des propulseurs (non nulles en Vy et Vz seulement)
    auv_ciscrea_test.setVx(0);
    auv_ciscrea_test.setVy(5);
    auv_ciscrea_test.setVz(36);
    auv_ciscrea_test.setRz(0);
    vecteurConsigne = auv_ciscrea_test.getVecteurConsigneAUV();
    Matrice *forcesPropulseurs = auv_ciscrea_test.getForcesPropulseurs();

    sessionDeTests.tester((*forcesPropulseurs)[0][0] != 0, "Vy & Vz != 0 : controle force non nulle appliquee en F1");	// F1
    sessionDeTests.tester((*forcesPropulseurs)[1][0] != 0, "Vy & Vz != 0 : controle force non nulle appliquee en F2");	// F2
    sessionDeTests.tester((*forcesPropulseurs)[2][0] != 0, "Vy & Vz != 0 : controle force non nulle appliquee en F3");	// F3
    sessionDeTests.tester((*forcesPropulseurs)[3][0] != 0, "Vy & Vz != 0 : controle force non nulle appliquee en F4");	// F4
    sessionDeTests.tester((*forcesPropulseurs)[4][0] != 0, "Vy & Vz != 0 : controle force non nulle appliquee en F5");	// F5
    sessionDeTests.tester(round((*forcesPropulseurs)[5][0]) == round((*forcesPropulseurs)[4][0]), "Vy & Vz != 0 : controle non force F5 = F6");	// F6

    // Contrôle des forces des propulseurs (non nulles en Vz seulement)
    auv_ciscrea_test.setVx(0);
    auv_ciscrea_test.setVy(0);
    auv_ciscrea_test.setVz(12);
    auv_ciscrea_test.setRz(0);
    vecteurConsigne = auv_ciscrea_test.getVecteurConsigneAUV();
    forcesPropulseurs = auv_ciscrea_test.getForcesPropulseurs();

    sessionDeTests.tester((*forcesPropulseurs)[0][0] == 0, "Vz != 0 : controle force nulle appliquee en F1");	// F1
    sessionDeTests.tester((*forcesPropulseurs)[1][0] == 0, "Vz != 0 : controle force nulle appliquee en F2");	// F2
    sessionDeTests.tester((*forcesPropulseurs)[2][0] == 0, "Vz != 0 : controle force nulle appliquee en F3");	// F3
    sessionDeTests.tester((*forcesPropulseurs)[3][0] == 0, "Vz != 0 : controle force nulle appliquee en F4");	// F4
    sessionDeTests.tester((*forcesPropulseurs)[4][0] != 0, "Vz != 0 : controle force non nulle appliquee en F5");	// F5
    sessionDeTests.tester(round((*forcesPropulseurs)[5][0]) == round((*forcesPropulseurs)[4][0]), "Vz != 0 : controle force non nulle F5 = F6");	// F6

    // Contrôle des forces des propulseurs (non nulles en Vz seulement)
    auv_ciscrea_test.setVx(-29);
    auv_ciscrea_test.setVy(0);
    auv_ciscrea_test.setVz(0);
    auv_ciscrea_test.setRz(0);
    vecteurConsigne = auv_ciscrea_test.getVecteurConsigneAUV();
    forcesPropulseurs = auv_ciscrea_test.getForcesPropulseurs();
    forcesPropulseurs->afficher();
    sessionDeTests.tester((*forcesPropulseurs)[0][0] != 0, "Vx != 0 : controle force non nulle appliquee en F1");	// F1
    sessionDeTests.tester((*forcesPropulseurs)[1][0] != 0, "Vx != 0 : controle force non nulle appliquee en F2");	// F2
    sessionDeTests.tester((*forcesPropulseurs)[2][0] != 0, "Vx != 0 : controle force non nulle appliquee en F3");	// F3
    sessionDeTests.tester((*forcesPropulseurs)[3][0] != 0, "Vx != 0 : controle force non nulle appliquee en F4");	// F4
    sessionDeTests.tester((*forcesPropulseurs)[4][0] == 0, "Vx != 0 : controle force nulle appliquee en F5");	// F5
    sessionDeTests.tester(round((*forcesPropulseurs)[5][0]) == round((*forcesPropulseurs)[4][0]), "Vx != 0 : controle force nulle F5 = F6");	// F6

    sessionDeTests.afficherConclusionTests();
}
Beispiel #26
0
Matrice operator+(const Matrice& matrice1,const Matrice& matrice2){
	if(matrice1.TailleLigne() == matrice2.TailleLigne() 
			&& matrice1.TailleColonne() == matrice2.TailleColonne()){
		Matrice res(matrice1.TailleLigne(), matrice1.TailleColonne());
		for(int i=0; i < matrice1.NombreCases(); i++){
			for(int j=0;j < matrice2.NombreCases(); j++){
				if(matrice1(i).caseLigne == matrice2(j).caseLigne && matrice1(i).caseColonne == matrice2(j).caseColonne){
					if(matrice1(i).caseLigne == 0 && matrice1(i).caseColonne == 0)
						res.AjouterCase(matrice1(i).caseLigne,matrice1(i).caseColonne,matrice1(i).caseValeur + matrice2(j).caseValeur);
					else
						res.ModifierCase(matrice1(i).caseLigne,matrice1(i).caseColonne,matrice1(i).caseValeur + matrice2(j).caseValeur);
				}
				else{
					if(!res.EstPresent(matrice1(i)))
						res.AjouterCase(matrice1(i).caseLigne,matrice1(i).caseColonne,matrice1(i).caseValeur);
					if(!res.EstPresent(matrice2(j)))
						res.AjouterCase(matrice2(j).caseLigne,matrice2(j).caseColonne,matrice2(j).caseValeur);
				}
			}
		}
		return res;
	}
	else{
		cerr << "Les matrices ("<<matrice1.TailleLigne() << ","
			 << matrice1.TailleColonne() << ") et ("
			 << matrice2.TailleLigne() << "," << matrice2.TailleColonne() << ")"
			 << " ne sont pas additionnables." << endl;
		return NULL;
	}
}
Beispiel #27
0
void afficheTM(std::string& user)
{
	do {
		system("clear");

		int maxChoix = 0, choix = 0;
		std::string mat = "", info = "";
		Matrice* A = NULL;
	
		maxChoix = afficheSM();

		getline(std::cin, user);
		choix = atoi(user.c_str()); // on change string en int

		if (user != "q" && user != "r" && user[0] != 'x') {
			if (choix <= maxChoix && choix > 0) {
				mat = trouveFichier(choix);

				A = new Matrice("./mat/"+mat);

				A->Transpose();

				std::cout << std::endl << *A << std::endl << "  - Voulez vous sauvegarder la matrice ? (y, n) : ";
				getline(std::cin, user);

				if (user == "y") {
					std::cout << std::endl << *A << std::endl << "  - Veuillez donner un nom à la matrice : ";
					getline(std::cin, user);

					saveBdd(user, A);			
				}

				delete A;
				A = NULL;
			}

			else {
				system("clear");
				if(maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
				else if(maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
				else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
			}
		}

		else if (user[0] == 'x') {
			user.erase(0,1); //supprime le x
			choix = atoi(user.c_str()); // on change string en int
			if (choix <= maxChoix && choix > 0) {
				removeSave(trouveFichier(choix));
				system("clear");
			}
			else {
				system("clear");
				if(maxChoix > 1) std::cout << rouge << "        Veuillez inserer 1 à " << maxChoix << ", r, q ou x[choix]        " << reset << std::endl;
				else if(maxChoix == 1) std::cout << rouge << "             Veuillez inserer 1, r, q ou x1             " << reset << std::endl;
				else std::cout << rouge << "                Veuillez inserer r ou q                 " << reset << std::endl;
			}	
		}
	}while (user != "r" && user != "q");

	system("clear");
}