1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
| ////////////////////////////////////////////////////////////////////////// CACMatrix
////////////// Constructeur //////////////////
CACMatrix::CACMatrix()
{
C = 0;
L = 0;
M = NULL;
}
CACMatrix::CACMatrix(int l, int c)
{
int x,y;
C = c;
L = l;
M = new long*[L];
for(y=0;y<L;y++)
{
M[y] = new long[C];
for(x=0;x<C;x++) M[y][x]=0;
}
}
////////////// Destructeur //////////////////
CACMatrix::~CACMatrix()
{
for(int y=0;y<L;y++) delete [] M[y];
delete [] M;
}
////////////// Oérateur ///////////////////
CACMatrix& CACMatrix::operator*(CACMatrix& m) const {
CACMatrix* x;
if(C==m.GetL())
{
x = new CACMatrix(L,m.GetC());
for(int l=0;l<L;l++)
{
for(int c=0;c<m.GetC(); c++)
{
int r = 0;
for(int n=0;n<C; n++)
r = M[l][n]*m.GetValeur(n,c);
x->SetValeur(l,c,r);
}
}
}
else
{
x = new CACMatrix();
}
return *x
}
////////////// Accesseur ///////////////////
long CACMatrix::GetL()
{
return L;
}
long CACMatrix::GetC()
{
return L;
}
long CACMatrix::GetValeur(int l, int c)
{
return M[l][c];
}
void CACMatrix::SetValeur(int l, int c, long v)
{
M[l][c] = v;
}
void CACMatrix::SetLigne(int l, CACVector* V)
{
for(int x=0;x<C;x++)
{
if(x<V->GetN()) M[l][x]=V->GetValeur(x);
else M[l][x]=0;
}
}
void CACMatrix::AddLigne(CACVector* v)
{
long** t;
int l,c;
if((v==NULL)||(L==0))
{
L = 0;
C = v->GetN();
}
if(v->GetN()==C)
{
// création du nouveau tableau
t = new long*[L+1];
// recopie du tableau existant
for(l=0;l<L;l++)
{
t[l] = new long[C];
for(c=0;c<C;c++) t[l][c]=M[l][c];
}
for(int y=0;y<L;y++) delete [] M[y];
delete [] M;
// modification du nombre de ligne
L = L+1;
// ajout du vecteur
t[l] = new long[C];
for(int c=0;c<C; c++) t[l][c] = v->GetValeur(c);
M = t;
}
}
CACVector* CACMatrix::SommeColonne()
{
CACVector * profil = new CACVector(C);
for(int x=0;x<C;x++)
{
long v = 0;
for(int y=0;y<L;y++)
{
v = v + (long)M[y][x];
}
profil->SetValeur(x,v);
}
return profil;
}
CACVector* CACMatrix::DeriveLigne()
{
CACVector * S = SommeColonne();
S->Deriver();
S->Absolu();
return S;
}
void CACMatrix::Absolu()
{
for(int y=0;y<L;y++) for(int x=0;x<C;x++) if(M[y][x]<0) M[y][x]=-M[y][x];
}
void CACMatrix::SetAllPixel(int p)
{
for(int y=0;y<L;y++)
{
for(int x=0;x<C;x++)
{
M[y][x]=p;
}
}
}
void CACMatrix::Delete()
{
for(int y=0;y<L;y++) delete [] M[y];
delete [] M;
}
////////////////////////////////////////////////////////////////////////////////////// |
Partager