1 #include "../include/Matematica.h" 4 int *Sequence = (
int *)calloc(NMass,
sizeof(
int));
5 for(
int n=0;n<NMass;n++){
7 int Ran = (int)(NMass*
Casuale());
10 for(
int gg= nSquare-1;gg>=0;gg--){
12 if(nSquare == Sequence[gg]){
17 if(!IfAlready)
continue;
18 while(Ran==nSquare || !IfGood){
21 for(
int gg= nSquare-1;gg>=0;gg--){
23 if(Ran == Sequence[gg]){
29 Sequence[nSquare] = Ran;
30 Sequence[Ran] = nSquare;
33 for(
int n=0;n<NMass;n++){
35 Perm[n].
m = Sequence[n];
38 for(
int n=0;n<NMass;n++){
39 if(Perm[n-nTemp].m < n ){
40 for(
int nn=n-nTemp;nn<NMass-1-nTemp;nn++){
41 Perm[nn].
n = nn+1+nTemp;
42 Perm[nn].
m = Sequence[nn+1+nTemp];
51 for(
int n=0;n<NMass;n++){
53 int Ran = (int)(NMass*
Casuale());
56 for(
int gg= nSquare-1;gg>=0;gg--){
58 if(nSquare == Sequence[gg]){
63 if(!IfAlready)
continue;
64 while(Ran==nSquare || !IfGood){
67 for(
int gg= nSquare-1;gg>=0;gg--){
69 if(Ran == Sequence[gg]){
75 Sequence[nSquare] = Ran;
76 Sequence[Ran] = nSquare;
84 printf(
"Matrices differ! %d %d \n",Point->
Size(),Res->
Size());
87 int NMaskh = Mask->
Size();
88 int NMaskw = Mask->
Size();
89 int height = Point->
Size();
90 int width = Point->
Size();
91 int NHalf = Mask->
Size()/2;
92 for(
int h=0;h<height; h++) {
93 for(
int w=0;w<width; w++) {
95 for(
int lh=0;lh<NMaskh;lh++){
96 for(
int lw=0;lw<NMaskw;lw++){
97 if(h+lh-NHalf <0 )
continue;
98 if(w+lw-NHalf <0 )
continue;
99 if(h+lh-NHalf > height-1)
continue;
100 if(w+lw-NHalf > width-1)
continue;
101 Res->
Add(h,w,Mask->
Val(lh,lw)*Point->
Val(h+lh-NHalf,w+lw-NHalf));
109 int NMaskh = Mask->
pNRow();
110 int NMaskw = Mask->
pNCol();
112 int width = Res->
pNRow();
113 int height = Res->
pNCol();
117 int NHalf = (int)Mask->
pNCol()/2;
118 for(
int h=0;h<height; h++) {
119 for(
int w=0;w<width; w++) {
122 for(
int lh=0;lh<NMaskh;lh++){
123 int l1h = h + lh - NHalf;
124 if(l1h >= height)
continue;
125 if(l1h < 0)
continue;
126 for(
int lw=0;lw<NMaskw;lw++){
127 int l1w = w + lw - NHalf;
128 if(l1w >= width)
continue;
129 if(l1w < 0)
continue;
130 dTemp += Mask->
Val(lw,lh)*Temp->
Val(l1w,l1h);
141 if( OP_IF(operation,OP_INVERT) ){
142 for(
int r=0;r<NEdge;r++)
143 for(
int c=0;c<NEdge;c++)
144 Out[r*NEdge+c] = In[r*NEdge+c] == 1 ? 0 : 1;
146 if( OP_IF(operation,OP_ROT_90) ){
147 for(
int r=0;r<NEdge;r++)
148 for(
int c=0;c<NEdge;c++)
149 Out[r*NEdge+c] = In[(NMin-c)*NEdge+r];
151 if( OP_IF(operation,OP_ROT_180) ){
152 for(
int r=0;r<NEdge;r++)
153 for(
int c=0;c<NEdge;c++)
154 Out[r*NEdge+c] = In[(NMin-r)*NEdge+(NMin-c)];
156 if( OP_IF(operation,OP_ROT_270) ){
157 for(
int r=0;r<NEdge;r++)
158 for(
int c=0;c<NEdge;c++)
159 Out[r*NEdge+c] = In[c*NEdge+(NMin-r)];
161 if( OP_IF(operation,OP_MIRROR) ){
162 for(
int r=0;r<NEdge;r++)
163 for(
int c=0;c<NEdge;c++)
164 Out[r*NEdge+c] = In[r*NEdge+(NMin-c)];
166 if( OP_IF(operation,OP_TRANSPOSE) ){
167 for(
int r=0;r<NEdge;r++)
168 for(
int c=0;c<NEdge;c++)
169 Out[r*NEdge+c] = In[c*NEdge+r];
174 for(
int r=0;r<In->
pNRow();r++){
177 if(r1 < 0) r1 += In->
pNRow();
178 for(
int c=0;c<In->
pNCol();c++){
179 Out->
Set(r1,c,In->
Val(r,c));
int pNCol()
Number of columns.
int m
Second number of the couple.
void BackFold(Matrice *In, Matrice *Out, int NShift)
Shift all the rows upwards/downwards.
int Transform(int *Out, int *In, int NEdge, int operation)
Boh.
void CopyOn(Matrice *B)
Copy on a matrix.
Indices for the permutation.
int PermuteRandomAll(int *Sequence, int NMass)
Permutes a sequence without repeating.
int n
First number of the couple.
double Casuale()
Random uniform number.
double Val(int row)
Returns a value in 1d.
bool Add(int row, int col, double Val)
Add the value of the coefficient to the previous one.
Matrice computes the algebric operations on matrices.
bool Set(int row, int column, double Val)
Set a coefficient.
int Size()
Size of Matrice.
int ApplyFilter(Matrice *Point, Matrice *Res, Matrice *Mask)
Applies the filter.
int pNRow()
Number of rows.