[228] | 1 | #include "spherethetaphi.h"
|
---|
| 2 | #include "nbmath.h"
|
---|
[470] | 3 | #include <complex>
|
---|
| 4 | #include "piocmplx.h"
|
---|
[228] | 5 | #include <iostream.h>
|
---|
[470] | 6 |
|
---|
| 7 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 8 | #pragma define_template SphereThetaPhi<double>
|
---|
| 9 | #pragma define_template SphereThetaPhi<float>
|
---|
| 10 | #pragma define_template SphereThetaPhi< complex<float> >
|
---|
| 11 | #pragma define_template SphereThetaPhi< complex<double> >
|
---|
| 12 | #pragma define_template FIO_SphereThetaPhi<double>
|
---|
| 13 | #pragma define_template FIO_SphereThetaPhi<float>
|
---|
| 14 | #pragma define_template FIO_SphereThetaPhi< complex<float> >
|
---|
| 15 | #pragma define_template FIO_SphereThetaPhi< complex<double> >
|
---|
| 16 | #endif
|
---|
| 17 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 18 | template class SphereThetaPhi<double>;
|
---|
| 19 | template class SphereThetaPhi<float>;
|
---|
| 20 | template class SphereThetaPhi< complex<float> >;
|
---|
| 21 | template class SphereThetaPhi< complex<double> >;
|
---|
| 22 | template class FIO_SphereThetaPhi<double>;
|
---|
| 23 | template class FIO_SphereThetaPhi<float>;
|
---|
| 24 | template class FIO_SphereThetaPhi< complex<float> >;
|
---|
| 25 | template class FIO_SphereThetaPhi< complex<double> >;
|
---|
| 26 | #endif
|
---|
| 27 |
|
---|
[228] | 28 | //***************************************************************
|
---|
| 29 | //++
|
---|
| 30 | // Class SphereThetaPhi
|
---|
| 31 | //
|
---|
| 32 | //
|
---|
| 33 | // include spherethetaphi.h nbmath.h
|
---|
| 34 | //
|
---|
| 35 | // Découpage de la sphère selon theta et phi, chaque
|
---|
| 36 | // hémisphère étant découpé en (m-1) parallèles (l'équateur compte pour du
|
---|
| 37 | // beurre), chacune des m bandes de theta ainsi définies étant découpée par
|
---|
| 38 | // des méridiens équirepartis, ce découpage étant fait de sorte que tous
|
---|
| 39 | // les pixels aient la même surface et soient le plus carré possible.
|
---|
| 40 | // On commence par découper l'hémisphère de z positif en partant du pôle et
|
---|
| 41 | // en allant vers l'équateur. Le premier pixel est la calotte polaire,
|
---|
| 42 | // il est circulaire et centré sur theta=0.
|
---|
| 43 | //--
|
---|
| 44 | //++
|
---|
| 45 | //
|
---|
| 46 | // Links Parents
|
---|
| 47 | //
|
---|
| 48 | // SphericalMap
|
---|
| 49 | //--
|
---|
| 50 | //++
|
---|
| 51 | //
|
---|
| 52 | // Links Descendants
|
---|
| 53 | //
|
---|
| 54 | //
|
---|
| 55 | //--
|
---|
| 56 |
|
---|
| 57 | /* --Methode-- */
|
---|
| 58 | //++
|
---|
| 59 | // Titre Constructeurs
|
---|
| 60 | //--
|
---|
| 61 | //++
|
---|
| 62 |
|
---|
[470] | 63 | template <class T>
|
---|
| 64 | SphereThetaPhi<T>::SphereThetaPhi()
|
---|
[228] | 65 |
|
---|
| 66 | //--
|
---|
| 67 | {
|
---|
| 68 | InitNul();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | /* --Methode-- */
|
---|
| 73 |
|
---|
| 74 | //++
|
---|
[470] | 75 | template <class T>
|
---|
[473] | 76 | SphereThetaPhi<T>::SphereThetaPhi(int m)
|
---|
[228] | 77 |
|
---|
| 78 | // Constructeur : m est le nombre de bandes en theta sur un hémisphère
|
---|
| 79 | // (la calotte constituant la premiere bande).
|
---|
| 80 | // pet est le nombre de pixels (pétales) de la bande en contact avec la
|
---|
| 81 | // calotte polaire. Pour l'instant pet est inopérant!
|
---|
| 82 | //--
|
---|
| 83 | {
|
---|
| 84 | InitNul();
|
---|
[470] | 85 | Pixelize(m);
|
---|
[228] | 86 | }
|
---|
| 87 |
|
---|
[470] | 88 | template <class T>
|
---|
| 89 | SphereThetaPhi<T>::SphereThetaPhi(const SphereThetaPhi<T>& s)
|
---|
| 90 | {
|
---|
| 91 | if(s.mInfo_) mInfo_= new DVList(*s.mInfo_);
|
---|
| 92 | NTheta_= s.NTheta_;
|
---|
| 93 | NPix_ = s.NPix_;
|
---|
[473] | 94 | NPhi_ = new int[NTheta_];
|
---|
| 95 | Theta_ = new double[NTheta_+1];
|
---|
| 96 | TNphi_ = new int[NTheta_+1];
|
---|
[470] | 97 | for(int k = 0; k < NTheta_; k++)
|
---|
| 98 | {
|
---|
| 99 | NPhi_[k] = s.NPhi_[k];
|
---|
| 100 | Theta_[k]= s.Theta_[k];
|
---|
| 101 | TNphi_[k]= s.TNphi_[k];
|
---|
| 102 | }
|
---|
| 103 | Theta_[NTheta_]= s.Theta_[NTheta_];
|
---|
| 104 | TNphi_[NTheta_]= s.TNphi_[NTheta_];
|
---|
| 105 | Omega_ = s.Omega_;
|
---|
| 106 | pixels_= s.pixels_;
|
---|
| 107 | }
|
---|
[228] | 108 |
|
---|
| 109 | //++
|
---|
| 110 | // Titre Destructeur
|
---|
| 111 | //--
|
---|
| 112 | //++
|
---|
[470] | 113 | template <class T>
|
---|
| 114 | SphereThetaPhi<T>::~SphereThetaPhi()
|
---|
[228] | 115 |
|
---|
| 116 | //--
|
---|
| 117 | {
|
---|
| 118 | Clear();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | //++
|
---|
| 122 | // Titre Méthodes
|
---|
| 123 | //--
|
---|
[470] | 124 | template <class T>
|
---|
| 125 | void SphereThetaPhi<T>::InitNul()
|
---|
[228] | 126 | //
|
---|
| 127 | // initialise à zéro les variables de classe pointeurs
|
---|
| 128 | {
|
---|
[470] | 129 | NTheta_= 0;
|
---|
| 130 | NPix_ = 0;
|
---|
| 131 | Theta_ = NULL;
|
---|
| 132 | NPhi_ = NULL;
|
---|
| 133 | TNphi_ = NULL;
|
---|
| 134 | pixels_.Reset();
|
---|
[228] | 135 | }
|
---|
| 136 |
|
---|
| 137 | /* --Methode-- */
|
---|
[470] | 138 | template <class T>
|
---|
| 139 | void SphereThetaPhi<T>::Clear()
|
---|
[228] | 140 |
|
---|
| 141 | {
|
---|
[470] | 142 | if(Theta_) delete[] Theta_;
|
---|
| 143 | if(NPhi_ ) delete[] NPhi_;
|
---|
| 144 | if(TNphi_) delete[] TNphi_;
|
---|
| 145 | InitNul();
|
---|
[228] | 146 | }
|
---|
| 147 |
|
---|
| 148 | //++
|
---|
[470] | 149 | template <class T>
|
---|
[473] | 150 | void SphereThetaPhi<T>::Resize(int m)
|
---|
[470] | 151 | // re-pixelize the sphere
|
---|
[228] | 152 | //--
|
---|
| 153 | {
|
---|
| 154 | Clear();
|
---|
[470] | 155 | Pixelize(m);
|
---|
[228] | 156 | }
|
---|
| 157 |
|
---|
| 158 | /* --Methode-- */
|
---|
| 159 | //++
|
---|
[470] | 160 | template <class T>
|
---|
[473] | 161 | int SphereThetaPhi<T>::NbPixels() const
|
---|
[228] | 162 |
|
---|
| 163 | // Retourne le nombre de pixels du découpage
|
---|
| 164 | //--
|
---|
| 165 | {
|
---|
[470] | 166 | return(NPix_);
|
---|
[228] | 167 | }
|
---|
| 168 |
|
---|
| 169 | /* --Methode-- */
|
---|
| 170 | //++
|
---|
[470] | 171 | template <class T>
|
---|
[473] | 172 | T& SphereThetaPhi<T>::PixVal(int k)
|
---|
[228] | 173 |
|
---|
| 174 | // Retourne la valeur du contenu du pixel d'indice k
|
---|
| 175 | //--
|
---|
| 176 | {
|
---|
[470] | 177 | if((k < 0) || (k >= NPix_))
|
---|
| 178 | {
|
---|
[473] | 179 | //THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range"));
|
---|
| 180 | cout << " SphereThetaPhi::PIxVal : exceptions a mettre en place" <<endl;
|
---|
[470] | 181 | THROW(rangeCheckErr);
|
---|
| 182 | }
|
---|
| 183 | return pixels_(k);
|
---|
| 184 | }
|
---|
[228] | 185 |
|
---|
| 186 | //++
|
---|
[470] | 187 | template <class T>
|
---|
[473] | 188 | T const& SphereThetaPhi<T>::PixVal(int k) const
|
---|
[228] | 189 |
|
---|
| 190 | // Retourne la valeur du contenu du pixel d'indice k
|
---|
| 191 | //--
|
---|
| 192 | {
|
---|
[470] | 193 | if((k < 0) || (k >= NPix_))
|
---|
| 194 | {
|
---|
| 195 | cout << " SphereThetaPhi::PIxVal : exceptions a mettre en place" <<endl;
|
---|
[473] | 196 | //THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range"));
|
---|
[470] | 197 | throw "SphereThetaPhi::PIxVal Pixel index out of range";
|
---|
| 198 | }
|
---|
| 199 | return *(pixels_.Data()+k);
|
---|
[228] | 200 | }
|
---|
| 201 |
|
---|
| 202 | /* --Methode-- */
|
---|
| 203 | //++
|
---|
[470] | 204 | template <class T>
|
---|
[473] | 205 | int SphereThetaPhi<T>::PixIndexSph(double theta, double phi) const
|
---|
[228] | 206 |
|
---|
[473] | 207 | // Retourne l'indice du pixel vers lequel pointe une direction définie par
|
---|
[228] | 208 | // ses coordonnées sphériques
|
---|
| 209 | //--
|
---|
| 210 | {
|
---|
[473] | 211 | double dphi;
|
---|
| 212 | int i,j,k;
|
---|
[228] | 213 | bool fgzn = false;
|
---|
| 214 |
|
---|
[473] | 215 | if((theta > Pi) || (theta < 0.)) return(-1);
|
---|
| 216 | if((phi < 0.) || (phi > DeuxPi)) return(-1);
|
---|
| 217 | if(theta > Pi*0.5) {fgzn = true; theta = Pi-theta;}
|
---|
[228] | 218 |
|
---|
| 219 | // La bande d'indice kt est limitée par les valeurs de theta contenues dans
|
---|
[470] | 220 | // Theta_[kt] et Theta_[kt+1]
|
---|
| 221 | for( i=1; i< NTheta_; i++ )
|
---|
| 222 | if( theta < Theta_[i] ) break;
|
---|
[228] | 223 |
|
---|
[473] | 224 | dphi= DeuxPi/(double)NPhi_[i-1];
|
---|
[228] | 225 |
|
---|
[473] | 226 | if (fgzn) k= NPix_-TNphi_[i]+(int)(phi/dphi);
|
---|
| 227 | else k= TNphi_[i-1]+(int)(phi/dphi);
|
---|
[228] | 228 | return(k);
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | /* --Methode-- */
|
---|
| 232 | //++
|
---|
[470] | 233 | template <class T>
|
---|
[473] | 234 | void SphereThetaPhi<T>::PixThetaPhi(int k,double& theta,double& phi) const
|
---|
[228] | 235 |
|
---|
| 236 | // Retourne les coordonnées (theta,phi) du milieu du pixel d'indice k
|
---|
| 237 | //--
|
---|
| 238 | {
|
---|
[473] | 239 | int i;
|
---|
[228] | 240 | bool fgzn = false;
|
---|
| 241 |
|
---|
[473] | 242 | if((k < 0) || (k >= NPix_)) {theta = -99999.; phi = -99999.; return; }
|
---|
| 243 | if( k >= NPix_/2) {fgzn = true; k = NPix_-1-k;}
|
---|
[228] | 244 |
|
---|
| 245 | // recupère l'indice i de la tranche qui contient le pixel k
|
---|
[470] | 246 | for( i=0; i< NTheta_; i++ )
|
---|
| 247 | if( k < TNphi_[i+1] ) break;
|
---|
[228] | 248 |
|
---|
| 249 | // angle theta
|
---|
[470] | 250 | theta= 0.5*(Theta_[i]+Theta_[i+1]);
|
---|
[228] | 251 | if (fgzn) theta= Pi-theta;
|
---|
| 252 |
|
---|
| 253 | // angle phi
|
---|
[470] | 254 | k -= TNphi_[i];
|
---|
[473] | 255 | phi= DeuxPi/(double)NPhi_[i]*(double)(k+.5);
|
---|
[228] | 256 | if (fgzn) phi= DeuxPi-phi;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[470] | 259 | //++
|
---|
| 260 | template <class T>
|
---|
[473] | 261 | double SphereThetaPhi<T>::PixSolAngle(int dummy) const
|
---|
[228] | 262 |
|
---|
| 263 | // Pixel Solid angle (steradians)
|
---|
| 264 | // All the pixels have the same solid angle. The dummy argument is
|
---|
| 265 | // for compatibility with eventual pixelizations which would not
|
---|
| 266 | // fulfil this requirement.
|
---|
| 267 | //--
|
---|
| 268 | {
|
---|
[470] | 269 | return Omega_;
|
---|
[228] | 270 | }
|
---|
| 271 |
|
---|
| 272 | /* --Methode-- */
|
---|
| 273 | //++
|
---|
[470] | 274 | template <class T>
|
---|
[473] | 275 | void SphereThetaPhi<T>::Limits(int k,double& tetMin,double& tetMax,double& phiMin,double& phiMax)
|
---|
[228] | 276 |
|
---|
| 277 | // Retourne les valeurs de theta et phi limitant le pixel d'indice k
|
---|
| 278 | //--
|
---|
| 279 | {
|
---|
[473] | 280 | int j;
|
---|
| 281 | double dphi;
|
---|
[228] | 282 | bool fgzn= false;
|
---|
| 283 |
|
---|
[473] | 284 | if((k < 0) || (k >= NPix_)) {
|
---|
[228] | 285 | tetMin= -99999.;
|
---|
| 286 | phiMin= -99999.;
|
---|
| 287 | tetMax= -99999.;
|
---|
| 288 | phiMax= -99999.;
|
---|
| 289 | return;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | // si on se trouve dans l'hémisphère Sud
|
---|
[473] | 293 | if(k >= NPix_/2) {
|
---|
[228] | 294 | fgzn= true;
|
---|
[470] | 295 | k= NPix_-1-k;
|
---|
[228] | 296 | }
|
---|
| 297 |
|
---|
| 298 | // on recupere l'indice i de la tranche qui contient le pixel k
|
---|
| 299 | int i;
|
---|
[470] | 300 | for( i=0; i< NTheta_; i++ )
|
---|
[473] | 301 | if(k < TNphi_[i+1]) break;
|
---|
[228] | 302 |
|
---|
| 303 | // valeurs limites de theta dans l'hemisphere Nord
|
---|
[470] | 304 | tetMin= Theta_[i];
|
---|
| 305 | tetMax= Theta_[i+1];
|
---|
[228] | 306 | // valeurs limites de theta dans l'hemisphere Sud
|
---|
| 307 | if (fgzn) {
|
---|
[470] | 308 | tetMin= Pi-Theta_[i+1];
|
---|
| 309 | tetMax= Pi-Theta_[i];
|
---|
[228] | 310 | }
|
---|
| 311 |
|
---|
| 312 | // pixel correspondant dans l'hemisphere Nord
|
---|
[470] | 313 | if (fgzn) k= TNphi_[i+1]-k+TNphi_[i]-1;
|
---|
[228] | 314 |
|
---|
| 315 | // indice j de discretisation ( phi= j*dphi )
|
---|
[470] | 316 | j= k-TNphi_[i];
|
---|
[473] | 317 | dphi= DeuxPi/(double)NPhi_[i];
|
---|
[228] | 318 |
|
---|
| 319 | // valeurs limites de phi
|
---|
[473] | 320 | phiMin= dphi*(double)(j);
|
---|
| 321 | phiMax= dphi*(double)(j+1);
|
---|
[228] | 322 | return;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | /* --Methode-- */
|
---|
| 326 | //++
|
---|
[470] | 327 | template <class T>
|
---|
[473] | 328 | int SphereThetaPhi<T>::NbThetaSlices() const
|
---|
[228] | 329 |
|
---|
| 330 | // Retourne le nombre de tranches en theta sur la sphere
|
---|
| 331 | //--
|
---|
| 332 | {
|
---|
[473] | 333 | int nbslices;
|
---|
[470] | 334 | nbslices= 2*NTheta_;
|
---|
[228] | 335 | return(nbslices);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | /* --Methode-- */
|
---|
| 339 | //++
|
---|
[470] | 340 | template <class T>
|
---|
[473] | 341 | int SphereThetaPhi<T>::NPhi(int kt) const
|
---|
[228] | 342 |
|
---|
| 343 | // Retourne le nombre de pixels en phi de la tranche kt
|
---|
| 344 | //--
|
---|
| 345 | {
|
---|
[473] | 346 | int nbpix;
|
---|
[228] | 347 | // verification
|
---|
[473] | 348 | if((kt < 0) || (kt >= 2*NTheta_)) return(-1);
|
---|
[228] | 349 |
|
---|
| 350 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 351 | if(kt >= NTheta_) {
|
---|
[470] | 352 | kt= 2*NTheta_-1-kt;
|
---|
[228] | 353 | }
|
---|
| 354 |
|
---|
| 355 | // nombre de pixels
|
---|
[470] | 356 | nbpix= NPhi_[kt];
|
---|
[228] | 357 | return(nbpix);
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 |
|
---|
| 361 | /* --Methode-- */
|
---|
| 362 | //++
|
---|
[470] | 363 | template <class T>
|
---|
[473] | 364 | void SphereThetaPhi<T>::Theta(int kt,double& tetMin,double& tetMax)
|
---|
[228] | 365 |
|
---|
| 366 | // Retourne les valeurs de theta limitant la tranche kt
|
---|
| 367 | //--
|
---|
| 368 | {
|
---|
| 369 | bool fgzn= false;
|
---|
| 370 | // verification
|
---|
[470] | 371 | if( (kt< 0) || (kt>= 2*NTheta_) ) {
|
---|
[228] | 372 | tetMin= -99999.;
|
---|
| 373 | tetMax= -99999.;
|
---|
| 374 | return;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | // si on se trouve dans l'hemisphere Sud
|
---|
[470] | 378 | if( kt >= NTheta_ ) {
|
---|
[228] | 379 | fgzn= true;
|
---|
[470] | 380 | kt= 2*NTheta_-1-kt;
|
---|
[228] | 381 | }
|
---|
| 382 |
|
---|
| 383 | // valeurs limites de theta dans l'hemisphere Nord
|
---|
[470] | 384 | tetMin= Theta_[kt];
|
---|
| 385 | tetMax= Theta_[kt+1];
|
---|
[228] | 386 | // valeurs limites de theta dans l'hemisphere Sud
|
---|
| 387 | if (fgzn) {
|
---|
[470] | 388 | tetMin= Pi-Theta_[kt+1];
|
---|
| 389 | tetMax= Pi-Theta_[kt];
|
---|
[228] | 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | /* --Methode-- */
|
---|
| 394 | //++
|
---|
[470] | 395 | template <class T>
|
---|
[473] | 396 | void SphereThetaPhi<T>::Phi(int kt,int jp,double& phiMin,double& phiMax)
|
---|
[228] | 397 |
|
---|
| 398 | // Retourne les valeurs de phi limitant le pixel jp de la tranche kt
|
---|
| 399 | //--
|
---|
| 400 | {
|
---|
| 401 | // verification
|
---|
[473] | 402 | if((kt < 0) || (kt >= 2*NTheta_)) {
|
---|
[228] | 403 | phiMin= -99999.;
|
---|
| 404 | phiMax= -99999.;
|
---|
| 405 | return;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 409 | if(kt >= NTheta_) kt= 2*NTheta_-1-kt;
|
---|
[228] | 410 |
|
---|
| 411 | // verifie si la tranche kt contient au moins jp pixels
|
---|
[470] | 412 | if( (jp< 0) || (jp >= NPhi_[kt]) ) {
|
---|
[228] | 413 | phiMin= -88888.;
|
---|
| 414 | phiMax= -88888.;
|
---|
| 415 | return;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
[473] | 418 | double dphi= DeuxPi/(double)NPhi_[kt];
|
---|
| 419 | phiMin= dphi*(double)(jp);
|
---|
| 420 | phiMax= dphi*(double)(jp+1);
|
---|
[228] | 421 | return;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | /* --Methode-- */
|
---|
| 425 | //++
|
---|
[470] | 426 | template <class T>
|
---|
[473] | 427 | int SphereThetaPhi<T>::Index(int kt,int jp) const
|
---|
[228] | 428 |
|
---|
| 429 | // Retourne l'indice du pixel d'indice jp dans la tranche kt
|
---|
| 430 | //--
|
---|
| 431 | {
|
---|
[473] | 432 | int k;
|
---|
[228] | 433 | bool fgzn= false;
|
---|
| 434 |
|
---|
| 435 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 436 | if(kt >= NTheta_) {
|
---|
[228] | 437 | fgzn= true;
|
---|
[470] | 438 | kt= 2*NTheta_-1-kt;
|
---|
[228] | 439 | }
|
---|
| 440 |
|
---|
| 441 | // si la tranche kt contient au moins i pixels
|
---|
[470] | 442 | if( (jp>=0) && (jp<NPhi_[kt]) )
|
---|
| 443 | {
|
---|
| 444 | // dans l'hemisphere Sud
|
---|
| 445 | if (fgzn) k= NPix_-TNphi_[kt+1]+jp;
|
---|
| 446 | // dans l'hemisphere Nord
|
---|
| 447 | else k= TNphi_[kt]+jp;
|
---|
| 448 | }
|
---|
| 449 | else
|
---|
| 450 | {
|
---|
| 451 | k= 9999;
|
---|
| 452 | printf("\n la tranche %d ne contient pas un pixel de rang %d",kt,jp);
|
---|
| 453 | }
|
---|
[228] | 454 | return(k);
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | /* --Methode-- */
|
---|
| 458 | //++
|
---|
[470] | 459 | template <class T>
|
---|
[473] | 460 | void SphereThetaPhi<T>::ThetaPhiIndex(int k,int& kt,int& jp)
|
---|
[228] | 461 |
|
---|
| 462 | // Retourne les indices kt et jp du pixel d'indice k
|
---|
| 463 | //--
|
---|
| 464 | {
|
---|
[470] | 465 | bool fgzn= false;
|
---|
[228] | 466 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 467 | if(k >= NPix_/2)
|
---|
| 468 | {
|
---|
| 469 | fgzn= true;
|
---|
| 470 | k= NPix_-1-k;
|
---|
| 471 | }
|
---|
[228] | 472 |
|
---|
| 473 | // on recupere l'indice kt de la tranche qui contient le pixel k
|
---|
| 474 | int i;
|
---|
[473] | 475 | for(i = 0; i < NTheta_; i++)
|
---|
| 476 | if(k < TNphi_[i+1]) break;
|
---|
[228] | 477 |
|
---|
| 478 | // indice kt de tranche
|
---|
[470] | 479 | if (fgzn) kt= 2*NTheta_-1-i;
|
---|
[228] | 480 | else kt= i;
|
---|
| 481 |
|
---|
| 482 | // indice jp de pixel
|
---|
[470] | 483 | if (fgzn) jp= TNphi_[i+1]-k-1;
|
---|
[473] | 484 | else jp= k-TNphi_[i];
|
---|
[228] | 485 | }
|
---|
| 486 | //++
|
---|
[470] | 487 | template <class T>
|
---|
[473] | 488 | void SphereThetaPhi<T>::Pixelize(int m)
|
---|
[228] | 489 |
|
---|
| 490 | // effectue le découpage en pixels (m et pet ont la même signification
|
---|
| 491 | // que pour le constructeur)
|
---|
| 492 | //
|
---|
| 493 | // Chaque bande de theta sera découpée en partant de phi=0 ...
|
---|
| 494 | // L'autre hémisphère est parcourue dans le même sens en phi et de
|
---|
| 495 | // l'équateur vers le pôle (le pixel qui suit le dernier de la bande la plus
|
---|
| 496 | // proche de l'équateur a z>0 est celui de plus petit phi de la bande la
|
---|
| 497 | // plus proche de l'equateur a z<0).
|
---|
| 498 | //--
|
---|
| 499 | {
|
---|
[473] | 500 | int ntotpix,i,j;
|
---|
[470] | 501 |
|
---|
[228] | 502 | // Decodage et controle des arguments d'appel :
|
---|
| 503 | // au moins 2 et au plus 16384 bandes d'un hemisphere en theta
|
---|
| 504 | if (m < 2) m = 2;
|
---|
| 505 | if (m > 16384) m = 16384;
|
---|
| 506 |
|
---|
| 507 | // On memorise les arguments d'appel
|
---|
[470] | 508 | NTheta_ = m;
|
---|
[228] | 509 |
|
---|
| 510 | // On commence par decouper l'hemisphere z>0.
|
---|
| 511 | // Creation des vecteurs contenant :
|
---|
| 512 | // Les valeurs limites de theta (une valeur de plus que le nombre de bandes...)
|
---|
[473] | 513 | Theta_= new double[m+1];
|
---|
[228] | 514 |
|
---|
| 515 | // Le nombre de pixels en phi de chacune des bandes en theta
|
---|
[473] | 516 | NPhi_ = new int[m];
|
---|
[228] | 517 |
|
---|
| 518 | // Le nombre/Deuxpi total des pixels contenus dans les bandes de z superieur a une
|
---|
| 519 | // bande donnee (mTPphi[m] contient le nombre de pixels total de l'hemisphere)
|
---|
[473] | 520 | TNphi_= new int[m+1];
|
---|
[228] | 521 |
|
---|
| 522 | // Calcul du nombre total de pixels dans chaque bande pour optimiser
|
---|
| 523 | // le rapport largeur/hauteur des pixels
|
---|
| 524 |
|
---|
| 525 | //calotte polaire
|
---|
[470] | 526 | TNphi_[0]= 0;
|
---|
| 527 | NPhi_[0] = 1;
|
---|
[228] | 528 |
|
---|
| 529 | //bandes jusqu'a l'equateur
|
---|
[470] | 530 | for(j = 1; j < m; j++)
|
---|
| 531 | {
|
---|
| 532 | TNphi_[j]= TNphi_[j-1]+NPhi_[j-1];
|
---|
[473] | 533 | NPhi_[j] = (int)(.5+4.*(double)(m-.5)*sin(Pi*(double)j/(double)(2.*m-1.))) ;
|
---|
[470] | 534 | }
|
---|
[228] | 535 |
|
---|
| 536 | // Nombre total de pixels sur l'hemisphere
|
---|
[470] | 537 | ntotpix = TNphi_[m-1]+NPhi_[m-1];
|
---|
| 538 | TNphi_[m]= ntotpix;
|
---|
[228] | 539 | // et sur la sphere entiere
|
---|
[470] | 540 | NPix_= 2*ntotpix;
|
---|
[228] | 541 |
|
---|
| 542 | // Creation et initialisation du vecteur des contenus des pixels
|
---|
[470] | 543 | pixels_.ReSize(NPix_);
|
---|
| 544 | pixels_.Reset();
|
---|
| 545 |
|
---|
[228] | 546 | // Determination des limites des bandes en theta :
|
---|
| 547 | // omeg est l'angle solide couvert par chaque pixel,
|
---|
[470] | 548 | // une bande donnee kt couvre un angle solide NPhi_[kt]*omeg
|
---|
| 549 | // egal a 2* Pi*(cos Theta_[kt]-cos Theta_[kt+1]). De meme, l'angle solide
|
---|
[228] | 550 | //de la
|
---|
| 551 | // calotte allant du pole a la limite haute de la bande kt vaut
|
---|
[470] | 552 | // 2* Pi*(1.-cos Theta_[kt+1])= TNphi_[kt]*omeg...
|
---|
[228] | 553 |
|
---|
[470] | 554 | double omeg2pi= 1./(double)ntotpix;
|
---|
| 555 | Omega_ = omeg2pi*DeuxPi;
|
---|
[228] | 556 |
|
---|
[470] | 557 | for(j=0; j <= m; j++)
|
---|
| 558 | {
|
---|
| 559 | Theta_[j]= acos(1.-(double)TNphi_[j]*omeg2pi);
|
---|
| 560 | }
|
---|
[228] | 561 | }
|
---|
| 562 |
|
---|
| 563 | //++
|
---|
[470] | 564 | template <class T>
|
---|
[473] | 565 | void SphereThetaPhi<T>::GetThetaSlice(int index,double& theta, TVector<double>& phi, TVector<T>& value) const
|
---|
[228] | 566 |
|
---|
| 567 | // Retourne, pour la tranche en theta d'indice 'index' le theta
|
---|
| 568 | // correspondant, un vecteur (Peida) contenant les phi des pixels de
|
---|
| 569 | // la tranche, un vecteur (Peida) contenant les valeurs de pixel
|
---|
| 570 | // correspondantes
|
---|
| 571 | //--
|
---|
| 572 |
|
---|
| 573 | {
|
---|
| 574 | cout << "entree GetThetaSlice, couche no " << index << endl;
|
---|
[470] | 575 |
|
---|
| 576 | if(index < 0 || index > NbThetaSlices())
|
---|
| 577 | {
|
---|
| 578 | // THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range"));
|
---|
| 579 | cout << " SphereThetaPhi::GetThetaSlice : exceptions a mettre en place" <<endl;
|
---|
| 580 | THROW(rangeCheckErr);
|
---|
| 581 | }
|
---|
| 582 |
|
---|
[473] | 583 | int iring= Index(index,0);
|
---|
| 584 | int bid = this->NPhi(index);
|
---|
[470] | 585 | int lring = bid;
|
---|
[228] | 586 | cout << " iring= " << iring << " lring= " << lring << endl;
|
---|
| 587 |
|
---|
[470] | 588 | phi.ReSize(lring);
|
---|
| 589 | value.ReSize(lring);
|
---|
[473] | 590 | double Te= 0.;
|
---|
| 591 | double Fi= 0.;
|
---|
[470] | 592 | for(int kk = 0; kk < lring; kk++)
|
---|
| 593 | {
|
---|
| 594 | PixThetaPhi(kk+iring,Te,Fi);
|
---|
| 595 | phi(kk)= Fi;
|
---|
| 596 | value(kk)= PixVal(kk+iring);
|
---|
| 597 | }
|
---|
| 598 | theta= Te;
|
---|
[228] | 599 | }
|
---|
| 600 |
|
---|
[470] | 601 | template <class T>
|
---|
[473] | 602 | void SphereThetaPhi<T>::setmNPhi(int* array, int m)
|
---|
| 603 | //remplit le tableau contenant le nombre de pixels en phi de chacune des bandes en theta
|
---|
[470] | 604 | //--
|
---|
| 605 | {
|
---|
[473] | 606 | NPhi_= new int[m];
|
---|
[470] | 607 | for(int k = 0; k < m; k++) NPhi_[k]= array[k];
|
---|
| 608 | }
|
---|
[228] | 609 |
|
---|
[470] | 610 | template <class T>
|
---|
[473] | 611 | void SphereThetaPhi<T>::setmTNphi(int* array, int m)
|
---|
[470] | 612 | //remplit le tableau contenant le nombre/Deuxpi total des pixels contenus dans les bandes
|
---|
| 613 | //--
|
---|
| 614 | {
|
---|
[473] | 615 | TNphi_= new int[m];
|
---|
[470] | 616 | for(int k = 0; k < m; k++) TNphi_[k]= array[k];
|
---|
| 617 | }
|
---|
[228] | 618 |
|
---|
[470] | 619 | template <class T>
|
---|
[473] | 620 | void SphereThetaPhi<T>::setmTheta(double* array, int m)
|
---|
[470] | 621 | //remplit le tableau contenant les valeurs limites de theta
|
---|
| 622 | //--
|
---|
| 623 | {
|
---|
[473] | 624 | Theta_= new double[m];
|
---|
[470] | 625 | for(int k = 0; k < m; k++) Theta_[k]= array[k];
|
---|
| 626 | }
|
---|
| 627 |
|
---|
| 628 | template <class T>
|
---|
[473] | 629 | void SphereThetaPhi<T>::setDataBlock(T* data, int m)
|
---|
[470] | 630 | // remplit le vecteur des contenus des pixels
|
---|
| 631 | {
|
---|
| 632 | pixels_.FillFrom(m,data);
|
---|
| 633 | }
|
---|
| 634 |
|
---|
| 635 | template <class T>
|
---|
| 636 | void SphereThetaPhi<T>::print(ostream& os) const
|
---|
| 637 | {
|
---|
| 638 | if(mInfo_) os << " DVList Info= " << *mInfo_ << endl;
|
---|
| 639 | //
|
---|
| 640 | os << " NTheta_= " << NTheta_ << endl;
|
---|
| 641 | os << " NPix_ = " << NPix_ << endl;
|
---|
| 642 | os << " Omega_ = " << Omega_ << endl;
|
---|
| 643 |
|
---|
| 644 | os << " contenu de NPhi_ : ";
|
---|
| 645 | for(int i=0; i < NTheta_; i++)
|
---|
| 646 | {
|
---|
| 647 | if(i%5 == 0) os << endl;
|
---|
| 648 | os << NPhi_[i] <<", ";
|
---|
| 649 | }
|
---|
| 650 | os << endl;
|
---|
| 651 |
|
---|
| 652 | os << " contenu de Theta_ : ";
|
---|
| 653 | for(int i=0; i < NTheta_+1; i++)
|
---|
| 654 | {
|
---|
| 655 | if(i%5 == 0) os << endl;
|
---|
| 656 | os << Theta_[i] <<", ";
|
---|
| 657 | }
|
---|
| 658 | os << endl;
|
---|
| 659 |
|
---|
| 660 | os << " contenu de TNphi_ : ";
|
---|
| 661 | for(int i=0; i < NTheta_+1; i++)
|
---|
| 662 | {
|
---|
| 663 | if(i%5 == 0) os << endl;
|
---|
| 664 | os << TNphi_[i] <<", ";
|
---|
| 665 | }
|
---|
| 666 | os << endl;
|
---|
| 667 |
|
---|
| 668 | os << " contenu de pixels : ";
|
---|
| 669 | for(int i=0; i < NPix_; i++)
|
---|
| 670 | {
|
---|
| 671 | if(i%5 == 0) os << endl;
|
---|
| 672 | os << pixels_(i) <<", ";
|
---|
| 673 | }
|
---|
| 674 | os << endl;
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 | ///////////////////////////////////////////////////////////
|
---|
| 678 | // --------------------------------------------------------
|
---|
| 679 | // Les objets delegues pour la gestion de persistance
|
---|
| 680 | // --------------------------------------------------------
|
---|
| 681 | //////////////////////////////////////////////////////////
|
---|
| 682 |
|
---|
| 683 | template <class T>
|
---|
| 684 | FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi()
|
---|
| 685 | {
|
---|
| 686 | dobj= new SphereThetaPhi<T>;
|
---|
| 687 | ownobj= true;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | template <class T>
|
---|
| 691 | FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(string const& filename)
|
---|
| 692 | {
|
---|
| 693 | dobj= new SphereThetaPhi<T>;
|
---|
| 694 | ownobj= true;
|
---|
| 695 | Read(filename);
|
---|
| 696 | }
|
---|
| 697 |
|
---|
| 698 | template <class T>
|
---|
| 699 | FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(const SphereThetaPhi<T>& obj)
|
---|
| 700 | {
|
---|
| 701 | dobj= new SphereThetaPhi<T>(obj);
|
---|
| 702 | ownobj= true;
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | template <class T>
|
---|
| 706 | FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(SphereThetaPhi<T>* obj)
|
---|
| 707 | {
|
---|
| 708 | dobj= obj;
|
---|
| 709 | ownobj= false;
|
---|
| 710 | }
|
---|
| 711 |
|
---|
| 712 | template <class T>
|
---|
| 713 | FIO_SphereThetaPhi<T>::~FIO_SphereThetaPhi()
|
---|
| 714 | {
|
---|
| 715 | if (ownobj && dobj) delete dobj;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | template <class T>
|
---|
| 719 | AnyDataObj* FIO_SphereThetaPhi<T>::DataObj()
|
---|
| 720 | {
|
---|
| 721 | return(dobj);
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | template <class T>
|
---|
| 725 | void FIO_SphereThetaPhi<T>::ReadSelf(PInPersist& is)
|
---|
| 726 | {
|
---|
| 727 | cout << " FIO_SphereThetaPhi:: ReadSelf " << endl;
|
---|
| 728 |
|
---|
| 729 | if(dobj == NULL)
|
---|
| 730 | {
|
---|
| 731 | dobj= new SphereThetaPhi<T>;
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | // Pour savoir s'il y avait un DVList Info associe
|
---|
| 735 | char strg[256];
|
---|
| 736 | is.GetLine(strg, 255);
|
---|
| 737 | bool hadinfo= false;
|
---|
| 738 | if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
|
---|
| 739 | if(hadinfo)
|
---|
| 740 | { // Lecture eventuelle du DVList Info
|
---|
| 741 | is >> dobj->Info();
|
---|
| 742 | }
|
---|
| 743 |
|
---|
[473] | 744 | int mNTheta;
|
---|
[470] | 745 | is.GetI4(mNTheta);
|
---|
| 746 | dobj->setSizeIndex(mNTheta);
|
---|
| 747 |
|
---|
[473] | 748 | int mNPix;
|
---|
[470] | 749 | is.GetI4(mNPix);
|
---|
| 750 | dobj->setNbPixels(mNPix);
|
---|
| 751 |
|
---|
[473] | 752 | double mOmeg;
|
---|
[470] | 753 | is.GetR8(mOmeg);
|
---|
| 754 | dobj->setPixSolAngle(mOmeg);
|
---|
| 755 |
|
---|
[473] | 756 | int* mNphi= new int[mNTheta];
|
---|
[470] | 757 | is.GetI4s(mNphi, mNTheta);
|
---|
| 758 | dobj->setmNPhi(mNphi, mNTheta);
|
---|
| 759 | delete [] mNphi;
|
---|
| 760 |
|
---|
[473] | 761 | int* mTNphi= new int[mNTheta+1];
|
---|
[470] | 762 | is.GetI4s(mTNphi, mNTheta+1);
|
---|
| 763 | dobj->setmTNphi(mTNphi, mNTheta+1);
|
---|
| 764 | delete [] mTNphi;
|
---|
| 765 |
|
---|
[473] | 766 | double* mTheta= new double[mNTheta+1];
|
---|
| 767 | is.GetR8s(mTheta, mNTheta+1);
|
---|
[470] | 768 | dobj->setmTheta(mTheta, mNTheta+1);
|
---|
| 769 | delete [] mTheta;
|
---|
| 770 |
|
---|
| 771 | T* mPixels= new T[mNPix];
|
---|
| 772 | PIOSReadArray(is, mPixels, mNPix);
|
---|
| 773 | dobj->setDataBlock(mPixels, mNPix);
|
---|
| 774 | delete [] mPixels;
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 | template <class T>
|
---|
| 778 | void FIO_SphereThetaPhi<T>::WriteSelf(POutPersist& os) const
|
---|
| 779 | {
|
---|
| 780 | cout << " FIO_SphereThetaPhi:: WriteSelf " << endl;
|
---|
| 781 |
|
---|
| 782 | if(dobj == NULL)
|
---|
| 783 | {
|
---|
| 784 | cout << " WriteSelf:: dobj= null " << endl;
|
---|
| 785 | return;
|
---|
| 786 | }
|
---|
| 787 |
|
---|
| 788 | char strg[256];
|
---|
[473] | 789 | int mNTheta= dobj->SizeIndex();
|
---|
| 790 | int mNPix = dobj->NbPixels();
|
---|
[470] | 791 |
|
---|
| 792 | if(dobj->ptrInfo())
|
---|
| 793 | {
|
---|
| 794 | sprintf(strg,"SphereThetaPhi: NSlices=%6d NPix=%9d HasInfo",mNTheta,mNPix);
|
---|
| 795 | os.PutLine(strg);
|
---|
| 796 | os << dobj->Info();
|
---|
| 797 | }
|
---|
| 798 | else
|
---|
| 799 | {
|
---|
| 800 | sprintf(strg,"SphereThetaPhi: NSlices=%6d NPix=%9d ",mNTheta,mNPix);
|
---|
| 801 | os.PutLine(strg);
|
---|
| 802 | }
|
---|
| 803 |
|
---|
| 804 | os.PutI4(mNTheta);
|
---|
| 805 | os.PutI4(mNPix);
|
---|
| 806 | os.PutR8(dobj->PixSolAngle(0));
|
---|
| 807 | os.PutI4s(dobj->getmNPhi() , mNTheta);
|
---|
| 808 | os.PutI4s(dobj->getmTNphi(), mNTheta+1);
|
---|
[473] | 809 | os.PutR8s(dobj->getmTheta(), mNTheta+1);
|
---|
[470] | 810 | //os.Put((dobj->getDataBlock())->Data(), mNPix);
|
---|
| 811 | PIOSWriteArray(os,(dobj->getDataBlock())->Data(), mNPix);
|
---|
| 812 | }
|
---|