#include "sopnamsp.h" #include "machdefs.h" #include #include #include #include #include #include #include "datatype.h" #include "nomskymapadapter.h" #include "skymap.h" #include "pitvmaad.h" #include "complexios.h" // Valeur par defaut pour la projection MolleWeide, en dehors de la sphere static double _prjmol_defval = 0.; void Set_Project_Mol_DefVal(double def) { _prjmol_defval = def; return; } // Classe array adapter pour localMap template class LocalMapArrAdapter : public P2DArrayAdapter { public: LocalMapArrAdapter(LocalMap* lm, bool d=false) : P2DArrayAdapter(lm->SizeX(), lm->SizeY()) { ad = d; map = lm; } virtual ~LocalMapArrAdapter() { if (ad) delete map; } virtual double Value(int ix, int iy) { return((*map)(ix, iy)); } virtual double MeanVal(int ix1, int ix2, int jy1, int jy2) { int ec; if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } double ss = 0.; for(int j=jy1; j<=jy2; j++) for(int i=ix1; i<=ix2; i++) ss += (double)((*map)(i, j)); ss /= (double)((jy2-jy1+1)*(ix2-ix1+1)); return ss; } protected : bool ad; LocalMap* map; }; /* --Methode-- */ DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ double LocalMapArrAdapter< complex >::Value(int ix, int iy) { double re,im; re = (*map)(iy, ix).real(); im = (*map)(iy, ix).imag(); return(sqrt(re*re+im*im)); } /* --Methode-- */ DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ double LocalMapArrAdapter< complex >::Value(int ix, int iy) { double re,im; re = (*map)(iy, ix).real(); im = (*map)(iy, ix).imag(); return(sqrt(re*re+im*im)); } /* --Methode-- */ DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ double LocalMapArrAdapter< complex >::MeanVal(int ix1, int ix2, int jy1, int jy2) { int ec; if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } complex ss = 0.; for(int j=jy1; j<=jy2; j++) for(int i=ix1; i<=ix2; i++) ss += (*map)(i, j); ss /= (double)((jy2-jy1+1)*(ix2-ix1+1)); return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag()); } /* --Methode-- */ DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ double LocalMapArrAdapter< complex >::MeanVal(int ix1, int ix2, int jy1, int jy2) { int ec; if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; } if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; } complex ss = 0.; for(int j=jy1; j<=jy2; j++) for(int i=ix1; i<=ix2; i++) ss += (*map)(i, j); ss /= (double)((jy2-jy1+1)*(ix2-ix1+1)); return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag()); } //---------------------------------------------------------------- // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap //---------------------------------------------------------------- /* --Methode-- */ template NOMAdapter_PixelMap::NOMAdapter_PixelMap(PixelMap * o) : NObjMgrAdapter(o) { mMap = o; } /* --Methode-- */ template NOMAdapter_PixelMap::~NOMAdapter_PixelMap() { } /* --Methode-- */ template NObjMgrAdapter* NOMAdapter_PixelMap::Clone(AnyDataObj* o) { PixelMap* m = dynamic_cast *>(o); if (m) return ( new NOMAdapter_PixelMap(m) ); return ( new NObjMgrAdapter(o) ); } /* --Methode-- */ template string NOMAdapter_PixelMap::GetDataObjType() { string type = "PixelMap< "; LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) type = "LocalMap< "; SphereThetaPhi* st = dynamic_cast< SphereThetaPhi * >(mMap); if (st != NULL) type = "SphereThetaPhi< "; SphereHEALPix* sg = dynamic_cast< SphereHEALPix * >(mMap); if (sg != NULL) type = "SphereHEALPix< "; SphereECP* se = dynamic_cast< SphereECP * >(mMap); if (se != NULL) type = "SphereECP< "; // type += DecodeTypeIdName(typeid(T).name()); type += DataTypeInfo::getTypeName(); type += " > "; return(type); } /* --Methode-- */ template AnyDataObj* NOMAdapter_PixelMap::CloneDataObj(bool share) { LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) return( new LocalMap(*lm, share) ); SphereThetaPhi* st = dynamic_cast< SphereThetaPhi * >(mMap); if (st != NULL) return( new SphereThetaPhi(*st, share) ); SphereHEALPix* sg = dynamic_cast< SphereHEALPix * >(mMap); if (sg != NULL) return( new SphereHEALPix(*sg, share) ); SphereECP* se = dynamic_cast< SphereECP * >(mMap); if (se != NULL) return( new SphereECP(*se, share) ); return(NULL); } /* --Methode-- */ template void NOMAdapter_PixelMap::SavePPF(POutPersist& pos, string const & nom) { LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) { FIO_LocalMap fio(lm); fio.Write(pos, nom); return; } SphereThetaPhi* st = dynamic_cast< SphereThetaPhi * >(mMap); if (st != NULL) { FIO_SphereThetaPhi fio(st); fio.Write(pos, nom); return; } SphereHEALPix* sg = dynamic_cast< SphereHEALPix * >(mMap); if (sg != NULL) { FIO_SphereHEALPix fio(sg); fio.Write(pos, nom); return; } SphereECP* se = dynamic_cast< SphereECP * >(mMap); if (se != NULL) { FIO_SphereECP fio(se); fio.Write(pos, nom); return; } string s = typeid(*mMap).name(); cout << "NOMAdapter_PixelMap::SavePPF() - Error : Not supported for " << s << endl; } /* --Methode-- */ template void NOMAdapter_PixelMap::Print(ostream& os, int lev) { mMap->Show(os); if (lev > 0) { T moy, sig; MeanSig(moy, sig); os << "PixelMap: Mean= " << moy << " Sig2= " << sig << endl; } if (lev > 1) { int_4 nprmx = 10*lev; if (nprmx > mMap->NbPixels()) nprmx = mMap->NbPixels(); os << "[k] (Theta,Phi) : PixVal" << endl; double t, p; for(int k=0; kPixThetaPhi(k, t, p); os << "[" << k << "] (" << t << "," << p << ") : " << mMap->PixVal(k) << endl; } } } // -- Fonction pour convertir un X,Y en Theta-Phi sur projection MolleWeide -- char * _SphMollweideProj_XY2ThetaPhi(P2DArrayAdapter * aa, int ix, int iy); /* --Methode-- */ template P2DArrayAdapter* NOMAdapter_PixelMap::Get2DArray(string & opt) { LocalMap* lm = dynamic_cast< LocalMap * >(mMap); if (lm != NULL) return(new LocalMapArrAdapter(lm, false)); int nr = 250; int nc = 500; SphereECP* se = dynamic_cast< SphereECP * >(mMap); size_t olen = opt.length(); if ((se != NULL) && (opt.find("ecparray") < olen)) { // On veut la carte bi-dim complete de la sphere ECP TMatrix * mtxecp = new TMatrix(se->GetPixelArray(), true); // on partage les donnees POTMatrixAdapter * potmtxecp = new POTMatrixAdapter(mtxecp, true); if (opt.find("ecpscaledeg") < olen) // Echelle angulaire en degre potmtxecp->DefineXYCoordinates(se->MinPhi()*180./M_PI, se->MinTheta()*180./M_PI, se->DeltaPhi()*180./M_PI, se->DeltaTheta()*180./M_PI); else if (opt.find("ecpscalerad") < olen) // Echelle angulaire en radian potmtxecp->DefineXYCoordinates(se->MinPhi(), se->MinTheta(), se->DeltaPhi(), se->DeltaTheta()); return ( potmtxecp ); } SphericalMap* sm = dynamic_cast< SphericalMap *>(mMap); if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; } TMatrix * mtx = new TMatrix(nr, nc); Project_Mol(*mtx, (T)_prjmol_defval); POTMatrixAdapter * potma = new POTMatrixAdapter(mtx, true); potma->DefineXYCoordinates(0.,90.,360./(double)(mtx->NCols()),-180./(double)(mtx->NRows())); potma->SetInfoStringFunction(_SphMollweideProj_XY2ThetaPhi); return ( potma ); } /* --Methode-- */ template NTupleInterface* NOMAdapter_PixelMap::GetNTupleInterface(bool& adel) { adel = true; return( new NTupInt_PixelMap(mMap) ); } /* --Methode-- */ template void NOMAdapter_PixelMap::MeanSig(T& gmoy, T& gsig) { gmoy=0.; gsig = 0.; T valok; for(int k=0; kNbPixels(); k++) { valok = (*mMap)(k); gmoy += valok; gsig += valok*valok; } gmoy /= (T)mMap->NbPixels(); gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy; } /* --Methode-- */ template void NOMAdapter_PixelMap::Project_Mol(TMatrix & mtx, T defval) { r_8 xa, yd, teta,phi, facteur; int_4 l,c,k; int_4 nl = mtx.NRows(); int_4 nc = mtx.NCols(); mtx = defval; // On met tout a defval // cout << " NRows= " << nl << " NCols= " << nc << endl; for(l=0; l= 0.) ) { k = mMap->PixIndexSph(teta, phi); mtx(l,c) = (*mMap)(k); } } } } static char m_buff[128]; char * _SphMollweideProj_XY2ThetaPhi(P2DArrayAdapter * aa, int ix, int iy) { r_8 xa, yd, teta,phi, facteur; int_4 nl = aa->YSize(); int_4 nc = aa->XSize(); int l, c; aa->IJ2xy(ix, iy, c, l); yd = (r_8)(l+0.5)/(r_8)nl-0.5; facteur=2.*M_PI/sin(acos((double)yd*2)); teta = (yd+0.5)*Pi; xa = (r_8)(c+0.5)/(r_8)nc-0.5; phi = xa*facteur+M_PI; if ( (phi <= 2*M_PI) && (phi >= 0.) ) sprintf(m_buff,"(l,b=%5.1f,%5.1f)", phi*180./M_PI, 90.-teta*180./M_PI); else sprintf(m_buff,"(l,b=?,?)"); return (m_buff); } // ------------------------------------------------------------- /* --Methode-- */ template NTupInt_PixelMap::NTupInt_PixelMap(PixelMap* m) { mMap = m; } /* --Methode-- */ template NTupInt_PixelMap::~NTupInt_PixelMap() { } /* --Methode-- */ template sa_size_t NTupInt_PixelMap::NbLines() const { return( mMap->NbPixels() ); } /* --Methode-- */ template sa_size_t NTupInt_PixelMap::NbColumns() const { return(8); } /* --Methode-- */ template r_8* NTupInt_PixelMap::GetLineD(sa_size_t n) const { int i; if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) for(i=0; i<8; i++) mRet[i] = 0.; else { double teta,phi; mMap->PixThetaPhi(n, teta, phi); mRet[0] = n; mRet[1] = mMap->PixVal(n); mRet[2] = mRet[1]; mRet[3] = 0.; mRet[4] = mRet[1]; mRet[5] = 0.; mRet[6] = teta; mRet[7] = phi; } return(mRet); } /* --Methode-- */ template string NTupInt_PixelMap::VarList_C(const char* nx) const { string nomx; if (nx) nomx = nx; else nomx = "_xh_"; string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n"; vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n"; vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n"; vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n"; vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n"; return(vardec); } DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ r_8* NTupInt_PixelMap< complex >::GetLineD(sa_size_t n) const { int i; if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) for(i=0; i<8; i++) mRet[i] = 0.; else { double teta,phi; mMap->PixThetaPhi(n, teta, phi); mRet[0] = n; mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag(); mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]); mRet[5] = atan2(mRet[3], mRet[2]); mRet[6] = teta; mRet[7] = phi; } return(mRet); } DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ r_8* NTupInt_PixelMap< complex >::GetLineD(sa_size_t n) const { int i; if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) for(i=0; i<8; i++) mRet[i] = 0.; else { double teta,phi; mMap->PixThetaPhi(n, teta, phi); mRet[0] = n; mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag(); mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]); mRet[5] = atan2(mRet[3], mRet[2]); mRet[6] = teta; mRet[7] = phi; } return(mRet); } #ifdef __CXX_PRAGMA_TEMPLATES__ #pragma define_template NOMAdapter_PixelMap #pragma define_template NOMAdapter_PixelMap #pragma define_template NOMAdapter_PixelMap #pragma define_template NOMAdapter_PixelMap< complex > #pragma define_template NOMAdapter_PixelMap< complex > #pragma define_template NTupInt_PixelMap #pragma define_template NTupInt_PixelMap #pragma define_template NTupInt_PixelMap #pragma define_template NTupInt_PixelMap< complex > #pragma define_template NTupInt_PixelMap< complex > #endif #if defined(ANSI_TEMPLATES) template class NOMAdapter_PixelMap; template class NOMAdapter_PixelMap; template class NOMAdapter_PixelMap; template class NOMAdapter_PixelMap< complex >; template class NOMAdapter_PixelMap< complex >; template class NTupInt_PixelMap; template class NTupInt_PixelMap; template class NTupInt_PixelMap; template class NTupInt_PixelMap< complex >; template class NTupInt_PixelMap< complex >; #endif