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