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