| 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 "nomskymapadapter.h"
 | 
|---|
| 10 | #include "spherethetaphi.h"
 | 
|---|
| 11 | #include "spheregorski.h"
 | 
|---|
| 12 | #include "localmap.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->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 | 
 | 
|---|
| 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 | AnyDataObj* NOMAdapter_PixelMap<T>::GetCopyObj()
 | 
|---|
| 80 | {
 | 
|---|
| 81 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); 
 | 
|---|
| 82 | if (lm != NULL) return( new LocalMap<T>(*lm) );
 | 
|---|
| 83 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); 
 | 
|---|
| 84 | if (st != NULL) return( new SphereThetaPhi<T>(*st) );
 | 
|---|
| 85 | SphereGorski<T>* sg = dynamic_cast< SphereGorski<T> * >(mMap); 
 | 
|---|
| 86 | if (sg != NULL) return( new SphereGorski<T>(*sg) );
 | 
|---|
| 87 | return(NULL);
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | /* --Methode-- */
 | 
|---|
| 91 | template <class T> 
 | 
|---|
| 92 | void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
 | 
|---|
| 93 | {
 | 
|---|
| 94 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); 
 | 
|---|
| 95 | if (lm != NULL) {
 | 
|---|
| 96 |   FIO_LocalMap<T> fio(lm);
 | 
|---|
| 97 |   fio.Write(pos, nom);
 | 
|---|
| 98 |   return;
 | 
|---|
| 99 |   }
 | 
|---|
| 100 | SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap); 
 | 
|---|
| 101 | if (st != NULL) {
 | 
|---|
| 102 |   FIO_SphereThetaPhi<T> fio(st);
 | 
|---|
| 103 |   fio.Write(pos, nom);
 | 
|---|
| 104 |   return;
 | 
|---|
| 105 |   }
 | 
|---|
| 106 | SphereGorski<T>* sg = dynamic_cast< SphereGorski<T> * >(mMap); 
 | 
|---|
| 107 | if (sg != NULL) {
 | 
|---|
| 108 |   FIO_SphereGorski<T> fio(sg);
 | 
|---|
| 109 |   fio.Write(pos, nom);
 | 
|---|
| 110 |   return;
 | 
|---|
| 111 |   }
 | 
|---|
| 112 | string s = typeid(*mMap).name();
 | 
|---|
| 113 | cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
 | 
|---|
| 114 | }
 | 
|---|
| 115 | 
 | 
|---|
| 116 | /* --Methode-- */
 | 
|---|
| 117 | template <class T> 
 | 
|---|
| 118 | void NOMAdapter_PixelMap<T>::Print(ostream& os)
 | 
|---|
| 119 | {
 | 
|---|
| 120 | string s = typeid(*mMap).name();
 | 
|---|
| 121 | T moy, sig;
 | 
|---|
| 122 | MeanSig(moy, sig);
 | 
|---|
| 123 | cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
 | 
|---|
| 124 | cout << "  Mean= " << moy << "  Sig2= " << sig << endl;
 | 
|---|
| 125 | }
 | 
|---|
| 126 | 
 | 
|---|
| 127 | 
 | 
|---|
| 128 | /* --Methode-- */
 | 
|---|
| 129 | template <class T> 
 | 
|---|
| 130 | P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
 | 
|---|
| 131 | {
 | 
|---|
| 132 | LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap); 
 | 
|---|
| 133 | if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
 | 
|---|
| 134 | int nr = 250;
 | 
|---|
| 135 | int nc = 500;
 | 
|---|
| 136 | SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
 | 
|---|
| 137 | if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels());  nc = 2*nr; }
 | 
|---|
| 138 | TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
 | 
|---|
| 139 | Project_Mol(*mtx);
 | 
|---|
| 140 | return (new POTMatrixAdapter<T>(mtx, true) );
 | 
|---|
| 141 | }
 | 
|---|
| 142 | 
 | 
|---|
| 143 | /* --Methode-- */
 | 
|---|
| 144 | template <class T> 
 | 
|---|
| 145 | NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
 | 
|---|
| 146 | {
 | 
|---|
| 147 | adel = true;
 | 
|---|
| 148 | return( new NTupInt_PixelMap<T>(mMap) );
 | 
|---|
| 149 | }
 | 
|---|
| 150 | 
 | 
|---|
| 151 | /* --Methode-- */
 | 
|---|
| 152 | template <class T> 
 | 
|---|
| 153 | void 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-- */
 | 
|---|
| 168 | template <class T> 
 | 
|---|
| 169 | void 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 | }
 | 
|---|
| 192 | 
 | 
|---|
| 193 | // -------------------------------------------------------------
 | 
|---|
| 194 | 
 | 
|---|
| 195 | /* --Methode-- */
 | 
|---|
| 196 | template <class T> 
 | 
|---|
| 197 | NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
 | 
|---|
| 198 | {
 | 
|---|
| 199 | mMap = m;
 | 
|---|
| 200 | }
 | 
|---|
| 201 | 
 | 
|---|
| 202 | /* --Methode-- */
 | 
|---|
| 203 | template <class T> 
 | 
|---|
| 204 | NTupInt_PixelMap<T>::~NTupInt_PixelMap()
 | 
|---|
| 205 | {
 | 
|---|
| 206 | }
 | 
|---|
| 207 | 
 | 
|---|
| 208 | /* --Methode-- */
 | 
|---|
| 209 | template <class T> 
 | 
|---|
| 210 | uint_4 NTupInt_PixelMap<T>::NbLines() const
 | 
|---|
| 211 | {
 | 
|---|
| 212 | return( mMap->NbPixels() );
 | 
|---|
| 213 | }
 | 
|---|
| 214 | 
 | 
|---|
| 215 | /* --Methode-- */
 | 
|---|
| 216 | template <class T> 
 | 
|---|
| 217 | uint_4 NTupInt_PixelMap<T>::NbColumns() const 
 | 
|---|
| 218 | {
 | 
|---|
| 219 | return(8);
 | 
|---|
| 220 | }
 | 
|---|
| 221 | 
 | 
|---|
| 222 | /* --Methode-- */
 | 
|---|
| 223 | template <class T> 
 | 
|---|
| 224 | r_8* NTupInt_PixelMap<T>::GetLineD(int n) const 
 | 
|---|
| 225 | {
 | 
|---|
| 226 | int i;
 | 
|---|
| 227 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) 
 | 
|---|
| 228 |     for(i=0; i<8; i++)  mRet[i] = 0.;
 | 
|---|
| 229 | else { 
 | 
|---|
| 230 |   double teta,phi;
 | 
|---|
| 231 |   mMap->PixThetaPhi(n, teta, phi);
 | 
|---|
| 232 |   mRet[0] = n;  mRet[1] = mMap->PixVal(n);
 | 
|---|
| 233 |   mRet[2] = mRet[1];  mRet[3] = 0.;
 | 
|---|
| 234 |   mRet[4] = mRet[1];  mRet[5] = 0.;
 | 
|---|
| 235 |   mRet[6] = teta;     mRet[7] = phi;
 | 
|---|
| 236 |   }
 | 
|---|
| 237 | return(mRet);
 | 
|---|
| 238 | }
 | 
|---|
| 239 | 
 | 
|---|
| 240 | /* --Methode-- */
 | 
|---|
| 241 | template <class T> 
 | 
|---|
| 242 | string NTupInt_PixelMap<T>::VarList_C(const char* nx) const 
 | 
|---|
| 243 | {
 | 
|---|
| 244 | string nomx;
 | 
|---|
| 245 | if (nx) nomx = nx;
 | 
|---|
| 246 | else nomx = "_xh_";
 | 
|---|
| 247 | string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
 | 
|---|
| 248 | vardec += "i = " + nomx + "[0]; k = " + nomx + "[0];  val = " + nomx + "[1]; \n";
 | 
|---|
| 249 | vardec += "real = " + nomx + "[2];  imag = " + nomx + "[3]; \n";
 | 
|---|
| 250 | vardec += "mod  = " + nomx + "[4];  phas = " + nomx + "[5]; \n";
 | 
|---|
| 251 | vardec += "teta = " + nomx + "[6];  phi  = " + nomx + "[7]; \n";
 | 
|---|
| 252 | return(vardec);
 | 
|---|
| 253 | }
 | 
|---|
| 254 | 
 | 
|---|
| 255 | r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const 
 | 
|---|
| 256 | {
 | 
|---|
| 257 | int i;
 | 
|---|
| 258 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) 
 | 
|---|
| 259 |     for(i=0; i<8; i++)  mRet[i] = 0.;
 | 
|---|
| 260 | else { 
 | 
|---|
| 261 |   double teta,phi;
 | 
|---|
| 262 |   mMap->PixThetaPhi(n, teta, phi);
 | 
|---|
| 263 |   mRet[0] = n;  
 | 
|---|
| 264 |   mRet[2] = mMap->PixVal(n).real();  mRet[3] = mMap->PixVal(n).imag();
 | 
|---|
| 265 |   mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
 | 
|---|
| 266 |   mRet[5] = atan2(mRet[3], mRet[2]);
 | 
|---|
| 267 |   mRet[6] = teta;     mRet[7] = phi;
 | 
|---|
| 268 |   }
 | 
|---|
| 269 | return(mRet);
 | 
|---|
| 270 | }
 | 
|---|
| 271 | 
 | 
|---|
| 272 | r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const 
 | 
|---|
| 273 | {
 | 
|---|
| 274 | int i;
 | 
|---|
| 275 | if ((n < 0) || (n >= (int)(mMap->NbPixels()) )) 
 | 
|---|
| 276 |     for(i=0; i<8; i++)  mRet[i] = 0.;
 | 
|---|
| 277 | else { 
 | 
|---|
| 278 |   double teta,phi;
 | 
|---|
| 279 |   mMap->PixThetaPhi(n, teta, phi);
 | 
|---|
| 280 |   mRet[0] = n;  
 | 
|---|
| 281 |   mRet[2] = mMap->PixVal(n).real();  mRet[3] = mMap->PixVal(n).imag();
 | 
|---|
| 282 |   mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
 | 
|---|
| 283 |   mRet[5] = atan2(mRet[3], mRet[2]);
 | 
|---|
| 284 |   mRet[6] = teta;     mRet[7] = phi;
 | 
|---|
| 285 |   }
 | 
|---|
| 286 | return(mRet);
 | 
|---|
| 287 | }
 | 
|---|
| 288 | 
 | 
|---|
| 289 | 
 | 
|---|
| 290 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 291 | #pragma define_template NOMAdapter_PixelMap<r_4>
 | 
|---|
| 292 | #pragma define_template NOMAdapter_PixelMap<r_8>
 | 
|---|
| 293 | #pragma define_template NOMAdapter_PixelMap< complex<float> >
 | 
|---|
| 294 | #pragma define_template NOMAdapter_PixelMap< complex<double> >
 | 
|---|
| 295 | #pragma define_template NTupInt_PixelMap<r_4>
 | 
|---|
| 296 | #pragma define_template NTupInt_PixelMap<r_8>
 | 
|---|
| 297 | #pragma define_template NTupInt_PixelMap< complex<float> >
 | 
|---|
| 298 | #pragma define_template NTupInt_PixelMap< complex<double> >
 | 
|---|
| 299 | #endif
 | 
|---|
| 300 | 
 | 
|---|
| 301 | #if defined(ANSI_TEMPLATES) 
 | 
|---|
| 302 | template class NOMAdapter_PixelMap<r_4>;
 | 
|---|
| 303 | template class NOMAdapter_PixelMap<r_8>;
 | 
|---|
| 304 | template class NOMAdapter_PixelMap< complex<float> >;
 | 
|---|
| 305 | template class NOMAdapter_PixelMap< complex<double> >;
 | 
|---|
| 306 | template class NTupInt_PixelMap<r_4>;
 | 
|---|
| 307 | template class NTupInt_PixelMap<r_8>;
 | 
|---|
| 308 | template class NTupInt_PixelMap< complex<float> >;
 | 
|---|
| 309 | template class NTupInt_PixelMap< complex<double> >;
 | 
|---|
| 310 | #endif
 | 
|---|