Ignore:
Timestamp:
Nov 17, 1999, 7:49:32 PM (26 years ago)
Author:
ercodmgr
Message:

finalisation interfacage TMatrix, PixelMap - Reza 17/11/99

File:
1 edited

Legend:

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

    r585 r594  
    11#include "machdefs.h"
    22#include <stdlib.h>
     3#include <math.h>
    34#include <typeinfo>
    45#include <iostream.h>
     
    1011#include "spheregorski.h"
    1112#include "localmap.h"
    12 
     13#include "pitvmaad.h"
     14#include "complexios.h"
     15
     16//  Classe array adapter pour localMap
     17template <class T>
     18class LocalMapArrAdapter : public P2DArrayAdapter {
     19public:
     20                LocalMapArrAdapter(LocalMap<T>* lm, bool d=false) :
     21                    P2DArrayAdapter(lm->XSize(), lm->YSize())
     22                    { ad = d; map = lm; }
     23
     24  virtual       ~LocalMapArrAdapter() { if (ad) delete map; }
     25  virtual double  Value(int ix, int iy) { return((*map)(ix, iy)); }
     26
     27protected :
     28  bool ad;
     29  LocalMap<T>* map;
     30};
     31
     32/* --Methode-- */
     33double LocalMapArrAdapter< complex<float> >::Value(int ix, int iy)
     34{
     35double re,im;
     36re = (*map)(iy, ix).real();
     37im = (*map)(iy, ix).imag();
     38return(sqrt(re*re+im*im));
     39}
     40/* --Methode-- */
     41double LocalMapArrAdapter< complex<double> >::Value(int ix, int iy)
     42{
     43double re,im;
     44re = (*map)(iy, ix).real();
     45im = (*map)(iy, ix).imag();
     46return(sqrt(re*re+im*im));
     47}
    1348
    1449//----------------------------------------------------------------
     
    2055template <class T>
    2156NOMAdapter_PixelMap<T>::NOMAdapter_PixelMap(PixelMap<T> * o)
    22   : NObjMgrAdapter((AnyDataObj *)o)
     57  : NObjMgrAdapter(o)
    2358{
    2459mMap = o;
     
    84119{
    85120string s = typeid(*mMap).name();
     121T moy, sig;
     122MeanSig(moy, sig);
    86123cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
     124cout << "  Mean= " << moy << "  Sig2= " << sig << endl;
    87125}
    88126
     
    92130P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
    93131{
    94 return(NULL);
     132LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
     133if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
     134int nr = 250;
     135int nc = 500;
     136SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
     137if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels());  nc = 2*nr; }
     138TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
     139Project_Mol(*mtx);
     140return (new POTMatrixAdapter<T>(mtx, true) );
    95141}
    96142
     
    103149}
    104150
    105 
     151/* --Methode-- */
     152template <class T>
     153void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig)
     154{
     155  gmoy=0.;
     156  gsig = 0.;
     157  T valok;
     158  for(int k=0; k<mMap->NbPixels(); k++) {
     159    valok = (*mMap)(k);
     160    gmoy += valok;  gsig += valok*valok;
     161  }
     162  gmoy /= (T)mMap->NbPixels();
     163  gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy;
     164
     165}
     166
     167/* --Methode-- */
     168template <class T>
     169void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval)
     170{
     171  r_8 xa, yd, teta,phi, facteur;
     172  int_4 l,c,k;
     173  int_4 nl = mtx.NRows();
     174  int_4 nc = mtx.NCols();
     175  mtx.Reset(defval);   // On met tout a defval
     176//  cout << " NRows= " << nl << "  NCols= " << nc  << endl;
     177  for(l=0; l<nl; l++) {
     178    yd = (r_8)(l+0.5)/(r_8)nl-0.5;
     179    facteur=2.*M_PI/sin(acos((double)yd*2));
     180    teta = (yd+0.5)*Pi;
     181    //    teta = (0.5-yd)*M_PI;
     182    for(c=0; c<nc; c++)  {
     183      xa = (r_8)(c+0.5)/(r_8)nc-0.5;
     184      phi = xa*facteur+M_PI;
     185      if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
     186        k = mMap->PixIndexSph(teta, phi);
     187        mtx(l,c) = (*mMap)(k);
     188      }
     189    }
     190  }
     191}
    106192
    107193// -------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.