Changeset 3713 in Sophya for trunk/SophyaPI/PIext/pitvmaad.cc
- Timestamp:
- Dec 11, 2009, 9:57:10 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pitvmaad.cc
r3661 r3713 7 7 #include <math.h> 8 8 9 /* --Methode-- */ 10 template <class T> 11 POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad) 9 // ------------------------------------------------------- 10 // Decodage de la presence dans la chaine opt des options d'affichage pour tableaux complexes 11 // cdreal , cdimag , cdphase , cdmod , cdmod2 12 PICmplxDispOption StringToCmplxDispOption( string & opt ) 13 { 14 PICmplxDispOption dopt=PICDO_Module; 15 size_t olen = opt.length(); 16 if (opt.find("cdmod2")<olen) dopt=PICDO_Module2; 17 else if (opt.find("cdmod")<olen) dopt=PICDO_Module; 18 else if (opt.find("cdphas")<olen) dopt=PICDO_Phase; 19 else if (opt.find("cdimag")<olen) dopt=PICDO_Imag; 20 else if (opt.find("cdreal")<olen) dopt=PICDO_Real; 21 else dopt=PICDO_Module; 22 return dopt; 23 } 24 25 /* --- Methodes de calcul inline pour valeurs de retour complexes ---- */ 26 static inline double _z_mod_( complex< r_4 > z) 27 { 28 return ( sqrt((double)(z.real()*z.real()+z.imag()*z.imag() ) ) ); 29 } 30 static inline double _z_mod_( complex< r_8 > z) 31 { 32 return ( sqrt(z.real()*z.real()+z.imag()*z.imag() ) ); 33 } 34 static inline double _z_mod2_( complex< r_4 > z) 35 { 36 return ( (double)(z.real()*z.real()+z.imag()*z.imag() ) ); 37 } 38 static inline double _z_mod2_( complex< r_8 > z) 39 { 40 return ( z.real()*z.real()+z.imag()*z.imag() ); 41 } 42 /* ---------------------------- */ 43 44 /* --Methode-- */ 45 template <class T> 46 POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad, PICmplxDispOption dopt) 12 47 : P1DArrayAdapter(v->NElts()) 13 48 { 49 dOpt = dopt; 14 50 aDel = ad; 15 51 mVec = v; … … 26 62 double POTVectorAdapter<T>::Value(int i) 27 63 { 28 return((*mVec)(i));64 return((double)(*mVec)(i)); 29 65 } 30 66 … … 33 69 double POTVectorAdapter< complex<float> >::Value(int i) 34 70 { 35 double re,im; 36 re = (*mVec)(i).real(); 37 im = (*mVec)(i).imag(); 38 return(sqrt(re*re+im*im)); 71 switch (dOpt) { 72 case PICDO_Module: 73 return _z_mod_( (*mVec)(i) ); 74 break; 75 case PICDO_Real: 76 return (double)(((*mVec)(i)).real()); 77 break; 78 case PICDO_Imag: 79 return (double)(((*mVec)(i)).imag()); 80 break; 81 case PICDO_Phase: 82 return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) ); 83 break; 84 case PICDO_Module2: 85 return _z_mod2_( (*mVec)(i) ); 86 break; 87 } 39 88 } 40 89 … … 43 92 double POTVectorAdapter< complex<double> >::Value(int i) 44 93 { 45 double re,im; 46 re = (*mVec)(i).real(); 47 im = (*mVec)(i).imag(); 48 return(sqrt(re*re+im*im)); 49 } 50 51 /* --Methode-- */ 52 template <class T> 53 POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad) 94 switch (dOpt) { 95 case PICDO_Module: 96 return _z_mod_( (*mVec)(i) ); 97 break; 98 case PICDO_Real: 99 return (double)(((*mVec)(i)).real()); 100 break; 101 case PICDO_Imag: 102 return (double)(((*mVec)(i)).imag()); 103 break; 104 case PICDO_Phase: 105 return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) ); 106 break; 107 case PICDO_Module2: 108 return _z_mod2_( (*mVec)(i) ); 109 break; 110 } 111 } 112 113 /* --Methode-- */ 114 template <class T> 115 POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad, PICmplxDispOption dopt) 54 116 : P2DArrayAdapter(mtx->NCols(), mtx->NRows()) 55 117 { 118 dOpt = dopt; 56 119 aDel = ad; 57 120 mMtx = mtx; … … 89 152 double POTMatrixAdapter< complex<float> >::Value(int ix, int iy) 90 153 { 91 double re,im; 92 re = (*mMtx)(iy, ix).real(); 93 im = (*mMtx)(iy, ix).imag(); 94 return(sqrt(re*re+im*im)); 154 switch (dOpt) { 155 case PICDO_Module: 156 return _z_mod_( (*mMtx)(iy, ix) ); 157 break; 158 case PICDO_Real: 159 return (double)(((*mMtx)(iy, ix)).real()); 160 break; 161 case PICDO_Imag: 162 return (double)(((*mMtx)(iy, ix)).imag()); 163 break; 164 case PICDO_Phase: 165 return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() ); 166 break; 167 case PICDO_Module2: 168 return _z_mod2_( (*mMtx)(iy, ix) ); 169 break; 170 } 95 171 } 96 172 … … 99 175 double POTMatrixAdapter< complex<double> >::Value(int ix, int iy) 100 176 { 101 double re,im; 102 re = (*mMtx)(iy, ix).real(); 103 im = (*mMtx)(iy, ix).imag(); 104 return(sqrt(re*re+im*im)); 177 switch (dOpt) { 178 case PICDO_Module: 179 return _z_mod_( (*mMtx)(iy, ix) ); 180 break; 181 case PICDO_Real: 182 return (double)(((*mMtx)(iy, ix)).real()); 183 break; 184 case PICDO_Imag: 185 return (double)(((*mMtx)(iy, ix)).imag()); 186 break; 187 case PICDO_Phase: 188 return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() ); 189 break; 190 case PICDO_Module2: 191 return _z_mod2_( (*mMtx)(iy, ix) ); 192 break; 193 } 105 194 } 106 195 … … 112 201 if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } 113 202 if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } 114 complex<float> ss = 0.;203 complex<float> ssz = complex<float>(0.,0.); 115 204 for(int j=jy1; j<=jy2; j++) 116 for(int i=ix1; i<=ix2; i++) ss += (*mMtx)(j, i); 117 ss /= (double)((jy2-jy1+1)*(ix2-ix1+1)); 118 return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag()); 205 for(int i=ix1; i<=ix2; i++) ssz += (*mMtx)(j, i); 206 switch (dOpt) { 207 case PICDO_Module: 208 return _z_mod_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) ); 209 break; 210 case PICDO_Real: 211 return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; 212 break; 213 case PICDO_Imag: 214 return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; 215 break; 216 case PICDO_Phase: 217 return atan2( (double) ssz.real(), (double) ssz.imag() ); 218 break; 219 case PICDO_Module2: 220 return _z_mod2_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) ); 221 break; 222 } 223 return 0.; 119 224 } 120 225 … … 126 231 if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } 127 232 if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } 128 complex<double> ss = 0.;233 complex<double> ssz = complex<double>(0.,0.); 129 234 for(int j=jy1; j<=jy2; j++) 130 for(int i=ix1; i<=ix2; i++) ss += (*mMtx)(j, i); 131 ss /= (double)((jy2-jy1+1)*(ix2-ix1+1)); 132 return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag()); 235 for(int i=ix1; i<=ix2; i++) ssz += (*mMtx)(j, i); 236 switch (dOpt) { 237 case PICDO_Module: 238 return _z_mod_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) ); 239 break; 240 case PICDO_Real: 241 return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; 242 break; 243 case PICDO_Imag: 244 return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ; 245 break; 246 case PICDO_Phase: 247 return atan2( (double) ssz.real(), (double) ssz.imag() ); 248 break; 249 case PICDO_Module2: 250 return _z_mod2_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) ); 251 break; 252 } 253 return 0.; 133 254 } 255 256 257 258 134 259 135 260 #ifdef __CXX_PRAGMA_TEMPLATES__
Note:
See TracChangeset
for help on using the changeset viewer.