Changeset 3713 in Sophya for trunk/SophyaPI
- Timestamp:
- Dec 11, 2009, 9:57:10 AM (16 years ago)
- Location:
- trunk/SophyaPI/PIext
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/nomtarradapter.cc
r3661 r3713 224 224 TVector<T>* v = new TVector<T>(arr, true); // on partage les donnees 225 225 dopt = "thinline," + dopt; 226 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, true ), NULL, true) );226 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, true, StringToCmplxDispOption(dopt)), NULL, true) ); 227 227 } 228 228 else { … … 234 234 /* --Methode-- */ 235 235 template <class T> 236 P2DArrayAdapter* NOMAdapter_TArray<T>::Get2DArray(string & )236 P2DArrayAdapter* NOMAdapter_TArray<T>::Get2DArray(string & dopt) 237 237 { 238 238 TArray<T> arr(*mArr, true); // on partage les donnees … … 241 241 // On peut en faire un tableau 2-D ... 242 242 TMatrix<T>* m = new TMatrix<T>(arr, true); // on partage les donnees 243 return ( new POTMatrixAdapter<T>(m, true ) );243 return ( new POTMatrixAdapter<T>(m, true, StringToCmplxDispOption(dopt)) ); 244 244 } 245 245 else { -
trunk/SophyaPI/PIext/nomtmatvecadapter.cc
r3661 r3713 234 234 else { 235 235 dopt = "thinline " + dopt; 236 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false ), NULL, true) );237 } 238 } 239 240 /* --Methode-- */ 241 template <class T> 242 P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string & )236 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false, StringToCmplxDispOption(dopt)), NULL, true) ); 237 } 238 } 239 240 /* --Methode-- */ 241 template <class T> 242 P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string & dopt) 243 243 { 244 244 Image<T>* img = dynamic_cast<Image<T> *>(mMtx); 245 245 if (img != NULL) return ( new ImageAdapter<T>(img, false) ); 246 else return ( new POTMatrixAdapter<T>(mMtx, false) ); 247 } 246 else return ( new POTMatrixAdapter<T>(mMtx, false, StringToCmplxDispOption(dopt)) ); 247 } 248 248 249 249 250 // ---- Specialisation pour complexes ----- 250 251 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 251 P2DArrayAdapter* NOMAdapter_TMatrix< complex<r_4> >::Get2DArray(string & )252 { 253 return ( new POTMatrixAdapter< complex<r_4> >(mMtx, false) );254 } 255 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 256 P2DArrayAdapter* NOMAdapter_TMatrix< complex<r_8> >::Get2DArray(string & )257 { 258 return ( new POTMatrixAdapter< complex<r_8> >(mMtx, false) );252 P2DArrayAdapter* NOMAdapter_TMatrix< complex<r_4> >::Get2DArray(string & dopt) 253 { 254 return ( new POTMatrixAdapter< complex<r_4> >(mMtx, false, StringToCmplxDispOption(dopt) ) ); 255 } 256 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 257 P2DArrayAdapter* NOMAdapter_TMatrix< complex<r_8> >::Get2DArray(string & dopt) 258 { 259 return ( new POTMatrixAdapter< complex<r_8> >(mMtx, false, StringToCmplxDispOption(dopt) ) ); 259 260 } 260 261 // ------------------------------------------------------------- -
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__ -
trunk/SophyaPI/PIext/pitvmaad.h
r3520 r3713 13 13 #include "tvector.h" 14 14 15 // Definition d'enum pour choix de la quantite affichee pour les tableaux de complexes. 16 enum PICmplxDispOption { PICDO_Module, PICDO_Real, PICDO_Imag, PICDO_Phase, PICDO_Module2 }; 17 // Decode la presence d'une chaine opt contenant cdreal , cdimag , cdphase , cdmod , cdmod2 18 PICmplxDispOption StringToCmplxDispOption( string & opt ); 15 19 16 20 // Adaptateur de vecteurs SOPHYA a P1DArrayAdapter … … 18 22 class POTVectorAdapter : public P1DArrayAdapter { 19 23 public : 20 POTVectorAdapter(TVector<T>* v, bool ad=false);24 POTVectorAdapter(TVector<T>* v, bool ad=false, PICmplxDispOption dopt=PICDO_Module); 21 25 virtual ~POTVectorAdapter(); 22 26 virtual double Value(int i); 23 27 24 28 protected: 29 PICmplxDispOption dOpt; 25 30 bool aDel; 26 31 TVector<T>* mVec; … … 35 40 class POTMatrixAdapter : public P2DArrayAdapter { 36 41 public : 37 POTMatrixAdapter(TMatrix<T>* mtx, bool ad=false);42 POTMatrixAdapter(TMatrix<T>* mtx, bool ad=false, PICmplxDispOption dopt=PICDO_Module); 38 43 virtual ~POTMatrixAdapter(); 39 44 virtual double Value(int ix, int iy); … … 41 46 42 47 protected: 48 PICmplxDispOption dOpt; 43 49 bool aDel; 44 50 TMatrix<T>* mMtx;
Note:
See TracChangeset
for help on using the changeset viewer.