1 | #include "spherethetaphi.h"
|
---|
2 | #include "nbmath.h"
|
---|
3 | #include <complex>
|
---|
4 | #include "piocmplx.h"
|
---|
5 | #include <iostream.h>
|
---|
6 |
|
---|
7 |
|
---|
8 | //***************************************************************
|
---|
9 | //++
|
---|
10 | // Class SphereThetaPhi
|
---|
11 | //
|
---|
12 | //
|
---|
13 | // include spherethetaphi.h nbmath.h
|
---|
14 | //
|
---|
15 | // sphere splitted with respect to theta, phi : each hemisphere is
|
---|
16 | // splitted into (m-1) parallels (equator does not enter into account).
|
---|
17 | // This operation defines m slices, each of which is splitted into
|
---|
18 | // equidistant meridians. This splitting is realized in such a way that
|
---|
19 | // all pixels have the same area and are as square as possible.
|
---|
20 |
|
---|
21 | // One begins with the hemisphere with positive z, starting from the pole
|
---|
22 | // toward the equator. The first pixel is the polar cap ; it is circular
|
---|
23 | // and centered on theta=0.
|
---|
24 | //--
|
---|
25 | //++
|
---|
26 | //
|
---|
27 | // Links Parents
|
---|
28 | //
|
---|
29 | // SphericalMap
|
---|
30 | //--
|
---|
31 |
|
---|
32 | /* --Methode-- */
|
---|
33 | //++
|
---|
34 | // Titre Constructors
|
---|
35 | //--
|
---|
36 | //++
|
---|
37 |
|
---|
38 | template <class T>
|
---|
39 | SphereThetaPhi<T>::SphereThetaPhi()
|
---|
40 |
|
---|
41 | //--
|
---|
42 | {
|
---|
43 | InitNul();
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | /* --Methode-- */
|
---|
48 |
|
---|
49 | //++
|
---|
50 | template <class T>
|
---|
51 | SphereThetaPhi<T>::SphereThetaPhi(int m)
|
---|
52 |
|
---|
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.
|
---|
56 | //--
|
---|
57 | {
|
---|
58 | InitNul();
|
---|
59 | Pixelize(m);
|
---|
60 | }
|
---|
61 |
|
---|
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_;
|
---|
68 | NPhi_ = new int[NTheta_];
|
---|
69 | Theta_ = new double[NTheta_+1];
|
---|
70 | TNphi_ = new int[NTheta_+1];
|
---|
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 | }
|
---|
82 |
|
---|
83 | //++
|
---|
84 | // Titre Destructor
|
---|
85 | //--
|
---|
86 | //++
|
---|
87 | template <class T>
|
---|
88 | SphereThetaPhi<T>::~SphereThetaPhi()
|
---|
89 |
|
---|
90 | //--
|
---|
91 | {
|
---|
92 | Clear();
|
---|
93 | }
|
---|
94 |
|
---|
95 | //++
|
---|
96 | // Titre Public Méthods
|
---|
97 | //--
|
---|
98 | template <class T>
|
---|
99 | void SphereThetaPhi<T>::InitNul()
|
---|
100 | //
|
---|
101 | // initialise à zéro les variables de classe pointeurs
|
---|
102 | {
|
---|
103 | NTheta_= 0;
|
---|
104 | NPix_ = 0;
|
---|
105 | Theta_ = NULL;
|
---|
106 | NPhi_ = NULL;
|
---|
107 | TNphi_ = NULL;
|
---|
108 | pixels_.Reset();
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* --Methode-- */
|
---|
112 | template <class T>
|
---|
113 | void SphereThetaPhi<T>::Clear()
|
---|
114 |
|
---|
115 | {
|
---|
116 | if(Theta_) delete[] Theta_;
|
---|
117 | if(NPhi_ ) delete[] NPhi_;
|
---|
118 | if(TNphi_) delete[] TNphi_;
|
---|
119 | InitNul();
|
---|
120 | }
|
---|
121 |
|
---|
122 | //++
|
---|
123 | template <class T>
|
---|
124 | void SphereThetaPhi<T>::Resize(int m)
|
---|
125 | // re-pixelize the sphere
|
---|
126 | //--
|
---|
127 | {
|
---|
128 | Clear();
|
---|
129 | Pixelize(m);
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* --Methode-- */
|
---|
133 | //++
|
---|
134 | template <class T>
|
---|
135 | int SphereThetaPhi<T>::NbPixels() const
|
---|
136 |
|
---|
137 | // Return total number of pixels
|
---|
138 | //--
|
---|
139 | {
|
---|
140 | return(NPix_);
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* --Methode-- */
|
---|
144 | //++
|
---|
145 | template <class T>
|
---|
146 | T& SphereThetaPhi<T>::PixVal(int k)
|
---|
147 |
|
---|
148 | // Return value of pixel with index k
|
---|
149 | //--
|
---|
150 | {
|
---|
151 | if((k < 0) || (k >= NPix_))
|
---|
152 | {
|
---|
153 | //THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range"));
|
---|
154 | cout << " SphereThetaPhi::PIxVal : exceptions a mettre en place" <<endl;
|
---|
155 | THROW(rangeCheckErr);
|
---|
156 | }
|
---|
157 | return pixels_(k);
|
---|
158 | }
|
---|
159 |
|
---|
160 | //++
|
---|
161 | template <class T>
|
---|
162 | T const& SphereThetaPhi<T>::PixVal(int k) const
|
---|
163 |
|
---|
164 | // Return value of pixel with index k
|
---|
165 | //--
|
---|
166 | {
|
---|
167 | if((k < 0) || (k >= NPix_))
|
---|
168 | {
|
---|
169 | cout << " SphereThetaPhi::PIxVal : exceptions a mettre en place" <<endl;
|
---|
170 | //THROW(out_of_range("SphereThetaPhi::PIxVal Pixel index out of range"));
|
---|
171 | throw "SphereThetaPhi::PIxVal Pixel index out of range";
|
---|
172 | }
|
---|
173 | return *(pixels_.Data()+k);
|
---|
174 | }
|
---|
175 |
|
---|
176 | /* --Methode-- */
|
---|
177 | //++
|
---|
178 | template <class T>
|
---|
179 | bool SphereThetaPhi<T>::ContainsSph(double theta, double phi) const
|
---|
180 | //--
|
---|
181 | {
|
---|
182 | return(true);
|
---|
183 | }
|
---|
184 |
|
---|
185 | /* --Methode-- */
|
---|
186 | //++
|
---|
187 | template <class T>
|
---|
188 | int SphereThetaPhi<T>::PixIndexSph(double theta, double phi) const
|
---|
189 |
|
---|
190 | // Return index of the pixel corresponding to
|
---|
191 | // direction (theta, phi).
|
---|
192 | //--
|
---|
193 | {
|
---|
194 | double dphi;
|
---|
195 | int i,j,k;
|
---|
196 | bool fgzn = false;
|
---|
197 |
|
---|
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;}
|
---|
201 |
|
---|
202 | // La bande d'indice kt est limitée par les valeurs de theta contenues dans
|
---|
203 | // Theta_[kt] et Theta_[kt+1]
|
---|
204 | for( i=1; i< NTheta_; i++ )
|
---|
205 | if( theta < Theta_[i] ) break;
|
---|
206 |
|
---|
207 | dphi= DeuxPi/(double)NPhi_[i-1];
|
---|
208 |
|
---|
209 | if (fgzn) k= NPix_-TNphi_[i]+(int)(phi/dphi);
|
---|
210 | else k= TNphi_[i-1]+(int)(phi/dphi);
|
---|
211 | return(k);
|
---|
212 | }
|
---|
213 |
|
---|
214 | /* --Methode-- */
|
---|
215 | //++
|
---|
216 | template <class T>
|
---|
217 | void SphereThetaPhi<T>::PixThetaPhi(int k,double& theta,double& phi) const
|
---|
218 |
|
---|
219 | // Return (theta,phi) coordinates of middle of pixel with index k
|
---|
220 | //--
|
---|
221 | {
|
---|
222 | int i;
|
---|
223 | bool fgzn = false;
|
---|
224 |
|
---|
225 | if((k < 0) || (k >= NPix_)) {theta = -99999.; phi = -99999.; return; }
|
---|
226 | if( k >= NPix_/2) {fgzn = true; k = NPix_-1-k;}
|
---|
227 |
|
---|
228 | // recupère l'indice i de la tranche qui contient le pixel k
|
---|
229 | for( i=0; i< NTheta_; i++ )
|
---|
230 | if( k < TNphi_[i+1] ) break;
|
---|
231 |
|
---|
232 | // angle theta
|
---|
233 | theta= 0.5*(Theta_[i]+Theta_[i+1]);
|
---|
234 | if (fgzn) theta= Pi-theta;
|
---|
235 |
|
---|
236 | // angle phi
|
---|
237 | k -= TNphi_[i];
|
---|
238 | phi= DeuxPi/(double)NPhi_[i]*(double)(k+.5);
|
---|
239 | if (fgzn) phi= DeuxPi-phi;
|
---|
240 | }
|
---|
241 |
|
---|
242 | //++
|
---|
243 | template <class T>
|
---|
244 | double SphereThetaPhi<T>::PixSolAngle(int dummy) const
|
---|
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 | {
|
---|
252 | return Omega_;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /* --Methode-- */
|
---|
256 | //++
|
---|
257 | template <class T>
|
---|
258 | void SphereThetaPhi<T>::Limits(int k,double& tetMin,double& tetMax,double& phiMin,double& phiMax)
|
---|
259 |
|
---|
260 | // Return values of theta,phi which limit the pixel with index k
|
---|
261 | //--
|
---|
262 | {
|
---|
263 | int j;
|
---|
264 | double dphi;
|
---|
265 | bool fgzn= false;
|
---|
266 |
|
---|
267 | if((k < 0) || (k >= NPix_)) {
|
---|
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
|
---|
276 | if(k >= NPix_/2) {
|
---|
277 | fgzn= true;
|
---|
278 | k= NPix_-1-k;
|
---|
279 | }
|
---|
280 |
|
---|
281 | // on recupere l'indice i de la tranche qui contient le pixel k
|
---|
282 | int i;
|
---|
283 | for( i=0; i< NTheta_; i++ )
|
---|
284 | if(k < TNphi_[i+1]) break;
|
---|
285 |
|
---|
286 | // valeurs limites de theta dans l'hemisphere Nord
|
---|
287 | tetMin= Theta_[i];
|
---|
288 | tetMax= Theta_[i+1];
|
---|
289 | // valeurs limites de theta dans l'hemisphere Sud
|
---|
290 | if (fgzn) {
|
---|
291 | tetMin= Pi-Theta_[i+1];
|
---|
292 | tetMax= Pi-Theta_[i];
|
---|
293 | }
|
---|
294 |
|
---|
295 | // pixel correspondant dans l'hemisphere Nord
|
---|
296 | if (fgzn) k= TNphi_[i+1]-k+TNphi_[i]-1;
|
---|
297 |
|
---|
298 | // indice j de discretisation ( phi= j*dphi )
|
---|
299 | j= k-TNphi_[i];
|
---|
300 | dphi= DeuxPi/(double)NPhi_[i];
|
---|
301 |
|
---|
302 | // valeurs limites de phi
|
---|
303 | phiMin= dphi*(double)(j);
|
---|
304 | phiMax= dphi*(double)(j+1);
|
---|
305 | return;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* --Methode-- */
|
---|
309 | //++
|
---|
310 | template <class T>
|
---|
311 | int SphereThetaPhi<T>::NbThetaSlices() const
|
---|
312 |
|
---|
313 | // Return number of theta-slices on the sphere
|
---|
314 | //--
|
---|
315 | {
|
---|
316 | int nbslices;
|
---|
317 | nbslices= 2*NTheta_;
|
---|
318 | return(nbslices);
|
---|
319 | }
|
---|
320 |
|
---|
321 | /* --Methode-- */
|
---|
322 | //++
|
---|
323 | template <class T>
|
---|
324 | int SphereThetaPhi<T>::NPhi(int kt) const
|
---|
325 |
|
---|
326 | // Return number of pixels in phi-direction of the kt-th slice
|
---|
327 | //--
|
---|
328 | {
|
---|
329 | int nbpix;
|
---|
330 | // verification
|
---|
331 | if((kt < 0) || (kt >= 2*NTheta_)) return(-1);
|
---|
332 |
|
---|
333 | // si on se trouve dans l'hemisphere Sud
|
---|
334 | if(kt >= NTheta_) {
|
---|
335 | kt= 2*NTheta_-1-kt;
|
---|
336 | }
|
---|
337 |
|
---|
338 | // nombre de pixels
|
---|
339 | nbpix= NPhi_[kt];
|
---|
340 | return(nbpix);
|
---|
341 | }
|
---|
342 |
|
---|
343 |
|
---|
344 | /* --Methode-- */
|
---|
345 | //++
|
---|
346 | template <class T>
|
---|
347 | void SphereThetaPhi<T>::Theta(int kt,double& tetMin,double& tetMax)
|
---|
348 |
|
---|
349 | // Return theta values which limit the slice kt
|
---|
350 | //--
|
---|
351 | {
|
---|
352 | bool fgzn= false;
|
---|
353 | // verification
|
---|
354 | if( (kt< 0) || (kt>= 2*NTheta_) ) {
|
---|
355 | tetMin= -99999.;
|
---|
356 | tetMax= -99999.;
|
---|
357 | return;
|
---|
358 | }
|
---|
359 |
|
---|
360 | // si on se trouve dans l'hemisphere Sud
|
---|
361 | if( kt >= NTheta_ ) {
|
---|
362 | fgzn= true;
|
---|
363 | kt= 2*NTheta_-1-kt;
|
---|
364 | }
|
---|
365 |
|
---|
366 | // valeurs limites de theta dans l'hemisphere Nord
|
---|
367 | tetMin= Theta_[kt];
|
---|
368 | tetMax= Theta_[kt+1];
|
---|
369 | // valeurs limites de theta dans l'hemisphere Sud
|
---|
370 | if (fgzn) {
|
---|
371 | tetMin= Pi-Theta_[kt+1];
|
---|
372 | tetMax= Pi-Theta_[kt];
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | /* --Methode-- */
|
---|
377 | //++
|
---|
378 | template <class T>
|
---|
379 | void SphereThetaPhi<T>::Phi(int kt,int jp,double& phiMin,double& phiMax)
|
---|
380 |
|
---|
381 | // Return values of phi which limit the jp-th pixel of the kt-th slice
|
---|
382 | //--
|
---|
383 | {
|
---|
384 | // verification
|
---|
385 | if((kt < 0) || (kt >= 2*NTheta_)) {
|
---|
386 | phiMin= -99999.;
|
---|
387 | phiMax= -99999.;
|
---|
388 | return;
|
---|
389 | }
|
---|
390 |
|
---|
391 | // si on se trouve dans l'hemisphere Sud
|
---|
392 | if(kt >= NTheta_) kt= 2*NTheta_-1-kt;
|
---|
393 |
|
---|
394 | // verifie si la tranche kt contient au moins jp pixels
|
---|
395 | if( (jp< 0) || (jp >= NPhi_[kt]) ) {
|
---|
396 | phiMin= -88888.;
|
---|
397 | phiMax= -88888.;
|
---|
398 | return;
|
---|
399 | }
|
---|
400 |
|
---|
401 | double dphi= DeuxPi/(double)NPhi_[kt];
|
---|
402 | phiMin= dphi*(double)(jp);
|
---|
403 | phiMax= dphi*(double)(jp+1);
|
---|
404 | return;
|
---|
405 | }
|
---|
406 |
|
---|
407 | /* --Methode-- */
|
---|
408 | //++
|
---|
409 | template <class T>
|
---|
410 | int SphereThetaPhi<T>::Index(int kt,int jp) const
|
---|
411 |
|
---|
412 | // Return pixel index with sequence index jp in the slice kt
|
---|
413 | //--
|
---|
414 | {
|
---|
415 | int k;
|
---|
416 | bool fgzn= false;
|
---|
417 |
|
---|
418 | // si on se trouve dans l'hemisphere Sud
|
---|
419 | if(kt >= NTheta_) {
|
---|
420 | fgzn= true;
|
---|
421 | kt= 2*NTheta_-1-kt;
|
---|
422 | }
|
---|
423 |
|
---|
424 | // si la tranche kt contient au moins i pixels
|
---|
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 | }
|
---|
437 | return(k);
|
---|
438 | }
|
---|
439 |
|
---|
440 | /* --Methode-- */
|
---|
441 | //++
|
---|
442 | template <class T>
|
---|
443 | void SphereThetaPhi<T>::ThetaPhiIndex(int k,int& kt,int& jp)
|
---|
444 |
|
---|
445 | // Return indices kt (theta) and jp (phi) of pixel with index k
|
---|
446 | //--
|
---|
447 | {
|
---|
448 | bool fgzn= false;
|
---|
449 | // si on se trouve dans l'hemisphere Sud
|
---|
450 | if(k >= NPix_/2)
|
---|
451 | {
|
---|
452 | fgzn= true;
|
---|
453 | k= NPix_-1-k;
|
---|
454 | }
|
---|
455 |
|
---|
456 | // on recupere l'indice kt de la tranche qui contient le pixel k
|
---|
457 | int i;
|
---|
458 | for(i = 0; i < NTheta_; i++)
|
---|
459 | if(k < TNphi_[i+1]) break;
|
---|
460 |
|
---|
461 | // indice kt de tranche
|
---|
462 | if (fgzn) kt= 2*NTheta_-1-i;
|
---|
463 | else kt= i;
|
---|
464 |
|
---|
465 | // indice jp de pixel
|
---|
466 | if (fgzn) jp= TNphi_[i+1]-k-1;
|
---|
467 | else jp= k-TNphi_[i];
|
---|
468 | }
|
---|
469 | //++
|
---|
470 | template <class T>
|
---|
471 | void SphereThetaPhi<T>::Pixelize(int m)
|
---|
472 |
|
---|
473 | // achieve the splitting into pixels (m has the same signification
|
---|
474 | // as for the constructor)
|
---|
475 | //
|
---|
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).
|
---|
483 | //--
|
---|
484 | {
|
---|
485 | int ntotpix,i,j;
|
---|
486 |
|
---|
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
|
---|
493 | NTheta_ = m;
|
---|
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...)
|
---|
498 | Theta_= new double[m+1];
|
---|
499 |
|
---|
500 | // Le nombre de pixels en phi de chacune des bandes en theta
|
---|
501 | NPhi_ = new int[m];
|
---|
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)
|
---|
505 | TNphi_= new int[m+1];
|
---|
506 |
|
---|
507 | // Calcul du nombre total de pixels dans chaque bande pour optimiser
|
---|
508 | // le rapport largeur/hauteur des pixels
|
---|
509 |
|
---|
510 | //calotte polaire
|
---|
511 | TNphi_[0]= 0;
|
---|
512 | NPhi_[0] = 1;
|
---|
513 |
|
---|
514 | //bandes jusqu'a l'equateur
|
---|
515 | for(j = 1; j < m; j++)
|
---|
516 | {
|
---|
517 | TNphi_[j]= TNphi_[j-1]+NPhi_[j-1];
|
---|
518 | NPhi_[j] = (int)(.5+4.*(double)(m-.5)*sin(Pi*(double)j/(double)(2.*m-1.))) ;
|
---|
519 | }
|
---|
520 |
|
---|
521 | // Nombre total de pixels sur l'hemisphere
|
---|
522 | ntotpix = TNphi_[m-1]+NPhi_[m-1];
|
---|
523 | TNphi_[m]= ntotpix;
|
---|
524 | // et sur la sphere entiere
|
---|
525 | NPix_= 2*ntotpix;
|
---|
526 |
|
---|
527 | // Creation et initialisation du vecteur des contenus des pixels
|
---|
528 | pixels_.ReSize(NPix_);
|
---|
529 | pixels_.Reset();
|
---|
530 |
|
---|
531 | // Determination des limites des bandes en theta :
|
---|
532 | // omeg est l'angle solide couvert par chaque pixel,
|
---|
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
|
---|
535 | //de la
|
---|
536 | // calotte allant du pole a la limite haute de la bande kt vaut
|
---|
537 | // 2* Pi*(1.-cos Theta_[kt+1])= TNphi_[kt]*omeg...
|
---|
538 |
|
---|
539 | double omeg2pi= 1./(double)ntotpix;
|
---|
540 | Omega_ = omeg2pi*DeuxPi;
|
---|
541 |
|
---|
542 | for(j=0; j <= m; j++)
|
---|
543 | {
|
---|
544 | Theta_[j]= acos(1.-(double)TNphi_[j]*omeg2pi);
|
---|
545 | }
|
---|
546 | }
|
---|
547 |
|
---|
548 | //++
|
---|
549 | template <class T>
|
---|
550 | void SphereThetaPhi<T>::GetThetaSlice(int index,double& theta, TVector<double>& phi, TVector<T>& value) const
|
---|
551 |
|
---|
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
|
---|
556 | //--
|
---|
557 |
|
---|
558 | {
|
---|
559 | cout << "entree GetThetaSlice, couche no " << index << endl;
|
---|
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 |
|
---|
568 | int iring= Index(index,0);
|
---|
569 | int bid = this->NPhi(index);
|
---|
570 | int lring = bid;
|
---|
571 | cout << " iring= " << iring << " lring= " << lring << endl;
|
---|
572 |
|
---|
573 | phi.ReSize(lring);
|
---|
574 | value.ReSize(lring);
|
---|
575 | double Te= 0.;
|
---|
576 | double Fi= 0.;
|
---|
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;
|
---|
584 | }
|
---|
585 |
|
---|
586 | template <class T>
|
---|
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
|
---|
589 | //
|
---|
590 | {
|
---|
591 | NPhi_= new int[m];
|
---|
592 | for(int k = 0; k < m; k++) NPhi_[k]= array[k];
|
---|
593 | }
|
---|
594 |
|
---|
595 | template <class T>
|
---|
596 | void SphereThetaPhi<T>::setmTNphi(int* array, int m)
|
---|
597 | //remplit le tableau contenant le nombre/Deuxpi total des pixels contenus dans les bandes
|
---|
598 | //
|
---|
599 | {
|
---|
600 | TNphi_= new int[m];
|
---|
601 | for(int k = 0; k < m; k++) TNphi_[k]= array[k];
|
---|
602 | }
|
---|
603 |
|
---|
604 | template <class T>
|
---|
605 | void SphereThetaPhi<T>::setmTheta(double* array, int m)
|
---|
606 | //remplit le tableau contenant les valeurs limites de theta
|
---|
607 | //
|
---|
608 | {
|
---|
609 | Theta_= new double[m];
|
---|
610 | for(int k = 0; k < m; k++) Theta_[k]= array[k];
|
---|
611 | }
|
---|
612 |
|
---|
613 | template <class T>
|
---|
614 | void SphereThetaPhi<T>::setDataBlock(T* data, int m)
|
---|
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_ : ";
|
---|
630 | int i;
|
---|
631 | for(i=0; i < NTheta_; i++)
|
---|
632 | {
|
---|
633 | if(i%5 == 0) os << endl;
|
---|
634 | os << NPhi_[i] <<", ";
|
---|
635 | }
|
---|
636 | os << endl;
|
---|
637 |
|
---|
638 | os << " contenu de Theta_ : ";
|
---|
639 | for(i=0; i < NTheta_+1; i++)
|
---|
640 | {
|
---|
641 | if(i%5 == 0) os << endl;
|
---|
642 | os << Theta_[i] <<", ";
|
---|
643 | }
|
---|
644 | os << endl;
|
---|
645 |
|
---|
646 | os << " contenu de TNphi_ : ";
|
---|
647 | for(i=0; i < NTheta_+1; i++)
|
---|
648 | {
|
---|
649 | if(i%5 == 0) os << endl;
|
---|
650 | os << TNphi_[i] <<", ";
|
---|
651 | }
|
---|
652 | os << endl;
|
---|
653 |
|
---|
654 | os << " contenu de pixels : ";
|
---|
655 | for(i=0; i < NPix_; i++)
|
---|
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 |
|
---|
719 | // Let's Read the SphereCoordSys object -- ATTENTIOn - $CHECK$
|
---|
720 | SphereCoordSys* cs = dynamic_cast<SphereCoordSys*>(is.ReadObject());
|
---|
721 | dobj->SetCoordSys(cs);
|
---|
722 |
|
---|
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 |
|
---|
733 | int mNTheta;
|
---|
734 | is.GetI4(mNTheta);
|
---|
735 | dobj->setSizeIndex(mNTheta);
|
---|
736 |
|
---|
737 | int mNPix;
|
---|
738 | is.GetI4(mNPix);
|
---|
739 | dobj->setNbPixels(mNPix);
|
---|
740 |
|
---|
741 | double mOmeg;
|
---|
742 | is.GetR8(mOmeg);
|
---|
743 | dobj->setPixSolAngle(mOmeg);
|
---|
744 |
|
---|
745 | int* mNphi= new int[mNTheta];
|
---|
746 | is.GetI4s(mNphi, mNTheta);
|
---|
747 | dobj->setmNPhi(mNphi, mNTheta);
|
---|
748 | delete [] mNphi;
|
---|
749 |
|
---|
750 | int* mTNphi= new int[mNTheta+1];
|
---|
751 | is.GetI4s(mTNphi, mNTheta+1);
|
---|
752 | dobj->setmTNphi(mTNphi, mNTheta+1);
|
---|
753 | delete [] mTNphi;
|
---|
754 |
|
---|
755 | double* mTheta= new double[mNTheta+1];
|
---|
756 | is.GetR8s(mTheta, mNTheta+1);
|
---|
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 |
|
---|
776 | // Let's write the SphereCoordSys object
|
---|
777 | dobj->GetCoordSys()->Write(os);
|
---|
778 |
|
---|
779 | char strg[256];
|
---|
780 | int mNTheta= dobj->SizeIndex();
|
---|
781 | int mNPix = dobj->NbPixels();
|
---|
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);
|
---|
800 | os.PutR8s(dobj->getmTheta(), mNTheta+1);
|
---|
801 | //os.Put((dobj->getDataBlock())->Data(), mNPix);
|
---|
802 | PIOSWriteArray(os,(dobj->getDataBlock())->Data(), mNPix);
|
---|
803 | }
|
---|
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
|
---|