Changeset 470 in Sophya for trunk/SophyaLib/Samba/spherethetaphi.cc
- Timestamp:
- Oct 15, 1999, 5:43:30 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Samba/spherethetaphi.cc
r276 r470 1 //2 //3 1 #include "spherethetaphi.h" 4 2 #include "nbmath.h" 3 #include <complex> 4 #include "piocmplx.h" 5 5 #include <iostream.h> 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 6 28 //*************************************************************** 7 29 //++ … … 39 61 //++ 40 62 41 42 SphereThetaPhi ::SphereThetaPhi()63 template <class T> 64 SphereThetaPhi<T>::SphereThetaPhi() 43 65 44 66 //-- … … 49 71 /* --Methode-- */ 50 72 //++ 51 SphereThetaPhi::SphereThetaPhi(char* flnm) 73 template <class T> 74 SphereThetaPhi<T>::SphereThetaPhi(char* flnm) 52 75 53 76 // Constructeur : charge une image à partir d'un fichier … … 55 78 { 56 79 InitNul(); 57 PInPersist s(flnm); 58 Read(s); 59 } 60 61 /* --Methode-- */ 62 63 //++ 64 SphereThetaPhi::SphereThetaPhi(int_4 m, int_4 pet) 80 cout << " ShereThetaPhi:: constructeur lecture sur fichier A FAIRE " << endl; 81 //PInPersist s(flnm); 82 //Read(s); 83 } 84 85 /* --Methode-- */ 86 87 //++ 88 template <class T> 89 SphereThetaPhi<T>::SphereThetaPhi(int_4 m) 65 90 66 91 // Constructeur : m est le nombre de bandes en theta sur un hémisphère … … 71 96 { 72 97 InitNul(); 73 Pixelize(m,pet); 74 } 75 98 Pixelize(m); 99 } 100 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 } 76 121 77 122 //++ … … 79 124 //-- 80 125 //++ 81 SphereThetaPhi::~SphereThetaPhi() 126 template <class T> 127 SphereThetaPhi<T>::~SphereThetaPhi() 82 128 83 129 //-- … … 89 135 // Titre Méthodes 90 136 //-- 91 void SphereThetaPhi::InitNul() 137 template <class T> 138 void SphereThetaPhi<T>::InitNul() 92 139 // 93 140 // initialise à zéro les variables de classe pointeurs 94 141 { 95 mTheta = NULL; 96 mNphi = NULL; 97 mTNphi = NULL; 98 // mPix = NULL; 99 _pixel=NULL; 100 mNTheta = mNPet = 0; 101 mNPix = 0; 102 } 103 104 /* --Methode-- */ 105 void SphereThetaPhi::Clear() 106 107 { 108 if (mTheta) delete[] mTheta; 109 if (mNphi) delete[] mNphi; 110 if (mTNphi) delete[] mTNphi; 111 //if (mPix) delete[] mPix; 112 if (_pixel) _pixel->Detach(); 113 mTheta = NULL; 114 mNphi = NULL; 115 mTNphi = NULL; 116 //mPix = NULL; 117 _pixel=NULL; 118 mNTheta = mNPet = 0; 119 mNPix = 0; 120 } 121 122 /* --Methode-- */ 123 //++ 124 void SphereThetaPhi::WriteSelf(POutPersist& s) const 125 126 // créer un fichier image 127 //-- 128 { 129 char strg[256]; 130 if (mInfo_) {sprintf(strg, "SphereThetaPhi: NSlices=%6d NPix=%9d HasInfo", (int_4)mNTheta, (int_4)mNPix); 131 } 132 else { sprintf(strg, "SphereThetaPhi: NSlices=%6d NPix=%9d ", 133 (int_4)mNTheta, (int_4)mNPix); 134 } 135 s.PutLine(strg); 136 if (mInfo_) s << (*mInfo_); 137 s.PutI4(mNTheta); 138 s.PutI4(mNPet); 139 s.PutI4(mNPix); 140 s.PutR8(mOmeg); 141 s.PutR4s(mTheta, mNTheta+1); 142 s.PutI4s(mNphi, mNTheta); 143 s.PutI4s(mTNphi, mNTheta+1); 144 s.PutR8s(_pixel->Data(), mNPix); 145 //s.PutR8s(mPix, mNPix); 146 return; 147 } 148 149 /* --Methode-- */ 150 //++ 151 void SphereThetaPhi::ReadSelf(PInPersist& s) 152 153 // relit un fichier d'image 142 NTheta_= 0; 143 NPix_ = 0; 144 Theta_ = NULL; 145 NPhi_ = NULL; 146 TNphi_ = NULL; 147 pixels_.Reset(); 148 } 149 150 /* --Methode-- */ 151 template <class T> 152 void SphereThetaPhi<T>::Clear() 153 154 { 155 if(Theta_) delete[] Theta_; 156 if(NPhi_ ) delete[] NPhi_; 157 if(TNphi_) delete[] TNphi_; 158 InitNul(); 159 } 160 161 //++ 162 template <class T> 163 void SphereThetaPhi<T>::Resize(int_4 m) 164 // re-pixelize the sphere 154 165 //-- 155 166 { 156 167 Clear(); 157 char strg[256]; 158 s.GetLine(strg, 255); 159 // Pour savoir s'il y avait un DVList Info associe 160 bool hadinfo = false; 161 if (strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo = true; 162 if (hadinfo) { // Lecture eventuelle du DVList Info 163 if (mInfo_ == NULL) mInfo_ = new DVList; 164 s >> (*mInfo_); 165 } 166 s.GetI4(mNTheta); 167 s.GetI4(mNPet); 168 s.GetI4(mNPix); 169 s.GetR8(mOmeg); 170 mTheta = new r_4[mNTheta+1]; 171 mNphi = new int_4[mNTheta]; 172 mTNphi = new int_4[mNTheta+1]; 173 //mPix = new r_8[mNPix+1]; 174 _pixel=new PDataArray<r_8>(mNPix,true); 175 s.GetR4s(mTheta, mNTheta+1); 176 s.GetI4s(mNphi, mNTheta); 177 s.GetI4s(mTNphi, mNTheta+1); 178 s.GetR8s(_pixel->Data(), mNPix); 179 //s.GetR8s(mPix, mNPix); 180 return; 181 } 182 183 184 /* --Methode-- */ 185 //++ 186 int_4 SphereThetaPhi::NbPixels() const 168 Pixelize(m); 169 } 170 171 /* --Methode-- */ 172 //++ 173 template <class T> 174 int_4 SphereThetaPhi<T>::NbPixels() const 187 175 188 176 // Retourne le nombre de pixels du découpage 189 177 //-- 190 178 { 191 return(mNPix); 192 } 193 194 195 static r_8 dummy_pixel = 0; 196 197 /* --Methode-- */ 198 //++ 199 r_8& SphereThetaPhi::PixVal(int_4 k) 179 return(NPix_); 180 } 181 182 /* --Methode-- */ 183 //++ 184 template <class T> 185 T& SphereThetaPhi<T>::PixVal(int_4 k) 200 186 201 187 // Retourne la valeur du contenu du pixel d'indice k 202 188 //-- 203 189 { 204 if ( (k<0) || (k >= mNPix) ) {205 // THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range"));206 cout << " SphereThetaPhi::PIxVal : exceptions a mettre en place" <<endl;207 THROW(rangeCheckErr);208 209 //throw "SphereThetaPhi::PIxVal Pixel index out of range";210 }211 return (*(_pixel->Data()+k)); 212 //return(mPix[k]); 213 } 214 //++ 215 r_8 const& SphereThetaPhi::PixVal(int_4 k) const190 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 } 198 199 //++ 200 template <class T> 201 T const& SphereThetaPhi<T>::PixVal(int_4 k) const 216 202 217 203 // Retourne la valeur du contenu du pixel d'indice k 218 204 //-- 219 205 { 220 if ( (k<0) || (k >= mNPix) ) { 221 cout << " SphereThetaPhi::PIxVal : exceptions a mettre en place" <<endl; 222 // THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range")); 223 224 throw "SphereThetaPhi::PIxVal Pixel index out of range"; 225 } 226 return *(_pixel->Data()+k); 227 //return(mPix[k]); 228 } 229 230 231 /* --Methode-- */ 232 //++ 233 int_4 SphereThetaPhi::PixIndexSph(r_4 theta, r_4 phi) const 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); 213 } 214 215 /* --Methode-- */ 216 //++ 217 template <class T> 218 int_4 SphereThetaPhi<T>::PixIndexSph(r_4 theta, r_4 phi) const 234 219 235 220 // Retourne l'indice du pixel vers lequel pointe une direction définie par … … 246 231 247 232 // La bande d'indice kt est limitée par les valeurs de theta contenues dans 248 // mTheta[kt] et mTheta[kt+1] 249 for( i=1; i< mNTheta; i++ ) 250 if( theta < mTheta[i] ) break; 251 252 dphi= (r_4)DeuxPi/(r_4)mNphi[i-1]; 253 254 if (fgzn) k= mNPix-mTNphi[i]+(int_4)(phi/dphi); 255 else k= mTNphi[i-1]+(int_4)(phi/dphi); 256 233 // Theta_[kt] et Theta_[kt+1] 234 for( i=1; i< NTheta_; i++ ) 235 if( theta < Theta_[i] ) break; 236 237 dphi= (r_4)DeuxPi/(r_4)NPhi_[i-1]; 238 239 if (fgzn) k= NPix_-TNphi_[i]+(int_4)(phi/dphi); 240 else k= TNphi_[i-1]+(int_4)(phi/dphi); 257 241 return(k); 258 242 } 259 243 260 261 / * --Methode-- */262 //++ 263 void SphereThetaPhi ::PixThetaPhi(int_4 k, r_4& theta, r_4& phi) const244 /* --Methode-- */ 245 //++ 246 template <class T> 247 void SphereThetaPhi<T>::PixThetaPhi(int_4 k, r_4& theta, r_4& phi) const 264 248 265 249 // Retourne les coordonnées (theta,phi) du milieu du pixel d'indice k … … 269 253 bool fgzn = false; 270 254 271 if( (k < 0) || (k >= mNPix) ) {theta = -99999.; phi = -99999.; return; }272 if( k >= mNPix/2) {fgzn = true; k = mNPix-1-k; }255 if( (k < 0) || (k >= NPix_) ) {theta = -99999.; phi = -99999.; return; } 256 if( k >= NPix_/2) {fgzn = true; k = NPix_-1-k; } 273 257 274 258 // recupère l'indice i de la tranche qui contient le pixel k 275 for( i=0; i< mNTheta; i++ )276 if( k < mTNphi[i+1] ) break;259 for( i=0; i< NTheta_; i++ ) 260 if( k < TNphi_[i+1] ) break; 277 261 278 262 // angle theta 279 theta= 0.5*( mTheta[i]+mTheta[i+1]);263 theta= 0.5*(Theta_[i]+Theta_[i+1]); 280 264 if (fgzn) theta= Pi-theta; 281 265 282 266 // angle phi 283 k -= mTNphi[i];284 phi= (r_4)DeuxPi/(r_4) mNphi[i]*(r_4)(k+.5);267 k -= TNphi_[i]; 268 phi= (r_4)DeuxPi/(r_4)NPhi_[i]*(r_4)(k+.5); 285 269 if (fgzn) phi= DeuxPi-phi; 286 287 return; 288 } 289 290 291 //++ 292 r_8 SphereThetaPhi::PixSolAngle(int_4 dummy) const 270 } 271 272 //++ 273 template <class T> 274 r_8 SphereThetaPhi<T>::PixSolAngle(int_4 dummy) const 275 293 276 // Pixel Solid angle (steradians) 294 277 // All the pixels have the same solid angle. The dummy argument is … … 297 280 //-- 298 281 { 299 return mOmeg; 300 } 301 302 303 /* --Methode-- */ 304 //++ 305 void SphereThetaPhi::Limits(int_4 k, r_4& tetMin, r_4& tetMax, 306 r_4& phiMin, r_4& phiMax) 282 return Omega_; 283 } 284 285 /* --Methode-- */ 286 //++ 287 template <class T> 288 void SphereThetaPhi<T>::Limits(int_4 k, r_4& tetMin, r_4& tetMax, r_4& phiMin, r_4& phiMax) 307 289 308 290 // Retourne les valeurs de theta et phi limitant le pixel d'indice k … … 313 295 bool fgzn= false; 314 296 315 if( (k< 0) || (k >= mNPix) ) {297 if( (k< 0) || (k >= NPix_) ) { 316 298 tetMin= -99999.; 317 299 phiMin= -99999.; … … 322 304 323 305 // si on se trouve dans l'hémisphère Sud 324 if( k >= mNPix/2 ) {306 if( k >= NPix_/2 ) { 325 307 fgzn= true; 326 k= mNPix-1-k;308 k= NPix_-1-k; 327 309 } 328 310 329 311 // on recupere l'indice i de la tranche qui contient le pixel k 330 312 int i; 331 for( i=0; i< mNTheta; i++ )332 if( k< mTNphi[i+1] ) break;313 for( i=0; i< NTheta_; i++ ) 314 if( k< TNphi_[i+1] ) break; 333 315 334 316 // valeurs limites de theta dans l'hemisphere Nord 335 tetMin= mTheta[i];336 tetMax= mTheta[i+1];317 tetMin= Theta_[i]; 318 tetMax= Theta_[i+1]; 337 319 // valeurs limites de theta dans l'hemisphere Sud 338 320 if (fgzn) { 339 tetMin= Pi- mTheta[i+1];340 tetMax= Pi- mTheta[i];321 tetMin= Pi-Theta_[i+1]; 322 tetMax= Pi-Theta_[i]; 341 323 } 342 324 343 325 // pixel correspondant dans l'hemisphere Nord 344 if (fgzn) k= mTNphi[i+1]-k+mTNphi[i]-1;326 if (fgzn) k= TNphi_[i+1]-k+TNphi_[i]-1; 345 327 346 328 // indice j de discretisation ( phi= j*dphi ) 347 j= k- mTNphi[i];348 dphi= (r_4)DeuxPi/(r_4) mNphi[i];329 j= k-TNphi_[i]; 330 dphi= (r_4)DeuxPi/(r_4)NPhi_[i]; 349 331 350 332 // valeurs limites de phi … … 356 338 /* --Methode-- */ 357 339 //++ 358 int_4 SphereThetaPhi::NbThetaSlices() const 340 template <class T> 341 int_4 SphereThetaPhi<T>::NbThetaSlices() const 359 342 360 343 // Retourne le nombre de tranches en theta sur la sphere … … 362 345 { 363 346 int_4 nbslices; 364 nbslices= 2* mNTheta;347 nbslices= 2*NTheta_; 365 348 return(nbslices); 366 349 } … … 368 351 /* --Methode-- */ 369 352 //++ 370 int_4 SphereThetaPhi::NPhi(int_4 kt) const 353 template <class T> 354 int_4 SphereThetaPhi<T>::NPhi(int_4 kt) const 371 355 372 356 // Retourne le nombre de pixels en phi de la tranche kt 373 357 //-- 374 358 { 375 376 int_4 nbpix; 377 359 int_4 nbpix; 378 360 // verification 379 if( (kt< 0) || (kt>= 2* mNTheta) ) return(-1);361 if( (kt< 0) || (kt>= 2*NTheta_) ) return(-1); 380 362 381 363 // si on se trouve dans l'hemisphere Sud 382 if( kt >= mNTheta) {383 kt= 2* mNTheta-1-kt;364 if( kt >= NTheta_ ) { 365 kt= 2*NTheta_-1-kt; 384 366 } 385 367 386 368 // nombre de pixels 387 nbpix= mNphi[kt];369 nbpix= NPhi_[kt]; 388 370 return(nbpix); 389 371 } … … 392 374 /* --Methode-- */ 393 375 //++ 394 void SphereThetaPhi::Theta(int_4 kt,r_4& tetMin,r_4& tetMax) 376 template <class T> 377 void SphereThetaPhi<T>::Theta(int_4 kt,r_4& tetMin,r_4& tetMax) 395 378 396 379 // Retourne les valeurs de theta limitant la tranche kt 397 380 //-- 398 381 { 399 400 382 bool fgzn= false; 401 402 383 // verification 403 if( (kt< 0) || (kt>= 2* mNTheta) ) {384 if( (kt< 0) || (kt>= 2*NTheta_) ) { 404 385 tetMin= -99999.; 405 386 tetMax= -99999.; … … 408 389 409 390 // si on se trouve dans l'hemisphere Sud 410 if( kt >= mNTheta) {391 if( kt >= NTheta_ ) { 411 392 fgzn= true; 412 kt= 2* mNTheta-1-kt;393 kt= 2*NTheta_-1-kt; 413 394 } 414 395 415 396 // valeurs limites de theta dans l'hemisphere Nord 416 tetMin= mTheta[kt];417 tetMax= mTheta[kt+1];397 tetMin= Theta_[kt]; 398 tetMax= Theta_[kt+1]; 418 399 // valeurs limites de theta dans l'hemisphere Sud 419 400 if (fgzn) { 420 tetMin= Pi- mTheta[kt+1];421 tetMax= Pi- mTheta[kt];401 tetMin= Pi-Theta_[kt+1]; 402 tetMax= Pi-Theta_[kt]; 422 403 } 423 404 } … … 425 406 /* --Methode-- */ 426 407 //++ 427 void SphereThetaPhi::Phi(int_4 kt,int_4 jp,r_4& phiMin,r_4& phiMax) 408 template <class T> 409 void SphereThetaPhi<T>::Phi(int_4 kt,int_4 jp,r_4& phiMin,r_4& phiMax) 428 410 429 411 // Retourne les valeurs de phi limitant le pixel jp de la tranche kt 430 412 //-- 431 413 { 432 433 r_4 dphi;434 435 414 // verification 436 if( (kt< 0) || (kt>= 2* mNTheta) ) {415 if( (kt< 0) || (kt>= 2*NTheta_) ) { 437 416 phiMin= -99999.; 438 417 phiMax= -99999.; … … 441 420 442 421 // si on se trouve dans l'hemisphere Sud 443 if( kt >= mNTheta ) kt= 2*mNTheta-1-kt;422 if( kt >= NTheta_ ) kt= 2*NTheta_-1-kt; 444 423 445 424 // verifie si la tranche kt contient au moins jp pixels 446 if( (jp< 0) || (jp >= mNphi[kt]) ) {425 if( (jp< 0) || (jp >= NPhi_[kt]) ) { 447 426 phiMin= -88888.; 448 427 phiMax= -88888.; … … 450 429 } 451 430 452 dphi= (r_4)DeuxPi/(r_4)mNphi[kt];431 r_4 dphi= (r_4)DeuxPi/(r_4)NPhi_[kt]; 453 432 phiMin= dphi*(r_4)(jp); 454 433 phiMax= dphi*(r_4)(jp+1); … … 458 437 /* --Methode-- */ 459 438 //++ 460 int_4 SphereThetaPhi::Index(int_4 kt,int_4 jp) const 439 template <class T> 440 int_4 SphereThetaPhi<T>::Index(int_4 kt,int_4 jp) const 461 441 462 442 // Retourne l'indice du pixel d'indice jp dans la tranche kt 463 443 //-- 464 444 { 465 466 445 int_4 k; 467 446 bool fgzn= false; 468 447 469 448 // si on se trouve dans l'hemisphere Sud 470 if( kt >= mNTheta) {449 if( kt >= NTheta_ ) { 471 450 fgzn= true; 472 kt= 2* mNTheta-1-kt;451 kt= 2*NTheta_-1-kt; 473 452 } 474 453 475 454 // si la tranche kt contient au moins i pixels 476 if( (jp>=0) && (jp<mNphi[kt]) ) { 477 // dans l'hemisphere Sud 478 if (fgzn) k= mNPix-mTNphi[kt+1]+jp; 479 // dans l'hemisphere Nord 480 else k= mTNphi[kt]+jp; 481 } 482 else{ 483 k= 9999; 484 printf("\n la tranche %d ne contient pas un pixel de rang %d",kt,jp); 485 } 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 } 486 467 return(k); 487 468 } … … 489 470 /* --Methode-- */ 490 471 //++ 491 void SphereThetaPhi::ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp) 472 template <class T> 473 void SphereThetaPhi<T>::ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp) 492 474 493 475 // Retourne les indices kt et jp du pixel d'indice k 494 476 //-- 495 477 { 496 497 bool fgzn= false; 498 478 bool fgzn= false; 499 479 // si on se trouve dans l'hemisphere Sud 500 if( k >= mNPix/2 ) {480 if( k >= NPix_/2 ) { 501 481 fgzn= true; 502 k= mNPix-1-k;482 k= NPix_-1-k; 503 483 } 504 484 505 485 // on recupere l'indice kt de la tranche qui contient le pixel k 506 486 int i; 507 for( i=0; i< mNTheta; i++ )508 if( k< mTNphi[i+1] ) break;487 for( i=0; i< NTheta_; i++ ) 488 if( k< TNphi_[i+1] ) break; 509 489 510 490 // indice kt de tranche 511 if (fgzn) kt= 2* mNTheta-1-i;491 if (fgzn) kt= 2*NTheta_-1-i; 512 492 else kt= i; 513 493 514 494 // indice jp de pixel 515 if (fgzn) jp= mTNphi[i+1]-k-1; 516 else jp= k-mTNphi[i]; 517 518 } 519 //++ 520 void SphereThetaPhi::Pixelize( int_4 m, int_4 pet) 495 if (fgzn) jp= TNphi_[i+1]-k-1; 496 else jp= k-TNphi_[i]; 497 498 } 499 //++ 500 template <class T> 501 void SphereThetaPhi<T>::Pixelize( int_4 m) 521 502 522 503 // effectue le découpage en pixels (m et pet ont la même signification … … 531 512 { 532 513 int_4 ntotpix,i,j; 533 //r_8 x, omeg, omeg2pi, teti, tetm, tet, nphi, costeti; 534 r_8 omeg2pi; 514 535 515 // Decodage et controle des arguments d'appel : 536 516 // au moins 2 et au plus 16384 bandes d'un hemisphere en theta … … 538 518 if (m > 16384) m = 16384; 539 519 540 // Au moins 4 et au plus 256 pixels dans la premiere bande decoupee en phi541 if (pet < 4) pet = 4;542 if (pet > 256) pet = 256;543 544 520 // On memorise les arguments d'appel 545 mNTheta = m; mNPet = pet;521 NTheta_ = m; 546 522 547 523 // On commence par decouper l'hemisphere z>0. 548 524 // Creation des vecteurs contenant : 549 525 // Les valeurs limites de theta (une valeur de plus que le nombre de bandes...) 550 mTheta= new r_4[m+1];526 Theta_= new r_4[m+1]; 551 527 552 528 // Le nombre de pixels en phi de chacune des bandes en theta 553 mNphi= new int_4[m];529 NPhi_ = new int_4[m]; 554 530 555 531 // Le nombre/Deuxpi total des pixels contenus dans les bandes de z superieur a une 556 532 // bande donnee (mTPphi[m] contient le nombre de pixels total de l'hemisphere) 557 mTNphi= new int_4[m+1];533 TNphi_= new int_4[m+1]; 558 534 559 535 // Calcul du nombre total de pixels dans chaque bande pour optimiser … … 561 537 562 538 //calotte polaire 563 mTNphi[0]=0;564 mNphi[0] = 1;539 TNphi_[0]= 0; 540 NPhi_[0] = 1; 565 541 566 542 //bandes jusqu'a l'equateur 567 for(j=1; j < m; j++) { 568 mTNphi[j] = mTNphi[j-1]+mNphi[j-1]; 569 mNphi[j] = (int_4)(.5+4.*(double)(m-.5)*sin(Pi*(double)j/(double)(2.*m-1.))) ; 570 } 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 } 571 548 572 549 // Nombre total de pixels sur l'hemisphere 573 ntotpix = mTNphi[m-1]+mNphi[m-1];574 mTNphi[m]= ntotpix;550 ntotpix = TNphi_[m-1]+NPhi_[m-1]; 551 TNphi_[m]= ntotpix; 575 552 // et sur la sphere entiere 576 mNPix=2*ntotpix;553 NPix_= 2*ntotpix; 577 554 578 555 // Creation et initialisation du vecteur des contenus des pixels 579 //mPix = new r_8[mNPix]; 580 //for(i=0; i<mNPix; i++) mPix[i] = 0.; 581 _pixel=new PDataArray<r_8>(mNPix,true); 582 for(i=0; i<mNPix; i++) *(_pixel->Data()+i)=0.; 556 pixels_.ReSize(NPix_); 557 pixels_.Reset(); 558 583 559 // Determination des limites des bandes en theta : 584 560 // omeg est l'angle solide couvert par chaque pixel, 585 // une bande donnee kt couvre un angle solide mNphi[kt]*omeg586 // egal a 2* Pi*(cos mTheta[kt]-cos mTheta[kt+1]). De meme, l'angle solide561 // 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 587 563 //de la 588 564 // calotte allant du pole a la limite haute de la bande kt vaut 589 // 2* Pi*(1.-cos mTheta[kt+1])= mTNphi[kt]*omeg... 590 591 omeg2pi = 1./(r_8)ntotpix; 592 mOmeg = omeg2pi*DeuxPi; 593 594 for(j=0; j <= m; j++) { 595 mTheta[j] = acos(1.-(double)mTNphi[j]*omeg2pi); 596 } 597 } 598 599 600 //++ 601 void SphereThetaPhi::GetThetaSlice(int_4 index, r_4& theta, Vector& phi, Vector& value) const 565 // 2* Pi*(1.-cos Theta_[kt+1])= TNphi_[kt]*omeg... 566 567 double omeg2pi= 1./(double)ntotpix; 568 Omega_ = omeg2pi*DeuxPi; 569 570 for(j=0; j <= m; j++) 571 { 572 Theta_[j]= acos(1.-(double)TNphi_[j]*omeg2pi); 573 } 574 } 575 576 //++ 577 template <class T> 578 void SphereThetaPhi<T>::GetThetaSlice(int_4 index, r_4& theta, TVector<float>& phi, TVector<T>& value) const 602 579 603 580 // Retourne, pour la tranche en theta d'indice 'index' le theta … … 609 586 { 610 587 cout << "entree GetThetaSlice, couche no " << index << endl; 611 if (index<0 || index > NbThetaSlices()) { 612 // THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range")); 613 cout << " SphereThetaPhi::GetThetaSlice : exceptions a mettre en place" <<endl; 614 THROW(rangeCheckErr); 615 } 616 int_4 iring=Index(index,0); 617 int_4 bid=this->NPhi(index); 618 int lring=bid; 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; 619 599 cout << " iring= " << iring << " lring= " << lring << endl; 620 phi.Realloc(lring); 621 value.Realloc(lring); 622 float T=0.; 623 float F=0.; 624 for (int kk=0; kk<lring;kk++) { 625 PixThetaPhi(kk+iring,T,F); 626 phi(kk)=F; 627 value(kk)=PixVal(kk+iring); 628 } 629 theta=T; 630 631 } 632 633 634 /* --Methode-- */ 635 600 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; 612 } 613 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 } 622 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 } 631 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 }
Note:
See TracChangeset
for help on using the changeset viewer.