00001
00002
00003
00004
00005 #include "Wavelet.hpp"
00006
00007 void MatrixShape::Transpose() {
00008 int i ;
00009 i=BL0 , BL0=BL1 , BL1=i ;
00010 i=BR0 , BR0=BR1 , BR1=i ;
00011 i=M , M =N , N =i ;
00012 }
00013
00014 void MatrixShape::Print() {
00015 std::cout <<"BL0/1 "<<BL0<<'/'<<BL1<<" BR0/1 "<<BR0<<'/'<<BR1<<" M/N "<<M<<'/'<<N<<" U/O "<<U<<'/'<<O<<'\n' ;
00016 }
00017
00018
00019
00020
00021 void TransformMatrix::GetShape(int l,MatrixShape *S)
00022 {
00023 S->N=1<<l ;
00024 S->M=(1<<(l-1))-IsWT ;
00025
00026 S->BL0=AL[0].size[0]-1 ;
00027 S->BL1=AL[0].size[1]-1 ;
00028 S->BR0=AR[0].size[0]-1 ; S->BR0=S->M-S->BR0 ;
00029 S->BR1=AR[0].size[1]-1 ; S->BR1=S->N-S->BR1 ;
00030 S->U=U ;
00031 S->O=O ;
00032 }
00033
00034 void TransformMatrix::Copy(TransformMatrix *M)
00035 {
00036 int i ;
00037 for (i=0;i<(int)(sizeof(AL)/sizeof(AL[0]));i++) {
00038 AL[i].Copy(&M->AL[i]) ;
00039 AR[i].Copy(&M->AR[i]) ;
00040 }
00041
00042 for (i=0; i<(int)(sizeof(a)/sizeof(a[0])); i++) a[i]=M->a[i] ;
00043
00044 U=M->U ;
00045 O=M->O ;
00046
00047 IsWT=M->IsWT ;
00048 }
00049
00050
00051
00052
00053
00054
00055 int TransformMatrixFirstNZE(int j,MatrixShape *S)
00056 { if (j<=S->BL1) return 0 ;
00057 if (j<S->BR1) return (j-S->O+1)/2 ;
00058 return min( (j-S->O+1)/2, S->BR0) ; }
00059
00060 int TransformMatrixLastNZE (int j,MatrixShape *S)
00061 { if (j<=S->BL1) return max( S->BL0,(j+S->U)/2) ;
00062 if (j<S->BR1) return min( (j+S->U)/2 , S->M) ;
00063 return S->M ; }
00064
00065 int TransformMatrixFirstNZEP(int j,MatrixShape *S) { return ceil2(j-S->O) ; }
00066 int TransformMatrixLastNZEP (int j,MatrixShape *S) { return (j+S->U)/2 ; }
00067
00068
00069
00070 int TransformMatrixTransposeFirstNZE(int j,MatrixShape *S)
00071 { if (j<=S->BL1) return 0 ;
00072 if (j<S->BR1) return 2*j-S->U ;
00073 return S->BR0 ; }
00074
00075 int TransformMatrixTransposeLastNZE(int j,MatrixShape *S)
00076 { if (j<=S->BL1) return S->BL0 ;
00077 if (j<S->BR1) return 2*j+S->O ;
00078 return S->M ; }
00079
00080 int TransformMatrixTransposeFirstNZEP(int j,MatrixShape *S) { return 2*j-S->U ; }
00081 int TransformMatrixTransposeLastNZEP (int j,MatrixShape *S) { return 2*j+S->O ; }
00082
00083
00084
00085 int TransformMatrixFirst2NZE(int j,MatrixShape *S)
00086 { if (j<=S->BL1) return 0 ;
00087 if (j<S->BR1) return (j-S->O)/2 ;
00088 return min( (j-S->O)/2, S->BR0) ; }
00089
00090 int TransformMatrixLast2NZE (int j,MatrixShape *S)
00091 { if (j<=S->BL1) return max( S->BL0,(j+S->U+1)/2) ;
00092 if (j<S->BR1) return min( (j+S->U+1)/2 , S->M) ;
00093 return S->M ; }
00094
00095 int TransformMatrixFirst2NZEP(int j,MatrixShape *S) { return floor2(j-S->O) ; }
00096 int TransformMatrixLast2NZEP (int j,MatrixShape *S) { return (j+S->U+1)/2 ; }
00097
00098
00099 void TransformMatrix::Print()
00100 {
00101 int i ;
00102 std::cout << "U="<<U<<" O="<<O<<'\n' ;
00103 for (i=-U; i<=O; i++) std::cout <<a[i+U]<<' ' ;
00104 std::cout<<'\n' ;
00105 std::cout<< "IsWT="<<IsWT<<'\n' ;
00106 }
00107
00108
00109
00110
00111 OperatorMatrix::OperatorMatrix() { power=1e+100 ; IsWT=IsWF=0 ;}
00112
00113 void OperatorMatrix::Print()
00114 {
00115 int i ;
00116 std::cout<<"IsWT="<<IsWT<<" IsWF="<<IsWF<<" | pow="<<power<<" | U="<<U<<" O="<<O<<'\n' ;
00117 for (i=0; i<=U+O; i++) std::cout<<a[i]<<'\n' ;
00118 AL[0][0].Print() ;
00119 ALT[0][0].Print() ;
00120 AR[0][0].Print() ;
00121 ART[0][0].Print() ;
00122 }
00123
00124 void OperatorMatrix::GetShape(int l,MatrixShape *S)
00125 {
00126 S->N=(1<<l)-IsWF ;
00127 S->M=(1<<l)-IsWT ;
00128
00129 S->BL0=AL[0][0].size[0]+ALT[0][0].size[0]-1 ;
00130 S->BL1=AL[0][0].size[1]-1 ;
00131 S->BR0=AR[0][0].size[0]+ART[0][0].size[0]-1 ; S->BR0=S->M-S->BR0 ;
00132 S->BR1=AR[0][0].size[1]-1 ; S->BR1=S->N-S->BR1 ;
00133 S->U=U ;
00134 S->O=O ;
00135 }
00136
00137
00138 int OperatorMatrixFirstNZE (int j,MatrixShape *S)
00139 { if (j<=S->BL1) return 0 ;
00140 if (j<S->BR1) return j-S->U ;
00141 return min(j-S->U,S->BR0) ; }
00142
00143 int OperatorMatrixLastNZE (int j,MatrixShape *S)
00144 { if (j<=S->BL1) return max( S->BL0,j+S->O) ;
00145 if (j<S->BR1) return j+S->O ;
00146 return S->M ; }
00147
00148
00149 int OperatorMatrixFirstNZEP(int j,MatrixShape *S) { return j-S->U ; }
00150 int OperatorMatrixLastNZEP (int j,MatrixShape *S) { return j+S->O ; }
00151
00152
00153 int OperatorMatrixFirst2NZE (int j,MatrixShape *S) {
00154 if (j< S->BL1) return -1 ;
00155 if (j==S->BL1) return S->BL0 ;
00156 if (j< S->N ) return min(S->BR0-1,j-S->O) ;
00157 return S->M ;
00158 }
00159
00160 int OperatorMatrixLast2NZE (int j,MatrixShape *S) {
00161 if (j==0) return 0 ;
00162 if (j< S->BR1) return max(S->BL0+1,j + S->U) ;
00163 if (j==S->BR1) return S->BR0 ;
00164 return S->M+1 ;
00165 }
00166
00167
00168 int OperatorMatrixFirst2NZEP(int j,MatrixShape *S) { return j-S->O ; }
00169 int OperatorMatrixLast2NZEP (int j,MatrixShape *S) { return j+S->U ; }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 void LiftingMatrix::GetShape(int l,MatrixShape *S)
00190 {
00191 S->N= 1<<l ;
00192 S->M=(1<<l)-1 ;
00193
00194 S->BL0=QL[0].size[0]-1 ;
00195 S->BL1=QL[0].size[1]-1 ;
00196 S->BR0=QR[0].size[0]-1 ; S->BR0=S->M-S->BR0 ;
00197 S->BR1=QR[0].size[1]-1 ; S->BR1=S->N-S->BR1 ;
00198 S->U=U ;
00199 S->O=O ;
00200 }
00201
00202
00203 int LiftingMatrixTransposeFirstNZE (int j,MatrixShape *S) {
00204 if (j<=S->BL0) return 0 ;
00205 if (j>=S->BR0) return S->BR1 ;
00206 return j-S->U ;
00207 }
00208
00209 int LiftingMatrixTransposeLastNZE (int j,MatrixShape *S) {
00210 if (j<=S->BL0) return S->BL1 ;
00211 if (j>=S->BR0) return S->N ;
00212 return j+S->O ;
00213 }
00214
00215 int LiftingMatrixTransposeFirstNZEP (int j,MatrixShape *S) { return j-S->U ;}
00216 int LiftingMatrixTransposeLastNZEP (int j,MatrixShape *S) { return j+S->O ;}
00217