[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();
|
---|
[604] | 44 | pixels_.Reset();
|
---|
[228] | 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | /* --Methode-- */
|
---|
| 49 |
|
---|
| 50 | //++
|
---|
[470] | 51 | template <class T>
|
---|
[682] | 52 | SphereThetaPhi<T>::SphereThetaPhi(int_4 m)
|
---|
[228] | 53 |
|
---|
[565] | 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.
|
---|
[228] | 57 | //--
|
---|
| 58 | {
|
---|
| 59 | InitNul();
|
---|
[470] | 60 | Pixelize(m);
|
---|
[228] | 61 | }
|
---|
| 62 |
|
---|
[470] | 63 | template <class T>
|
---|
[574] | 64 | SphereThetaPhi<T>::SphereThetaPhi(const SphereThetaPhi<T>& s, bool share)
|
---|
| 65 | : pixels_(s.pixels_ , share)
|
---|
[470] | 66 | {
|
---|
| 67 | if(s.mInfo_) mInfo_= new DVList(*s.mInfo_);
|
---|
| 68 | NTheta_= s.NTheta_;
|
---|
| 69 | NPix_ = s.NPix_;
|
---|
[726] | 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_;
|
---|
[470] | 77 | Omega_ = s.Omega_;
|
---|
| 78 | }
|
---|
[228] | 79 |
|
---|
| 80 | //++
|
---|
[565] | 81 | // Titre Destructor
|
---|
[228] | 82 | //--
|
---|
| 83 | //++
|
---|
[470] | 84 | template <class T>
|
---|
| 85 | SphereThetaPhi<T>::~SphereThetaPhi()
|
---|
[228] | 86 |
|
---|
| 87 | //--
|
---|
[726] | 88 | {}
|
---|
[228] | 89 |
|
---|
| 90 | //++
|
---|
[565] | 91 | // Titre Public Méthods
|
---|
[228] | 92 | //--
|
---|
[470] | 93 | template <class T>
|
---|
| 94 | void SphereThetaPhi<T>::InitNul()
|
---|
[228] | 95 | //
|
---|
| 96 | {
|
---|
[470] | 97 | NTheta_= 0;
|
---|
| 98 | NPix_ = 0;
|
---|
[604] | 99 | // pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
|
---|
[228] | 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | //++
|
---|
[470] | 104 | template <class T>
|
---|
[682] | 105 | void SphereThetaPhi<T>::Resize(int_4 m)
|
---|
[470] | 106 | // re-pixelize the sphere
|
---|
[228] | 107 | //--
|
---|
| 108 | {
|
---|
[726] | 109 | InitNul();
|
---|
[470] | 110 | Pixelize(m);
|
---|
[228] | 111 | }
|
---|
| 112 |
|
---|
| 113 | /* --Methode-- */
|
---|
| 114 | //++
|
---|
[470] | 115 | template <class T>
|
---|
[682] | 116 | int_4 SphereThetaPhi<T>::NbPixels() const
|
---|
[228] | 117 |
|
---|
[565] | 118 | // Return total number of pixels
|
---|
[228] | 119 | //--
|
---|
| 120 | {
|
---|
[470] | 121 | return(NPix_);
|
---|
[228] | 122 | }
|
---|
| 123 |
|
---|
| 124 | /* --Methode-- */
|
---|
| 125 | //++
|
---|
[470] | 126 | template <class T>
|
---|
[682] | 127 | T& SphereThetaPhi<T>::PixVal(int_4 k)
|
---|
[228] | 128 |
|
---|
[565] | 129 | // Return value of pixel with index k
|
---|
[228] | 130 | //--
|
---|
| 131 | {
|
---|
[470] | 132 | if((k < 0) || (k >= NPix_))
|
---|
| 133 | {
|
---|
[726] | 134 | throw RangeCheckError("SphereThetaPhi::PIxVal Pixel index out of range");
|
---|
[470] | 135 | }
|
---|
| 136 | return pixels_(k);
|
---|
| 137 | }
|
---|
[228] | 138 |
|
---|
| 139 | //++
|
---|
[470] | 140 | template <class T>
|
---|
[682] | 141 | T const& SphereThetaPhi<T>::PixVal(int_4 k) const
|
---|
[228] | 142 |
|
---|
[565] | 143 | // Return value of pixel with index k
|
---|
[228] | 144 | //--
|
---|
| 145 | {
|
---|
[470] | 146 | if((k < 0) || (k >= NPix_))
|
---|
| 147 | {
|
---|
[726] | 148 | throw RangeCheckError("SphereThetaPhi::PIxVal Pixel index out of range");
|
---|
[470] | 149 | }
|
---|
| 150 | return *(pixels_.Data()+k);
|
---|
[228] | 151 | }
|
---|
| 152 |
|
---|
| 153 | /* --Methode-- */
|
---|
| 154 | //++
|
---|
[470] | 155 | template <class T>
|
---|
[682] | 156 | bool SphereThetaPhi<T>::ContainsSph(double /*theta*/, double /*phi*/) const
|
---|
[518] | 157 | //--
|
---|
| 158 | {
|
---|
| 159 | return(true);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | /* --Methode-- */
|
---|
| 163 | //++
|
---|
| 164 | template <class T>
|
---|
[682] | 165 | int_4 SphereThetaPhi<T>::PixIndexSph(double theta, double phi) const
|
---|
[228] | 166 |
|
---|
[565] | 167 | // Return index of the pixel corresponding to
|
---|
| 168 | // direction (theta, phi).
|
---|
[228] | 169 | //--
|
---|
| 170 | {
|
---|
[473] | 171 | double dphi;
|
---|
[574] | 172 | int i,k;
|
---|
[228] | 173 | bool fgzn = false;
|
---|
| 174 |
|
---|
[473] | 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;}
|
---|
[228] | 178 |
|
---|
| 179 | // La bande d'indice kt est limitée par les valeurs de theta contenues dans
|
---|
[470] | 180 | // Theta_[kt] et Theta_[kt+1]
|
---|
| 181 | for( i=1; i< NTheta_; i++ )
|
---|
[726] | 182 | if( theta < Theta_(i) ) break;
|
---|
[228] | 183 |
|
---|
[726] | 184 | dphi= DeuxPi/(double)NPhi_(i-1);
|
---|
[228] | 185 |
|
---|
[726] | 186 | if (fgzn) k= NPix_-TNphi_(i)+(int_4)(phi/dphi);
|
---|
| 187 | else k= TNphi_(i-1)+(int_4)(phi/dphi);
|
---|
[228] | 188 | return(k);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | /* --Methode-- */
|
---|
| 192 | //++
|
---|
[470] | 193 | template <class T>
|
---|
[682] | 194 | void SphereThetaPhi<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
|
---|
[228] | 195 |
|
---|
[565] | 196 | // Return (theta,phi) coordinates of middle of pixel with index k
|
---|
[228] | 197 | //--
|
---|
| 198 | {
|
---|
[473] | 199 | int i;
|
---|
[228] | 200 | bool fgzn = false;
|
---|
| 201 |
|
---|
[473] | 202 | if((k < 0) || (k >= NPix_)) {theta = -99999.; phi = -99999.; return; }
|
---|
| 203 | if( k >= NPix_/2) {fgzn = true; k = NPix_-1-k;}
|
---|
[228] | 204 |
|
---|
| 205 | // recupère l'indice i de la tranche qui contient le pixel k
|
---|
[470] | 206 | for( i=0; i< NTheta_; i++ )
|
---|
[726] | 207 | if( k < TNphi_(i+1) ) break;
|
---|
[228] | 208 |
|
---|
| 209 | // angle theta
|
---|
[726] | 210 | theta= 0.5*(Theta_(i)+Theta_(i+1));
|
---|
[228] | 211 | if (fgzn) theta= Pi-theta;
|
---|
| 212 |
|
---|
| 213 | // angle phi
|
---|
[726] | 214 | k -= TNphi_(i);
|
---|
| 215 | phi= DeuxPi/(double)NPhi_(i)*(double)(k+.5);
|
---|
[228] | 216 | if (fgzn) phi= DeuxPi-phi;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
[574] | 219 | template <class T>
|
---|
| 220 | T SphereThetaPhi<T>::SetPixels(T v)
|
---|
| 221 | {
|
---|
| 222 | pixels_.Reset(v);
|
---|
| 223 | return(v);
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[470] | 226 | //++
|
---|
| 227 | template <class T>
|
---|
[682] | 228 | double SphereThetaPhi<T>::PixSolAngle(int_4 /*dummy*/) const
|
---|
[228] | 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 | {
|
---|
[470] | 236 | return Omega_;
|
---|
[228] | 237 | }
|
---|
| 238 |
|
---|
| 239 | /* --Methode-- */
|
---|
| 240 | //++
|
---|
[470] | 241 | template <class T>
|
---|
[682] | 242 | void SphereThetaPhi<T>::Limits(int_4 k,double& tetMin,double& tetMax,double& phiMin,double& phiMax)
|
---|
[228] | 243 |
|
---|
[565] | 244 | // Return values of theta,phi which limit the pixel with index k
|
---|
[228] | 245 | //--
|
---|
| 246 | {
|
---|
[473] | 247 | int j;
|
---|
| 248 | double dphi;
|
---|
[228] | 249 | bool fgzn= false;
|
---|
| 250 |
|
---|
[473] | 251 | if((k < 0) || (k >= NPix_)) {
|
---|
[228] | 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
|
---|
[473] | 260 | if(k >= NPix_/2) {
|
---|
[228] | 261 | fgzn= true;
|
---|
[470] | 262 | k= NPix_-1-k;
|
---|
[228] | 263 | }
|
---|
| 264 |
|
---|
| 265 | // on recupere l'indice i de la tranche qui contient le pixel k
|
---|
| 266 | int i;
|
---|
[470] | 267 | for( i=0; i< NTheta_; i++ )
|
---|
[726] | 268 | if(k < TNphi_(i+1)) break;
|
---|
[228] | 269 |
|
---|
| 270 | // valeurs limites de theta dans l'hemisphere Nord
|
---|
[726] | 271 | tetMin= Theta_(i);
|
---|
| 272 | tetMax= Theta_(i+1);
|
---|
[228] | 273 | // valeurs limites de theta dans l'hemisphere Sud
|
---|
| 274 | if (fgzn) {
|
---|
[726] | 275 | tetMin= Pi - Theta_(i+1);
|
---|
| 276 | tetMax= Pi - Theta_(i);
|
---|
[228] | 277 | }
|
---|
| 278 |
|
---|
| 279 | // pixel correspondant dans l'hemisphere Nord
|
---|
[726] | 280 | if (fgzn) k= TNphi_(i+1)-k+TNphi_(i)-1;
|
---|
[228] | 281 |
|
---|
| 282 | // indice j de discretisation ( phi= j*dphi )
|
---|
[726] | 283 | j= k-TNphi_(i);
|
---|
| 284 | dphi= DeuxPi/(double)NPhi_(i);
|
---|
[228] | 285 |
|
---|
| 286 | // valeurs limites de phi
|
---|
[473] | 287 | phiMin= dphi*(double)(j);
|
---|
| 288 | phiMax= dphi*(double)(j+1);
|
---|
[228] | 289 | return;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | /* --Methode-- */
|
---|
| 293 | //++
|
---|
[470] | 294 | template <class T>
|
---|
[726] | 295 | uint_4 SphereThetaPhi<T>::NbThetaSlices() const
|
---|
[228] | 296 |
|
---|
[565] | 297 | // Return number of theta-slices on the sphere
|
---|
[228] | 298 | //--
|
---|
| 299 | {
|
---|
[726] | 300 | if (NTheta_<=0)
|
---|
| 301 | {
|
---|
| 302 | throw PException(" sphere not pixelized, NbSlice=0 ");
|
---|
| 303 | }
|
---|
[701] | 304 | return( 2*NTheta_);
|
---|
[228] | 305 | }
|
---|
| 306 |
|
---|
| 307 | /* --Methode-- */
|
---|
| 308 | //++
|
---|
[470] | 309 | template <class T>
|
---|
[682] | 310 | int_4 SphereThetaPhi<T>::NPhi(int_4 kt) const
|
---|
[228] | 311 |
|
---|
[565] | 312 | // Return number of pixels in phi-direction of the kt-th slice
|
---|
[228] | 313 | //--
|
---|
| 314 | {
|
---|
[473] | 315 | int nbpix;
|
---|
[228] | 316 | // verification
|
---|
[473] | 317 | if((kt < 0) || (kt >= 2*NTheta_)) return(-1);
|
---|
[228] | 318 |
|
---|
| 319 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 320 | if(kt >= NTheta_) {
|
---|
[470] | 321 | kt= 2*NTheta_-1-kt;
|
---|
[228] | 322 | }
|
---|
| 323 |
|
---|
| 324 | // nombre de pixels
|
---|
[726] | 325 | nbpix= NPhi_(kt);
|
---|
[228] | 326 | return(nbpix);
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 | /* --Methode-- */
|
---|
| 331 | //++
|
---|
[470] | 332 | template <class T>
|
---|
[682] | 333 | void SphereThetaPhi<T>::Theta(int_4 kt,double& tetMin,double& tetMax)
|
---|
[228] | 334 |
|
---|
[565] | 335 | // Return theta values which limit the slice kt
|
---|
[228] | 336 | //--
|
---|
| 337 | {
|
---|
| 338 | bool fgzn= false;
|
---|
| 339 | // verification
|
---|
[470] | 340 | if( (kt< 0) || (kt>= 2*NTheta_) ) {
|
---|
[228] | 341 | tetMin= -99999.;
|
---|
| 342 | tetMax= -99999.;
|
---|
| 343 | return;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | // si on se trouve dans l'hemisphere Sud
|
---|
[470] | 347 | if( kt >= NTheta_ ) {
|
---|
[228] | 348 | fgzn= true;
|
---|
[470] | 349 | kt= 2*NTheta_-1-kt;
|
---|
[228] | 350 | }
|
---|
| 351 |
|
---|
| 352 | // valeurs limites de theta dans l'hemisphere Nord
|
---|
[726] | 353 | tetMin= Theta_(kt);
|
---|
| 354 | tetMax= Theta_(kt+1);
|
---|
[228] | 355 | // valeurs limites de theta dans l'hemisphere Sud
|
---|
| 356 | if (fgzn) {
|
---|
[726] | 357 | tetMin= Pi - Theta_(kt+1);
|
---|
| 358 | tetMax= Pi - Theta_(kt);
|
---|
[228] | 359 | }
|
---|
| 360 | }
|
---|
| 361 |
|
---|
| 362 | /* --Methode-- */
|
---|
| 363 | //++
|
---|
[470] | 364 | template <class T>
|
---|
[682] | 365 | void SphereThetaPhi<T>::Phi(int_4 kt,int_4 jp,double& phiMin,double& phiMax)
|
---|
[228] | 366 |
|
---|
[565] | 367 | // Return values of phi which limit the jp-th pixel of the kt-th slice
|
---|
[228] | 368 | //--
|
---|
| 369 | {
|
---|
| 370 | // verification
|
---|
[473] | 371 | if((kt < 0) || (kt >= 2*NTheta_)) {
|
---|
[228] | 372 | phiMin= -99999.;
|
---|
| 373 | phiMax= -99999.;
|
---|
| 374 | return;
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 378 | if(kt >= NTheta_) kt= 2*NTheta_-1-kt;
|
---|
[228] | 379 |
|
---|
| 380 | // verifie si la tranche kt contient au moins jp pixels
|
---|
[726] | 381 | if( (jp< 0) || (jp >= NPhi_(kt)) ) {
|
---|
[228] | 382 | phiMin= -88888.;
|
---|
| 383 | phiMax= -88888.;
|
---|
| 384 | return;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
[726] | 387 | double dphi= DeuxPi/(double)NPhi_(kt);
|
---|
[473] | 388 | phiMin= dphi*(double)(jp);
|
---|
| 389 | phiMax= dphi*(double)(jp+1);
|
---|
[228] | 390 | return;
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | /* --Methode-- */
|
---|
| 394 | //++
|
---|
[470] | 395 | template <class T>
|
---|
[682] | 396 | int_4 SphereThetaPhi<T>::Index(int_4 kt,int_4 jp) const
|
---|
[228] | 397 |
|
---|
[565] | 398 | // Return pixel index with sequence index jp in the slice kt
|
---|
[228] | 399 | //--
|
---|
| 400 | {
|
---|
[473] | 401 | int k;
|
---|
[228] | 402 | bool fgzn= false;
|
---|
| 403 |
|
---|
| 404 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 405 | if(kt >= NTheta_) {
|
---|
[228] | 406 | fgzn= true;
|
---|
[470] | 407 | kt= 2*NTheta_-1-kt;
|
---|
[228] | 408 | }
|
---|
| 409 |
|
---|
| 410 | // si la tranche kt contient au moins i pixels
|
---|
[726] | 411 | if( (jp>=0) && (jp<NPhi_(kt)) )
|
---|
[470] | 412 | {
|
---|
| 413 | // dans l'hemisphere Sud
|
---|
[726] | 414 | if (fgzn) k= NPix_-TNphi_(kt+1)+jp;
|
---|
[470] | 415 | // dans l'hemisphere Nord
|
---|
[726] | 416 | else k= TNphi_(kt)+jp;
|
---|
[470] | 417 | }
|
---|
| 418 | else
|
---|
| 419 | {
|
---|
| 420 | k= 9999;
|
---|
| 421 | printf("\n la tranche %d ne contient pas un pixel de rang %d",kt,jp);
|
---|
| 422 | }
|
---|
[228] | 423 | return(k);
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | /* --Methode-- */
|
---|
| 427 | //++
|
---|
[470] | 428 | template <class T>
|
---|
[682] | 429 | void SphereThetaPhi<T>::ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp)
|
---|
[228] | 430 |
|
---|
[565] | 431 | // Return indices kt (theta) and jp (phi) of pixel with index k
|
---|
[228] | 432 | //--
|
---|
| 433 | {
|
---|
[470] | 434 | bool fgzn= false;
|
---|
[228] | 435 | // si on se trouve dans l'hemisphere Sud
|
---|
[473] | 436 | if(k >= NPix_/2)
|
---|
| 437 | {
|
---|
| 438 | fgzn= true;
|
---|
| 439 | k= NPix_-1-k;
|
---|
| 440 | }
|
---|
[228] | 441 |
|
---|
| 442 | // on recupere l'indice kt de la tranche qui contient le pixel k
|
---|
| 443 | int i;
|
---|
[473] | 444 | for(i = 0; i < NTheta_; i++)
|
---|
[726] | 445 | if(k < TNphi_(i+1)) break;
|
---|
[228] | 446 |
|
---|
| 447 | // indice kt de tranche
|
---|
[470] | 448 | if (fgzn) kt= 2*NTheta_-1-i;
|
---|
[228] | 449 | else kt= i;
|
---|
| 450 |
|
---|
| 451 | // indice jp de pixel
|
---|
[726] | 452 | if (fgzn) jp= TNphi_(i+1)-k-1;
|
---|
| 453 | else jp= k-TNphi_(i);
|
---|
[228] | 454 | }
|
---|
| 455 | //++
|
---|
[470] | 456 | template <class T>
|
---|
[682] | 457 | void SphereThetaPhi<T>::Pixelize(int_4 m)
|
---|
[228] | 458 |
|
---|
[565] | 459 | // achieve the splitting into pixels (m has the same signification
|
---|
| 460 | // as for the constructor)
|
---|
[228] | 461 | //
|
---|
[565] | 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).
|
---|
[228] | 469 | //--
|
---|
| 470 | {
|
---|
[574] | 471 | int ntotpix,j;
|
---|
[470] | 472 |
|
---|
[228] | 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
|
---|
[470] | 479 | NTheta_ = m;
|
---|
[228] | 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...)
|
---|
[726] | 484 | // Theta_= new double[m+1];
|
---|
| 485 | Theta_.ReSize(m+1);
|
---|
[228] | 486 |
|
---|
| 487 | // Le nombre de pixels en phi de chacune des bandes en theta
|
---|
[726] | 488 | // NPhi_ = new int_4[m];
|
---|
| 489 | NPhi_.ReSize(m);
|
---|
[228] | 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)
|
---|
[726] | 493 | // TNphi_= new int_4[m+1];
|
---|
| 494 | TNphi_.ReSize(m+1);
|
---|
[228] | 495 |
|
---|
| 496 | // Calcul du nombre total de pixels dans chaque bande pour optimiser
|
---|
| 497 | // le rapport largeur/hauteur des pixels
|
---|
| 498 |
|
---|
| 499 | //calotte polaire
|
---|
[726] | 500 | TNphi_(0)= 0;
|
---|
| 501 | NPhi_(0) = 1;
|
---|
[228] | 502 |
|
---|
| 503 | //bandes jusqu'a l'equateur
|
---|
[470] | 504 | for(j = 1; j < m; j++)
|
---|
| 505 | {
|
---|
[726] | 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.))) ;
|
---|
[470] | 508 | }
|
---|
[228] | 509 |
|
---|
| 510 | // Nombre total de pixels sur l'hemisphere
|
---|
[726] | 511 | ntotpix = TNphi_(m-1)+NPhi_(m-1);
|
---|
| 512 | TNphi_(m)= ntotpix;
|
---|
[228] | 513 | // et sur la sphere entiere
|
---|
[470] | 514 | NPix_= 2*ntotpix;
|
---|
[228] | 515 |
|
---|
| 516 | // Creation et initialisation du vecteur des contenus des pixels
|
---|
[470] | 517 | pixels_.ReSize(NPix_);
|
---|
| 518 | pixels_.Reset();
|
---|
| 519 |
|
---|
[228] | 520 | // Determination des limites des bandes en theta :
|
---|
| 521 | // omeg est l'angle solide couvert par chaque pixel,
|
---|
[470] | 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
|
---|
[228] | 524 | //de la
|
---|
| 525 | // calotte allant du pole a la limite haute de la bande kt vaut
|
---|
[470] | 526 | // 2* Pi*(1.-cos Theta_[kt+1])= TNphi_[kt]*omeg...
|
---|
[228] | 527 |
|
---|
[470] | 528 | double omeg2pi= 1./(double)ntotpix;
|
---|
| 529 | Omega_ = omeg2pi*DeuxPi;
|
---|
[228] | 530 |
|
---|
[470] | 531 | for(j=0; j <= m; j++)
|
---|
| 532 | {
|
---|
[726] | 533 | Theta_(j)= acos(1.-(double)TNphi_(j)*omeg2pi);
|
---|
[470] | 534 | }
|
---|
[228] | 535 | }
|
---|
| 536 |
|
---|
| 537 | //++
|
---|
[470] | 538 | template <class T>
|
---|
[746] | 539 | void SphereThetaPhi<T>::GetThetaSlice(int_4 index,r_8& theta, TVector<r_8>& phi, TVector<T>& value) const
|
---|
[228] | 540 |
|
---|
[565] | 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
|
---|
[228] | 545 | //--
|
---|
| 546 |
|
---|
| 547 | {
|
---|
[470] | 548 |
|
---|
[701] | 549 | if(index < 0 || index >= NbThetaSlices())
|
---|
[470] | 550 | {
|
---|
[726] | 551 | throw RangeCheckError("SphereThetaPhi::PIxVal Pixel index out of range");
|
---|
[470] | 552 | }
|
---|
| 553 |
|
---|
[473] | 554 | int iring= Index(index,0);
|
---|
[701] | 555 | int lring = NPhi(index);
|
---|
[228] | 556 |
|
---|
[470] | 557 | phi.ReSize(lring);
|
---|
| 558 | value.ReSize(lring);
|
---|
[473] | 559 | double Te= 0.;
|
---|
| 560 | double Fi= 0.;
|
---|
[470] | 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;
|
---|
[228] | 568 | }
|
---|
| 569 |
|
---|
[726] | 570 | //++
|
---|
[470] | 571 | template <class T>
|
---|
[746] | 572 | void SphereThetaPhi<T>::GetThetaSlice(int_4 index,r_8& theta, r_8& phi0,TVector<int_4>& pixelIndices, TVector<T>& value) const
|
---|
[228] | 573 |
|
---|
[726] | 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 |
|
---|
[470] | 582 | {
|
---|
[228] | 583 |
|
---|
[726] | 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);
|
---|
[470] | 603 | }
|
---|
| 604 |
|
---|
| 605 |
|
---|
[726] | 606 |
|
---|
| 607 |
|
---|
[470] | 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_ : ";
|
---|
[515] | 618 | int i;
|
---|
| 619 | for(i=0; i < NTheta_; i++)
|
---|
[470] | 620 | {
|
---|
| 621 | if(i%5 == 0) os << endl;
|
---|
[726] | 622 | os << NPhi_(i) <<", ";
|
---|
[470] | 623 | }
|
---|
| 624 | os << endl;
|
---|
| 625 |
|
---|
| 626 | os << " contenu de Theta_ : ";
|
---|
[515] | 627 | for(i=0; i < NTheta_+1; i++)
|
---|
[470] | 628 | {
|
---|
| 629 | if(i%5 == 0) os << endl;
|
---|
[726] | 630 | os << Theta_(i) <<", ";
|
---|
[470] | 631 | }
|
---|
| 632 | os << endl;
|
---|
| 633 |
|
---|
| 634 | os << " contenu de TNphi_ : ";
|
---|
[515] | 635 | for(i=0; i < NTheta_+1; i++)
|
---|
[470] | 636 | {
|
---|
| 637 | if(i%5 == 0) os << endl;
|
---|
[726] | 638 | os << TNphi_(i) <<", ";
|
---|
[470] | 639 | }
|
---|
| 640 | os << endl;
|
---|
| 641 |
|
---|
| 642 | os << " contenu de pixels : ";
|
---|
[515] | 643 | for(i=0; i < NPix_; i++)
|
---|
[470] | 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>;
|
---|
[701] | 668 | dobj->pixels_.SetTemp(true);
|
---|
[470] | 669 | ownobj= true;
|
---|
| 670 | Read(filename);
|
---|
| 671 | }
|
---|
| 672 |
|
---|
| 673 | template <class T>
|
---|
| 674 | FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(const SphereThetaPhi<T>& obj)
|
---|
| 675 | {
|
---|
[574] | 676 | dobj= new SphereThetaPhi<T>(obj, true);
|
---|
[701] | 677 | dobj->pixels_.SetTemp(true);
|
---|
[470] | 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 | template <class T>
|
---|
| 701 | void FIO_SphereThetaPhi<T>::ReadSelf(PInPersist& is)
|
---|
| 702 | {
|
---|
| 703 |
|
---|
| 704 | if(dobj == NULL)
|
---|
| 705 | {
|
---|
| 706 | dobj= new SphereThetaPhi<T>;
|
---|
[701] | 707 | dobj->pixels_.SetTemp(true);
|
---|
[604] | 708 | ownobj= true;
|
---|
[470] | 709 | }
|
---|
| 710 |
|
---|
[726] | 711 | // On lit les 3 premiers uint_8
|
---|
| 712 | uint_8 itab[3];
|
---|
| 713 | is.Get(itab, 3);
|
---|
[518] | 714 | // Let's Read the SphereCoordSys object -- ATTENTIOn - $CHECK$
|
---|
[701] | 715 | FIO_SphereCoordSys fio_scs( dobj->GetCoordSys());
|
---|
| 716 | fio_scs.Read(is);
|
---|
[518] | 717 |
|
---|
[470] | 718 | // Pour savoir s'il y avait un DVList Info associe
|
---|
| 719 | char strg[256];
|
---|
| 720 | is.GetLine(strg, 255);
|
---|
| 721 | bool hadinfo= false;
|
---|
| 722 | if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
|
---|
| 723 | if(hadinfo)
|
---|
| 724 | { // Lecture eventuelle du DVList Info
|
---|
| 725 | is >> dobj->Info();
|
---|
| 726 | }
|
---|
| 727 |
|
---|
[682] | 728 | int_4 mNTheta;
|
---|
[470] | 729 | is.GetI4(mNTheta);
|
---|
[682] | 730 | int_4 mNPix;
|
---|
[470] | 731 | is.GetI4(mNPix);
|
---|
[473] | 732 | double mOmeg;
|
---|
[470] | 733 | is.GetR8(mOmeg);
|
---|
[701] | 734 | dobj->setParameters(mNPix, mOmeg, mNTheta);
|
---|
[726] | 735 | FIO_NDataBlock<int_4> fio_nd_nphi(&dobj->NPhi_);
|
---|
| 736 | fio_nd_nphi.Read(is);
|
---|
| 737 | FIO_NDataBlock<int_4> fio_nd_Tnphi(&dobj->TNphi_);
|
---|
| 738 | fio_nd_Tnphi.Read(is);
|
---|
| 739 | FIO_NDataBlock<r_8> fio_nd_Theta(&dobj->Theta_);
|
---|
| 740 | fio_nd_Theta.Read(is);
|
---|
[470] | 741 |
|
---|
[701] | 742 | FIO_NDataBlock<T> fio_nd(&dobj->pixels_);
|
---|
| 743 | fio_nd.Read(is);
|
---|
[470] | 744 | }
|
---|
| 745 |
|
---|
| 746 | template <class T>
|
---|
| 747 | void FIO_SphereThetaPhi<T>::WriteSelf(POutPersist& os) const
|
---|
| 748 | {
|
---|
| 749 |
|
---|
| 750 | if(dobj == NULL)
|
---|
| 751 | {
|
---|
| 752 | cout << " WriteSelf:: dobj= null " << endl;
|
---|
| 753 | return;
|
---|
| 754 | }
|
---|
| 755 |
|
---|
[726] | 756 | // On ecrit 3 uint_8
|
---|
| 757 | // 0 : Numero de version, 1 : Size index, 2 reserve a l
|
---|
| 758 | uint_8 itab[3];
|
---|
| 759 | itab[0] = 1;
|
---|
| 760 | itab[1] = dobj->SizeIndex();
|
---|
| 761 | itab[2] = 0;
|
---|
| 762 | os.Put(itab, 3);
|
---|
[518] | 763 | // Let's write the SphereCoordSys object
|
---|
[701] | 764 | FIO_SphereCoordSys fio_scs( dobj->GetCoordSys());
|
---|
| 765 | fio_scs.Write(os);
|
---|
[518] | 766 |
|
---|
[470] | 767 | char strg[256];
|
---|
[682] | 768 | int_4 mNTheta= dobj->SizeIndex();
|
---|
| 769 | int_4 mNPix = dobj->NbPixels();
|
---|
[470] | 770 |
|
---|
| 771 | if(dobj->ptrInfo())
|
---|
| 772 | {
|
---|
| 773 | sprintf(strg,"SphereThetaPhi: NSlices=%6d NPix=%9d HasInfo",mNTheta,mNPix);
|
---|
| 774 | os.PutLine(strg);
|
---|
| 775 | os << dobj->Info();
|
---|
| 776 | }
|
---|
| 777 | else
|
---|
| 778 | {
|
---|
| 779 | sprintf(strg,"SphereThetaPhi: NSlices=%6d NPix=%9d ",mNTheta,mNPix);
|
---|
| 780 | os.PutLine(strg);
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | os.PutI4(mNTheta);
|
---|
| 784 | os.PutI4(mNPix);
|
---|
[701] | 785 | os.PutR8(dobj->PixSolAngle());
|
---|
[726] | 786 | FIO_NDataBlock<int_4> fio_nd_nphi(&dobj->NPhi_);
|
---|
| 787 | fio_nd_nphi.Write(os);
|
---|
| 788 | FIO_NDataBlock<int_4> fio_nd_Tnphi(&dobj->TNphi_);
|
---|
| 789 | fio_nd_Tnphi.Write(os);
|
---|
| 790 | FIO_NDataBlock<r_8> fio_nd_Theta(&dobj->Theta_);
|
---|
| 791 | fio_nd_Theta.Write(os);
|
---|
[701] | 792 | FIO_NDataBlock<T> fio_nd(&dobj->pixels_);
|
---|
| 793 | fio_nd.Write(os);
|
---|
[470] | 794 | }
|
---|
[515] | 795 |
|
---|
| 796 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 797 | #pragma define_template SphereThetaPhi<double>
|
---|
| 798 | #pragma define_template SphereThetaPhi<float>
|
---|
| 799 | #pragma define_template SphereThetaPhi< complex<float> >
|
---|
| 800 | #pragma define_template SphereThetaPhi< complex<double> >
|
---|
| 801 | #pragma define_template FIO_SphereThetaPhi<double>
|
---|
| 802 | #pragma define_template FIO_SphereThetaPhi<float>
|
---|
| 803 | #pragma define_template FIO_SphereThetaPhi< complex<float> >
|
---|
| 804 | #pragma define_template FIO_SphereThetaPhi< complex<double> >
|
---|
| 805 | #endif
|
---|
| 806 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 807 | template class SphereThetaPhi<double>;
|
---|
| 808 | template class SphereThetaPhi<float>;
|
---|
| 809 | template class SphereThetaPhi< complex<float> >;
|
---|
| 810 | template class SphereThetaPhi< complex<double> >;
|
---|
| 811 | template class FIO_SphereThetaPhi<double>;
|
---|
| 812 | template class FIO_SphereThetaPhi<float>;
|
---|
| 813 | template class FIO_SphereThetaPhi< complex<float> >;
|
---|
| 814 | template class FIO_SphereThetaPhi< complex<double> >;
|
---|
| 815 | #endif
|
---|