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