| 1 | #include "machdefs.h" | 
|---|
| 2 | #include <stdlib.h> | 
|---|
| 3 | #include <math.h> | 
|---|
| 4 | #include <typeinfo> | 
|---|
| 5 | #include <iostream.h> | 
|---|
| 6 | #include <string> | 
|---|
| 7 | #include <complex> | 
|---|
| 8 |  | 
|---|
| 9 | #include "datatype.h" | 
|---|
| 10 |  | 
|---|
| 11 | #include "nomskymapadapter.h" | 
|---|
| 12 | #include "skymap.h" | 
|---|
| 13 | #include "pitvmaad.h" | 
|---|
| 14 | #include "complexios.h" | 
|---|
| 15 |  | 
|---|
| 16 | //  Classe array adapter pour localMap | 
|---|
| 17 | template <class T> | 
|---|
| 18 | class LocalMapArrAdapter : public P2DArrayAdapter { | 
|---|
| 19 | public: | 
|---|
| 20 | LocalMapArrAdapter(LocalMap<T>* lm, bool d=false) : | 
|---|
| 21 | P2DArrayAdapter(lm->SizeX(), lm->SizeY()) | 
|---|
| 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 |  | 
|---|
| 27 | protected : | 
|---|
| 28 | bool ad; | 
|---|
| 29 | LocalMap<T>* map; | 
|---|
| 30 | }; | 
|---|
| 31 |  | 
|---|
| 32 | /* --Methode-- */ | 
|---|
| 33 | double LocalMapArrAdapter< complex<float> >::Value(int ix, int iy) | 
|---|
| 34 | { | 
|---|
| 35 | double re,im; | 
|---|
| 36 | re = (*map)(iy, ix).real(); | 
|---|
| 37 | im = (*map)(iy, ix).imag(); | 
|---|
| 38 | return(sqrt(re*re+im*im)); | 
|---|
| 39 | } | 
|---|
| 40 | /* --Methode-- */ | 
|---|
| 41 | double LocalMapArrAdapter< complex<double> >::Value(int ix, int iy) | 
|---|
| 42 | { | 
|---|
| 43 | double re,im; | 
|---|
| 44 | re = (*map)(iy, ix).real(); | 
|---|
| 45 | im = (*map)(iy, ix).imag(); | 
|---|
| 46 | return(sqrt(re*re+im*im)); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | //---------------------------------------------------------------- | 
|---|
| 50 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap<T> | 
|---|
| 51 | //---------------------------------------------------------------- | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | /* --Methode-- */ | 
|---|
| 55 | template <class T> | 
|---|
| 56 | NOMAdapter_PixelMap<T>::NOMAdapter_PixelMap(PixelMap<T> * o) | 
|---|
| 57 | : NObjMgrAdapter(o) | 
|---|
| 58 | { | 
|---|
| 59 | mMap = o; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | /* --Methode-- */ | 
|---|
| 63 | template <class T> | 
|---|
| 64 | NOMAdapter_PixelMap<T>::~NOMAdapter_PixelMap() | 
|---|
| 65 | { | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | /* --Methode-- */ | 
|---|
| 69 | template <class T> | 
|---|
| 70 | NObjMgrAdapter* NOMAdapter_PixelMap<T>::Clone(AnyDataObj* o) | 
|---|
| 71 | { | 
|---|
| 72 | PixelMap<T>* m = dynamic_cast<PixelMap<T> *>(o); | 
|---|
| 73 | if (m) return ( new NOMAdapter_PixelMap<T>(m) ); | 
|---|
| 74 | return ( new NObjMgrAdapter(o) ); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | /* --Methode-- */ | 
|---|
| 78 | template <class T> | 
|---|
| 79 | string NOMAdapter_PixelMap<T>::GetDataObjType() | 
|---|
| 80 | { | 
|---|
| 81 | string type = "PixelMap< "; | 
|---|
| 82 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); | 
|---|
| 83 | if (lm != NULL) type = "LocalMap< "; | 
|---|
| 84 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); | 
|---|
| 85 | if (st != NULL) type = "SphereThetaPhi< "; | 
|---|
| 86 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap); | 
|---|
| 87 | if (sg != NULL) type = "SphereHEALPix< "; | 
|---|
| 88 |  | 
|---|
| 89 | // type +=  DecodeTypeIdName(typeid(T).name()); | 
|---|
| 90 | type += DataType<T>::getTypeName(); | 
|---|
| 91 | type +=  " > "; | 
|---|
| 92 | return(type); | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | /* --Methode-- */ | 
|---|
| 96 | template <class T> | 
|---|
| 97 | AnyDataObj* NOMAdapter_PixelMap<T>::CloneDataObj() | 
|---|
| 98 | { | 
|---|
| 99 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); | 
|---|
| 100 | if (lm != NULL) return( new LocalMap<T>(*lm) ); | 
|---|
| 101 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); | 
|---|
| 102 | if (st != NULL) return( new SphereThetaPhi<T>(*st) ); | 
|---|
| 103 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap); | 
|---|
| 104 | if (sg != NULL) return( new SphereHEALPix<T>(*sg) ); | 
|---|
| 105 | return(NULL); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | /* --Methode-- */ | 
|---|
| 109 | template <class T> | 
|---|
| 110 | void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom) | 
|---|
| 111 | { | 
|---|
| 112 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); | 
|---|
| 113 | if (lm != NULL) { | 
|---|
| 114 | FIO_LocalMap<T> fio(lm); | 
|---|
| 115 | fio.Write(pos, nom); | 
|---|
| 116 | return; | 
|---|
| 117 | } | 
|---|
| 118 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); | 
|---|
| 119 | if (st != NULL) { | 
|---|
| 120 | FIO_SphereThetaPhi<T> fio(st); | 
|---|
| 121 | fio.Write(pos, nom); | 
|---|
| 122 | return; | 
|---|
| 123 | } | 
|---|
| 124 | SphereHEALPix<T>* sg = dynamic_cast< SphereHEALPix<T> * >(mMap); | 
|---|
| 125 | if (sg != NULL) { | 
|---|
| 126 | FIO_SphereHEALPix<T> fio(sg); | 
|---|
| 127 | fio.Write(pos, nom); | 
|---|
| 128 | return; | 
|---|
| 129 | } | 
|---|
| 130 | string s = typeid(*mMap).name(); | 
|---|
| 131 | cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl; | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | /* --Methode-- */ | 
|---|
| 135 | template <class T> | 
|---|
| 136 | void NOMAdapter_PixelMap<T>::Print(ostream& os) | 
|---|
| 137 | { | 
|---|
| 138 | string s = typeid(*mMap).name(); | 
|---|
| 139 | T moy, sig; | 
|---|
| 140 | MeanSig(moy, sig); | 
|---|
| 141 | cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl; | 
|---|
| 142 | cout << "  Mean= " << moy << "  Sig2= " << sig << endl; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 | /* --Methode-- */ | 
|---|
| 147 | template <class T> | 
|---|
| 148 | P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &) | 
|---|
| 149 | { | 
|---|
| 150 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); | 
|---|
| 151 | if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false)); | 
|---|
| 152 | int nr = 250; | 
|---|
| 153 | int nc = 500; | 
|---|
| 154 | SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap); | 
|---|
| 155 | if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels());  nc = 2*nr; } | 
|---|
| 156 | TMatrix<T> * mtx = new TMatrix<T>(nr, nc); | 
|---|
| 157 | Project_Mol(*mtx); | 
|---|
| 158 | return (new POTMatrixAdapter<T>(mtx, true) ); | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | /* --Methode-- */ | 
|---|
| 162 | template <class T> | 
|---|
| 163 | NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel) | 
|---|
| 164 | { | 
|---|
| 165 | adel = true; | 
|---|
| 166 | return( new NTupInt_PixelMap<T>(mMap) ); | 
|---|
| 167 | } | 
|---|
| 168 |  | 
|---|
| 169 | /* --Methode-- */ | 
|---|
| 170 | template <class T> | 
|---|
| 171 | void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig) | 
|---|
| 172 | { | 
|---|
| 173 | gmoy=0.; | 
|---|
| 174 | gsig = 0.; | 
|---|
| 175 | T valok; | 
|---|
| 176 | for(int k=0; k<mMap->NbPixels(); k++) { | 
|---|
| 177 | valok = (*mMap)(k); | 
|---|
| 178 | gmoy += valok;  gsig += valok*valok; | 
|---|
| 179 | } | 
|---|
| 180 | gmoy /= (T)mMap->NbPixels(); | 
|---|
| 181 | gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy; | 
|---|
| 182 |  | 
|---|
| 183 | } | 
|---|
| 184 |  | 
|---|
| 185 | /* --Methode-- */ | 
|---|
| 186 | template <class T> | 
|---|
| 187 | void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval) | 
|---|
| 188 | { | 
|---|
| 189 | r_8 xa, yd, teta,phi, facteur; | 
|---|
| 190 | int_4 l,c,k; | 
|---|
| 191 | int_4 nl = mtx.NRows(); | 
|---|
| 192 | int_4 nc = mtx.NCols(); | 
|---|
| 193 | mtx = defval;   // On met tout a defval | 
|---|
| 194 | //  cout << " NRows= " << nl << "  NCols= " << nc  << endl; | 
|---|
| 195 | for(l=0; l<nl; l++) { | 
|---|
| 196 | yd = (r_8)(l+0.5)/(r_8)nl-0.5; | 
|---|
| 197 | facteur=2.*M_PI/sin(acos((double)yd*2)); | 
|---|
| 198 | teta = (yd+0.5)*Pi; | 
|---|
| 199 | //    teta = (0.5-yd)*M_PI; | 
|---|
| 200 | for(c=0; c<nc; c++)  { | 
|---|
| 201 | xa = (r_8)(c+0.5)/(r_8)nc-0.5; | 
|---|
| 202 | phi = xa*facteur+M_PI; | 
|---|
| 203 | if ( (phi <= 2*M_PI) && (phi >= 0.) ) { | 
|---|
| 204 | k = mMap->PixIndexSph(teta, phi); | 
|---|
| 205 | mtx(l,c) = (*mMap)(k); | 
|---|
| 206 | } | 
|---|
| 207 | } | 
|---|
| 208 | } | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | // ------------------------------------------------------------- | 
|---|
| 212 |  | 
|---|
| 213 | /* --Methode-- */ | 
|---|
| 214 | template <class T> | 
|---|
| 215 | NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m) | 
|---|
| 216 | { | 
|---|
| 217 | mMap = m; | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | /* --Methode-- */ | 
|---|
| 221 | template <class T> | 
|---|
| 222 | NTupInt_PixelMap<T>::~NTupInt_PixelMap() | 
|---|
| 223 | { | 
|---|
| 224 | } | 
|---|
| 225 |  | 
|---|
| 226 | /* --Methode-- */ | 
|---|
| 227 | template <class T> | 
|---|
| 228 | uint_4 NTupInt_PixelMap<T>::NbLines() const | 
|---|
| 229 | { | 
|---|
| 230 | return( mMap->NbPixels() ); | 
|---|
| 231 | } | 
|---|
| 232 |  | 
|---|
| 233 | /* --Methode-- */ | 
|---|
| 234 | template <class T> | 
|---|
| 235 | uint_4 NTupInt_PixelMap<T>::NbColumns() const | 
|---|
| 236 | { | 
|---|
| 237 | return(8); | 
|---|
| 238 | } | 
|---|
| 239 |  | 
|---|
| 240 | /* --Methode-- */ | 
|---|
| 241 | template <class T> | 
|---|
| 242 | r_8* NTupInt_PixelMap<T>::GetLineD(int n) const | 
|---|
| 243 | { | 
|---|
| 244 | int i; | 
|---|
| 245 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) | 
|---|
| 246 | for(i=0; i<8; i++)  mRet[i] = 0.; | 
|---|
| 247 | else { | 
|---|
| 248 | double teta,phi; | 
|---|
| 249 | mMap->PixThetaPhi(n, teta, phi); | 
|---|
| 250 | mRet[0] = n;  mRet[1] = mMap->PixVal(n); | 
|---|
| 251 | mRet[2] = mRet[1];  mRet[3] = 0.; | 
|---|
| 252 | mRet[4] = mRet[1];  mRet[5] = 0.; | 
|---|
| 253 | mRet[6] = teta;     mRet[7] = phi; | 
|---|
| 254 | } | 
|---|
| 255 | return(mRet); | 
|---|
| 256 | } | 
|---|
| 257 |  | 
|---|
| 258 | /* --Methode-- */ | 
|---|
| 259 | template <class T> | 
|---|
| 260 | string NTupInt_PixelMap<T>::VarList_C(const char* nx) const | 
|---|
| 261 | { | 
|---|
| 262 | string nomx; | 
|---|
| 263 | if (nx) nomx = nx; | 
|---|
| 264 | else nomx = "_xh_"; | 
|---|
| 265 | string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n"; | 
|---|
| 266 | vardec += "i = " + nomx + "[0]; k = " + nomx + "[0];  val = " + nomx + "[1]; \n"; | 
|---|
| 267 | vardec += "real = " + nomx + "[2];  imag = " + nomx + "[3]; \n"; | 
|---|
| 268 | vardec += "mod  = " + nomx + "[4];  phas = " + nomx + "[5]; \n"; | 
|---|
| 269 | vardec += "teta = " + nomx + "[6];  phi  = " + nomx + "[7]; \n"; | 
|---|
| 270 | return(vardec); | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const | 
|---|
| 274 | { | 
|---|
| 275 | int i; | 
|---|
| 276 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) | 
|---|
| 277 | for(i=0; i<8; i++)  mRet[i] = 0.; | 
|---|
| 278 | else { | 
|---|
| 279 | double teta,phi; | 
|---|
| 280 | mMap->PixThetaPhi(n, teta, phi); | 
|---|
| 281 | mRet[0] = n; | 
|---|
| 282 | mRet[2] = mMap->PixVal(n).real();  mRet[3] = mMap->PixVal(n).imag(); | 
|---|
| 283 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]); | 
|---|
| 284 | mRet[5] = atan2(mRet[3], mRet[2]); | 
|---|
| 285 | mRet[6] = teta;     mRet[7] = phi; | 
|---|
| 286 | } | 
|---|
| 287 | return(mRet); | 
|---|
| 288 | } | 
|---|
| 289 |  | 
|---|
| 290 | r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const | 
|---|
| 291 | { | 
|---|
| 292 | int i; | 
|---|
| 293 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) | 
|---|
| 294 | for(i=0; i<8; i++)  mRet[i] = 0.; | 
|---|
| 295 | else { | 
|---|
| 296 | double teta,phi; | 
|---|
| 297 | mMap->PixThetaPhi(n, teta, phi); | 
|---|
| 298 | mRet[0] = n; | 
|---|
| 299 | mRet[2] = mMap->PixVal(n).real();  mRet[3] = mMap->PixVal(n).imag(); | 
|---|
| 300 | mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]); | 
|---|
| 301 | mRet[5] = atan2(mRet[3], mRet[2]); | 
|---|
| 302 | mRet[6] = teta;     mRet[7] = phi; | 
|---|
| 303 | } | 
|---|
| 304 | return(mRet); | 
|---|
| 305 | } | 
|---|
| 306 |  | 
|---|
| 307 |  | 
|---|
| 308 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| 309 | #pragma define_template NOMAdapter_PixelMap<r_4> | 
|---|
| 310 | #pragma define_template NOMAdapter_PixelMap<r_8> | 
|---|
| 311 | #pragma define_template NOMAdapter_PixelMap< complex<float> > | 
|---|
| 312 | #pragma define_template NOMAdapter_PixelMap< complex<double> > | 
|---|
| 313 | #pragma define_template NTupInt_PixelMap<r_4> | 
|---|
| 314 | #pragma define_template NTupInt_PixelMap<r_8> | 
|---|
| 315 | #pragma define_template NTupInt_PixelMap< complex<float> > | 
|---|
| 316 | #pragma define_template NTupInt_PixelMap< complex<double> > | 
|---|
| 317 | #endif | 
|---|
| 318 |  | 
|---|
| 319 | #if defined(ANSI_TEMPLATES) | 
|---|
| 320 | template class NOMAdapter_PixelMap<r_4>; | 
|---|
| 321 | template class NOMAdapter_PixelMap<r_8>; | 
|---|
| 322 | template class NOMAdapter_PixelMap< complex<float> >; | 
|---|
| 323 | template class NOMAdapter_PixelMap< complex<double> >; | 
|---|
| 324 | template class NTupInt_PixelMap<r_4>; | 
|---|
| 325 | template class NTupInt_PixelMap<r_8>; | 
|---|
| 326 | template class NTupInt_PixelMap< complex<float> >; | 
|---|
| 327 | template class NTupInt_PixelMap< complex<double> >; | 
|---|
| 328 | #endif | 
|---|