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