Changeset 3713 in Sophya


Ignore:
Timestamp:
Dec 11, 2009, 9:57:10 AM (16 years ago)
Author:
ansari
Message:

Ajout options afichage cdreal,cdimag,cdphas,cdmod,cdmod2 pour tableaux complexes, Reza 11/12/2009

Location:
trunk/SophyaPI/PIext
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/nomtarradapter.cc

    r3661 r3713  
    224224  TVector<T>* v = new TVector<T>(arr, true);  // on partage les donnees
    225225  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) );
    227227}
    228228else {
     
    234234/* --Methode-- */
    235235template <class T>
    236 P2DArrayAdapter* NOMAdapter_TArray<T>::Get2DArray(string &)
     236P2DArrayAdapter* NOMAdapter_TArray<T>::Get2DArray(string & dopt)
    237237{
    238238TArray<T> arr(*mArr, true);    // on partage les donnees
     
    241241  // On peut en faire un tableau 2-D ...
    242242  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)) );
    244244}
    245245else {
  • trunk/SophyaPI/PIext/nomtmatvecadapter.cc

    r3661 r3713  
    234234else {
    235235  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-- */
     241template <class T>
     242P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string & dopt)
    243243{
    244244Image<T>* img = dynamic_cast<Image<T> *>(mMtx);
    245245if (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
    248249
    249250// ---- Specialisation pour complexes -----
    250251DECL_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) );
     252P2DArrayAdapter* NOMAdapter_TMatrix< complex<r_4> >::Get2DArray(string & dopt)
     253{
     254  return ( new POTMatrixAdapter< complex<r_4> >(mMtx, false, StringToCmplxDispOption(dopt) ) );
     255}
     256DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
     257P2DArrayAdapter* NOMAdapter_TMatrix< complex<r_8> >::Get2DArray(string & dopt)
     258{
     259  return ( new POTMatrixAdapter< complex<r_8> >(mMtx, false, StringToCmplxDispOption(dopt) ) );
    259260}
    260261// -------------------------------------------------------------
  • trunk/SophyaPI/PIext/pitvmaad.cc

    r3661 r3713  
    77#include <math.h>
    88
    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
     12PICmplxDispOption StringToCmplxDispOption( string & opt )
     13{
     14PICmplxDispOption dopt=PICDO_Module;
     15size_t olen = opt.length();
     16if (opt.find("cdmod2")<olen) dopt=PICDO_Module2;
     17else if (opt.find("cdmod")<olen) dopt=PICDO_Module;
     18else if (opt.find("cdphas")<olen) dopt=PICDO_Phase;
     19else if (opt.find("cdimag")<olen) dopt=PICDO_Imag;
     20else if (opt.find("cdreal")<olen) dopt=PICDO_Real;
     21else dopt=PICDO_Module;
     22return dopt; 
     23}
     24
     25/* --- Methodes de calcul inline pour valeurs de retour complexes ---- */
     26static inline double  _z_mod_( complex< r_4 > z)
     27{
     28  return ( sqrt((double)(z.real()*z.real()+z.imag()*z.imag() ) ) );
     29}
     30static inline double  _z_mod_( complex< r_8 > z)
     31{
     32  return ( sqrt(z.real()*z.real()+z.imag()*z.imag() )  );
     33}
     34static inline double  _z_mod2_( complex< r_4 > z)
     35{
     36  return ( (double)(z.real()*z.real()+z.imag()*z.imag() ) );
     37}
     38static inline double  _z_mod2_( complex< r_8 > z)
     39{
     40  return ( z.real()*z.real()+z.imag()*z.imag() );
     41}
     42/* ----------------------------  */
     43
     44/* --Methode-- */
     45template <class T>
     46POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad, PICmplxDispOption dopt)
    1247        : P1DArrayAdapter(v->NElts())
    1348{
     49dOpt = dopt;
    1450aDel = ad;
    1551mVec = v;
     
    2662double POTVectorAdapter<T>::Value(int i)
    2763{
    28 return((*mVec)(i));
     64  return((double)(*mVec)(i));
    2965}
    3066
     
    3369double POTVectorAdapter< complex<float> >::Value(int i)
    3470{
    35 double re,im;
    36 re = (*mVec)(i).real();
    37 im = (*mVec)(i).imag();
    38 return(sqrt(re*re+im*im));
     71switch (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 }
    3988}
    4089
     
    4392double POTVectorAdapter< complex<double> >::Value(int i)
    4493{
    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)
     94switch (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-- */
     114template <class T>
     115POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad, PICmplxDispOption dopt)
    54116        : P2DArrayAdapter(mtx->NCols(), mtx->NRows())
    55117{
     118dOpt = dopt;
    56119aDel = ad;
    57120mMtx = mtx;
     
    89152double POTMatrixAdapter< complex<float> >::Value(int ix, int iy)
    90153{
    91 double re,im;
    92 re = (*mMtx)(iy, ix).real();
    93 im = (*mMtx)(iy, ix).imag();
    94 return(sqrt(re*re+im*im));
     154switch (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 }
    95171}
    96172
     
    99175double POTMatrixAdapter< complex<double> >::Value(int ix, int iy)
    100176{
    101 double re,im;
    102 re = (*mMtx)(iy, ix).real();
    103 im = (*mMtx)(iy, ix).imag();
    104 return(sqrt(re*re+im*im));
     177switch (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 }
    105194}
    106195
     
    112201if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
    113202if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }   
    114 complex<float> ss = 0.;
     203complex<float> ssz = complex<float>(0.,0.);
    115204for(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);
     206switch (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 }
     223return 0.; 
    119224}   
    120225
     
    126231if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
    127232if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }   
    128 complex<double> ss = 0.;
     233complex<double> ssz = complex<double>(0.,0.);
    129234for(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);
     236switch (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 }
     253return 0.; 
    133254}   
     255
     256
     257
     258
    134259
    135260#ifdef __CXX_PRAGMA_TEMPLATES__
  • trunk/SophyaPI/PIext/pitvmaad.h

    r3520 r3713  
    1313#include "tvector.h"
    1414
     15// Definition d'enum pour choix de la quantite affichee pour les tableaux de complexes.
     16enum 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
     18PICmplxDispOption StringToCmplxDispOption( string & opt );
    1519
    1620// Adaptateur de vecteurs SOPHYA a P1DArrayAdapter
     
    1822class POTVectorAdapter : public P1DArrayAdapter {
    1923public :
    20                   POTVectorAdapter(TVector<T>* v, bool ad=false);
     24  POTVectorAdapter(TVector<T>* v, bool ad=false, PICmplxDispOption dopt=PICDO_Module);
    2125  virtual         ~POTVectorAdapter();
    2226  virtual double  Value(int i);
    2327
    2428protected:
     29  PICmplxDispOption dOpt;
    2530  bool aDel;
    2631  TVector<T>* mVec;
     
    3540class POTMatrixAdapter :  public P2DArrayAdapter {
    3641public :
    37                   POTMatrixAdapter(TMatrix<T>* mtx, bool ad=false);
     42  POTMatrixAdapter(TMatrix<T>* mtx, bool ad=false, PICmplxDispOption dopt=PICDO_Module);
    3843  virtual         ~POTMatrixAdapter();
    3944  virtual double  Value(int ix, int iy);
     
    4146
    4247protected:
     48  PICmplxDispOption dOpt;
    4349  bool aDel;
    4450  TMatrix<T>* mMtx;
Note: See TracChangeset for help on using the changeset viewer.