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