source: Sophya/trunk/SophyaLib/SkyMap/spherethetaphi.cc@ 4078

Last change on this file since 4078 was 4066, checked in by ansari, 13 years ago

Ajout gestion de niveau d'impression globale pour les cartes du module SkyMap ds pixelmap.h et prise en compte du niveau pour les prints ds Resize des SphericalMaps (fait en janv 2012 ?), Reza 27/04/2012

File size: 22.1 KB
Line 
1#include "sopnamsp.h"
2#include "smathconst.h"
3#include <complex>
4#include "fiondblock.h"
5#include <iostream>
6
7#define SPHERETHETAPHI_CC_BFILE // avoid extern template declarations
8#include "spherethetaphi.h"
9
10//----- global print level for spherical maps -----
11static int_4 pixel_map_prt_lev_ = 0;
12// Set global print level
13void SOPHYA::PixelMap_SetGlobalPrintLevel(int_4 lev)
14{ pixel_map_prt_lev_=lev; }
15// Get global print level
16int_4 SOPHYA::PixelMap_GetGlobalPrintLevel()
17{ return pixel_map_prt_lev_; }
18//----------------------------------------------------
19
20/*!
21 \class SOPHYA::SphereThetaPhi
22 \ingroup SkyMap
23
24 \brief Spherical map with equal latitude (iso-theta) rings
25
26
27 Class implementing spherical maps, with equal latitude (iso-theta) rings
28 pixelisation scheme - with template data types (double, float, complex, ...)
29
30 sphere splitted with respect to theta, phi : each hemisphere is
31 splitted into (m-1) parallels (equator does not enter into account).
32 This operation defines m slices, each of which is splitted into
33 equidistant meridians. This splitting is realized in such a way that
34 all pixels have the same area and are as square as possible.
35
36 One begins with the hemisphere with positive z, starting from the pole
37 toward the equator. The first pixel is the polar cap ; it is circular
38 and centered on theta=0.
39*/
40
41//***************************************************************
42//++
43// Class SphereThetaPhi
44//
45//
46// include spherethetaphi.h
47//--
48//++
49//
50// Links Parents
51//
52// SphericalMap
53//--
54
55/* --Methode-- */
56//++
57// Titre Constructors
58//--
59//++
60
61template <class T>
62SphereThetaPhi<T>::SphereThetaPhi()
63 : NPhi_(), TNphi_(), Theta_(), pixels_()
64
65//--
66{
67 InitNul();
68}
69
70
71/* --Methode-- */
72
73/*!
74 \brief Constructor with specification of number of slices (in a hemisphere)
75 \param m is the number of slices in theta on an hemisphere (the polar cap
76 forms the first slice).
77*/
78template <class T>
79SphereThetaPhi<T>::SphereThetaPhi(int_4 m)
80{
81 InitNul();
82 Pixelize(m);
83}
84
85//! Copy constructor (shares the pixel data if share==true)
86template <class T>
87SphereThetaPhi<T>::SphereThetaPhi(const SphereThetaPhi<T>& s, bool share)
88 : NPhi_(s.NPhi_, share), TNphi_(s.TNphi_, share), Theta_(s.Theta_, share),
89 pixels_(s.pixels_ , share)
90{
91
92 NTheta_= s.NTheta_;
93 NPix_ = s.NPix_;
94 Omega_ = s.Omega_;
95 if(s.mInfo_) this->mInfo_= new DVList(*s.mInfo_);
96}
97
98//! Copy constructor (shares the pixel data)
99template <class T>
100SphereThetaPhi<T>::SphereThetaPhi(const SphereThetaPhi<T>& s)
101 : NPhi_(s.NPhi_), TNphi_(s.TNphi_), Theta_(s.Theta_), pixels_(s.pixels_)
102{
103
104 NTheta_= s.NTheta_;
105 NPix_ = s.NPix_;
106 Omega_ = s.Omega_;
107 if(s.mInfo_) this->mInfo_= new DVList(*s.mInfo_);
108}
109
110//++
111// Titre Destructor
112//--
113//++
114template <class T>
115SphereThetaPhi<T>::~SphereThetaPhi()
116
117//--
118{}
119
120template <class T>
121void SphereThetaPhi<T>::InitNul()
122//
123{
124 NTheta_= 0;
125 NPix_ = 0;
126// pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
127}
128
129
130//! re-pixelize the sphere if (m > 0)
131template <class T>
132void SphereThetaPhi<T>::Resize(int_4 m)
133{
134 if ((m <= 0) && (NTheta_ > 0) ) {
135 if (PixelMap_GetGlobalPrintLevel()>0)
136 cout << "SphereThetaPhi<T>::Resize(m) with m<=0 - NOT resized" << endl;
137 return;
138 }
139 InitNul();
140 Pixelize(m);
141}
142
143//! Clone or share the SphereThetaPhi object \b a
144template<class T>
145void SphereThetaPhi<T>::CloneOrShare(const SphereThetaPhi<T>& a)
146{
147
148 NTheta_= a.NTheta_;
149 NPix_ = a.NPix_;
150 Omega_ = a.Omega_;
151 NPhi_.CloneOrShare(a.NPhi_);
152 TNphi_.CloneOrShare(a.TNphi_);
153 Theta_.CloneOrShare(a.Theta_);
154 pixels_.CloneOrShare(a.pixels_);
155 if (this->mInfo_) {delete this->mInfo_; this->mInfo_ = NULL;}
156 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
157}
158//! Share the pixel data with object \b a
159template<class T>
160void SphereThetaPhi<T>::Share(const SphereThetaPhi<T>& a)
161{
162
163 NTheta_= a.NTheta_;
164 NPix_ = a.NPix_;
165 Omega_ = a.Omega_;
166 NPhi_.Share(a.NPhi_);
167 TNphi_.Share(a.TNphi_);
168 Theta_.Share(a.Theta_);
169 pixels_.Share(a.pixels_);
170 if (this->mInfo_) {delete this->mInfo_; this->mInfo_ = NULL;}
171 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
172}
173
174////////////////////////// methodes de copie/share
175//! Perform data copy or shares the data
176template<class T>
177SphereThetaPhi<T>& SphereThetaPhi<T>::Set(const SphereThetaPhi<T>& a)
178{
179 if (this != &a)
180 {
181
182
183 if (a.NbPixels() < 1)
184 throw RangeCheckError("SphereThetaPhi<T>::Set(a ) - Array a not allocated ! ");
185 if (NbPixels() < 1) CloneOrShare(a);
186 else CopyElt(a);
187 if (this->mInfo_) delete this->mInfo_;
188 this->mInfo_ = NULL;
189 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
190 }
191 return(*this);
192}
193
194//! Perform data copy or shares the data
195template<class T>
196SphereThetaPhi<T>& SphereThetaPhi<T>::CopyElt(const SphereThetaPhi<T>& a)
197{
198 if (NbPixels() < 1)
199 throw RangeCheckError("SphereThetaPhi<T>::CopyElt(const SphereThetaPhi<T>& ) - Not Allocated Array ! ");
200 if (NbPixels() != a.NbPixels())
201 throw(SzMismatchError("SphereThetaPhi<T>::CopyElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
202
203 NTheta_= a.NTheta_;
204 NPix_ = a.NPix_;
205 Omega_ = a.Omega_;
206 for (int_4 k=0; k< NPix_; k++) pixels_(k) = a.pixels_(k);
207 for (size_t k=0; k< a.NPhi_.Size(); k++) NPhi_(k) = a.NPhi_(k);
208 for (size_t k=0; k< a.TNphi_.Size(); k++) TNphi_(k) = a.TNphi_(k);
209 for (size_t k=0; k< a.Theta_.Size(); k++) Theta_(k) = a.Theta_(k);
210 return(*this);
211
212}
213
214/* --Methode-- */
215//! Return total number of pixels
216template <class T>
217int_4 SphereThetaPhi<T>::NbPixels() const
218{
219 return(NPix_);
220}
221
222/* --Methode-- */
223//! Return value of pixel with index k
224template <class T>
225T& SphereThetaPhi<T>::PixVal(int_4 k)
226{
227 if((k < 0) || (k >= NPix_))
228 {
229 throw RangeCheckError("SphereThetaPhi::PIxVal Pixel index out of range");
230 }
231 return pixels_(k);
232}
233
234//! Return value of pixel with index k
235template <class T>
236T const& SphereThetaPhi<T>::PixVal(int_4 k) const
237{
238 if((k < 0) || (k >= NPix_))
239 {
240 throw RangeCheckError("SphereThetaPhi::PIxVal Pixel index out of range");
241 }
242 return *(pixels_.Data()+k);
243}
244
245/* --Methode-- */
246//! Return true if teta,phi in map
247template <class T>
248bool SphereThetaPhi<T>::ContainsSph(double /*theta*/, double /*phi*/) const
249{
250 return(true);
251}
252
253/* --Methode-- */
254//! Return index of the pixel corresponding to direction (theta, phi).
255template <class T>
256int_4 SphereThetaPhi<T>::PixIndexSph(double theta, double phi) const
257{
258 double dphi;
259 int_4 i,k;
260 bool fgzn = false;
261
262 if((theta > Pi) || (theta < 0.)) return(-1);
263 if((phi < 0.) || (phi > DeuxPi)) return(-1);
264 if(theta > Pi*0.5) {fgzn = true; theta = Pi-theta;}
265
266 // La bande d'indice kt est limitée par les valeurs de theta contenues dans
267 // Theta_[kt] et Theta_[kt+1]
268 for( i=1; i< NTheta_; i++ )
269 if( theta < Theta_(i) ) break;
270
271 dphi= DeuxPi/(double)NPhi_(i-1);
272
273 if (fgzn) k= NPix_-TNphi_(i)+(int_4)(phi/dphi);
274 else k= TNphi_(i-1)+(int_4)(phi/dphi);
275 return(k);
276}
277
278/* --Methode-- */
279//! Return (theta,phi) coordinates of middle of pixel with index k
280template <class T>
281void SphereThetaPhi<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
282{
283 int_4 i;
284 bool fgzn = false;
285
286 if((k < 0) || (k >= NPix_)) {theta = -99999.; phi = -99999.; return; }
287 if( k >= NPix_/2) {fgzn = true; k = NPix_-1-k;}
288
289 // recupère l'indice i de la tranche qui contient le pixel k
290 for( i=0; i< NTheta_; i++ )
291 if( k < TNphi_(i+1) ) break;
292
293 // angle theta
294 theta= 0.5*(Theta_(i)+Theta_(i+1));
295 if (fgzn) theta= Pi-theta;
296
297 // angle phi
298 k -= TNphi_(i);
299 phi= DeuxPi/(double)NPhi_(i)*(double)(k+.5);
300 if (fgzn) phi= DeuxPi-phi;
301}
302
303//! Setting pixel values to a constant
304template <class T>
305T SphereThetaPhi<T>::SetPixels(T v)
306{
307pixels_.Reset(v);
308return(v);
309}
310
311/*!
312 \brief Pixel Solid angle (steradians)
313 All the pixels have the same solid angle. The dummy argument is
314 for compatibility with eventual pixelizations which would not
315 fulfil this requirement.
316*/
317template <class T>
318double SphereThetaPhi<T>::PixSolAngle(int_4 /*dummy*/) const
319
320{
321 return Omega_;
322}
323
324/* --Methode-- */
325//! Return values of theta,phi which limit the pixel with index k
326template <class T>
327void SphereThetaPhi<T>::Limits(int_4 k,double& tetMin,double& tetMax,double& phiMin,double& phiMax)
328 {
329 int_4 j;
330 double dphi;
331 bool fgzn= false;
332
333 if((k < 0) || (k >= NPix_)) {
334 tetMin= -99999.;
335 phiMin= -99999.;
336 tetMax= -99999.;
337 phiMax= -99999.;
338 return;
339 }
340
341 // si on se trouve dans l'hémisphère Sud
342 if(k >= NPix_/2) {
343 fgzn= true;
344 k= NPix_-1-k;
345 }
346
347 // on recupere l'indice i de la tranche qui contient le pixel k
348 int_4 i;
349 for( i=0; i< NTheta_; i++ )
350 if(k < TNphi_(i+1)) break;
351
352 // valeurs limites de theta dans l'hemisphere Nord
353 tetMin= Theta_(i);
354 tetMax= Theta_(i+1);
355 // valeurs limites de theta dans l'hemisphere Sud
356 if (fgzn) {
357 tetMin= Pi - Theta_(i+1);
358 tetMax= Pi - Theta_(i);
359 }
360
361 // pixel correspondant dans l'hemisphere Nord
362 if (fgzn) k= TNphi_(i+1)-k+TNphi_(i)-1;
363
364 // indice j de discretisation ( phi= j*dphi )
365 j= k-TNphi_(i);
366 dphi= DeuxPi/(double)NPhi_(i);
367
368 // valeurs limites de phi
369 phiMin= dphi*(double)(j);
370 phiMax= dphi*(double)(j+1);
371 return;
372}
373
374/* --Methode-- */
375//! Return number of theta-slices on the sphere
376template <class T>
377uint_4 SphereThetaPhi<T>::NbThetaSlices() const
378{
379 if (NTheta_<=0)
380 {
381 throw PException(" sphere not pixelized, NbSlice=0 ");
382 }
383 return( 2*NTheta_);
384}
385
386/* --Methode-- */
387//! Return number of pixels along the phi-direction of the kt-th slice
388template <class T>
389int_4 SphereThetaPhi<T>::NPhi(int_4 kt) const
390{
391 int_4 nbpix;
392 // verification
393 if((kt < 0) || (kt >= 2*NTheta_)) return(-1);
394
395 // si on se trouve dans l'hemisphere Sud
396 if(kt >= NTheta_) {
397 kt= 2*NTheta_-1-kt;
398 }
399
400 // nombre de pixels
401 nbpix= NPhi_(kt);
402 return(nbpix);
403}
404
405
406/* --Methode-- */
407//! Return theta values which limit the slice kt
408template <class T>
409void SphereThetaPhi<T>::Theta(int_4 kt,double& tetMin,double& tetMax) const
410{
411 bool fgzn= false;
412 // verification
413 if( (kt< 0) || (kt>= 2*NTheta_) ) {
414 tetMin= -99999.;
415 tetMax= -99999.;
416 return;
417 }
418
419 // si on se trouve dans l'hemisphere Sud
420 if( kt >= NTheta_ ) {
421 fgzn= true;
422 kt= 2*NTheta_-1-kt;
423 }
424
425 // valeurs limites de theta dans l'hemisphere Nord
426 tetMin= Theta_(kt);
427 tetMax= Theta_(kt+1);
428 // valeurs limites de theta dans l'hemisphere Sud
429 if (fgzn) {
430 tetMin= Pi - Theta_(kt+1);
431 tetMax= Pi - Theta_(kt);
432 }
433}
434
435/* --Methode-- */
436//! Return values of phi which limit the jp-th pixel of the kt-th slice
437template <class T>
438void SphereThetaPhi<T>::Phi(int_4 kt,int_4 jp,double& phiMin,double& phiMax) const
439{
440 // verification
441 if((kt < 0) || (kt >= 2*NTheta_)) {
442 phiMin= -99999.;
443 phiMax= -99999.;
444 return;
445 }
446
447 // si on se trouve dans l'hemisphere Sud
448 if(kt >= NTheta_) kt= 2*NTheta_-1-kt;
449
450 // verifie si la tranche kt contient au moins jp pixels
451 if( (jp< 0) || (jp >= NPhi_(kt)) ) {
452 phiMin= -88888.;
453 phiMax= -88888.;
454 return;
455 }
456
457 double dphi= DeuxPi/(double)NPhi_(kt);
458 phiMin= dphi*(double)(jp);
459 phiMax= dphi*(double)(jp+1);
460 return;
461}
462
463/* --Methode-- */
464//! Return pixel index with sequence index jp in the slice kt
465template <class T>
466int_4 SphereThetaPhi<T>::Index(int_4 kt,int_4 jp) const
467{
468 int_4 k;
469 bool fgzn= false;
470
471 // si on se trouve dans l'hemisphere Sud
472 if(kt >= NTheta_) {
473 fgzn= true;
474 kt= 2*NTheta_-1-kt;
475 }
476
477 // si la tranche kt contient au moins i pixels
478 if( (jp>=0) && (jp<NPhi_(kt)) )
479 {
480 // dans l'hemisphere Sud
481 if (fgzn) k= NPix_-TNphi_(kt+1)+jp;
482 // dans l'hemisphere Nord
483 else k= TNphi_(kt)+jp;
484 }
485 else
486 {
487 k= 9999;
488 printf("\n la tranche %d ne contient pas un pixel de rang %d",kt,jp);
489 }
490 return(k);
491}
492
493/* --Methode-- */
494//! Return indices kt (theta) and jp (phi) of pixel with index k
495template <class T>
496void SphereThetaPhi<T>::ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp)
497{
498 bool fgzn= false;
499 // si on se trouve dans l'hemisphere Sud
500 if(k >= NPix_/2)
501 {
502 fgzn= true;
503 k= NPix_-1-k;
504 }
505
506 // on recupere l'indice kt de la tranche qui contient le pixel k
507 int_4 i;
508 for(i = 0; i < NTheta_; i++)
509 if(k < TNphi_(i+1)) break;
510
511 // indice kt de tranche
512 if (fgzn) kt= 2*NTheta_-1-i;
513 else kt= i;
514
515 // indice jp de pixel
516 if (fgzn) jp= TNphi_(i+1)-k-1;
517 else jp= k-TNphi_(i);
518}
519/*!
520 \brief achieve the splitting into pixels
521 m has the same signification as for the constructor
522
523 Each theta-slice of the north hemisphere will be spitted starting f
524 from phi=0 ...
525
526 South hemisphere is scanned in the same direction according to phi
527 and from equator to the pole (the pixel following the last one of
528 the slice closest to the equator with z>0, is the pixel with lowest
529 phi of the slice closest of the equator with z<0).
530*/
531template <class T>
532void SphereThetaPhi<T>::Pixelize(int_4 m)
533
534//--
535{
536 int_4 ntotpix,j;
537
538 // Decodage et controle des arguments d'appel :
539 // au moins 2 et au plus 524288 bandes d'un hemisphere en theta
540 if (m < 2) m = 2;
541 if (m > 524288) m = 524288;
542
543 // On memorise les arguments d'appel
544 NTheta_ = m;
545
546 // On commence par decouper l'hemisphere z>0.
547 // Creation des vecteurs contenant :
548 // Les valeurs limites de theta (une valeur de plus que le nombre de bandes...)
549 // Theta_= new double[m+1];
550 Theta_.ReSize(m+1);
551
552 // Le nombre de pixels en phi de chacune des bandes en theta
553 // NPhi_ = new int_4[m];
554 // une taille de m suffit, mais je mets m+1 pour que les 3 tableaux aient
555 // la meme taille pour une manipulation plus faciles par la librairie
556 // cfitsio -- GLM (13-04-00)
557 NPhi_.ReSize(m+1);
558
559 // Le nombre/Deuxpi total des pixels contenus dans les bandes de z superieur a une
560 // bande donnee (mTPphi[m] contient le nombre de pixels total de l'hemisphere)
561 // TNphi_= new int_4[m+1];
562 TNphi_.ReSize(m+1);
563
564 // Calcul du nombre total de pixels dans chaque bande pour optimiser
565 // le rapport largeur/hauteur des pixels
566
567 //calotte polaire
568 TNphi_(0)= 0;
569 NPhi_(0) = 1;
570
571 //bandes jusqu'a l'equateur
572 for(j = 1; j < m; j++)
573 {
574 TNphi_(j)= TNphi_(j-1)+NPhi_(j-1);
575 NPhi_(j) = (int_4)(.5+4.*(double)(m-.5)*sin(Pi*(double)j/(double)(2.*m-1.))) ;
576 }
577
578 // Nombre total de pixels sur l'hemisphere
579 ntotpix = TNphi_(m-1)+NPhi_(m-1);
580 TNphi_(m)= ntotpix;
581 // et sur la sphere entiere
582 NPix_= 2*ntotpix;
583
584 // Creation et initialisation du vecteur des contenus des pixels
585 pixels_.ReSize(NPix_);
586 pixels_.Reset();
587
588 // Determination des limites des bandes en theta :
589 // omeg est l'angle solide couvert par chaque pixel,
590 // une bande donnee kt couvre un angle solide NPhi_[kt]*omeg
591 // egal a 2* Pi*(cos Theta_[kt]-cos Theta_[kt+1]). De meme, l'angle solide
592 //de la
593 // calotte allant du pole a la limite haute de la bande kt vaut
594 // 2* Pi*(1.-cos Theta_[kt+1])= TNphi_[kt]*omeg...
595
596 double omeg2pi= 1./(double)ntotpix;
597 Omega_ = omeg2pi*DeuxPi;
598
599 for(j=0; j <= m; j++)
600 {
601 Theta_(j)= acos(1.-(double)TNphi_(j)*omeg2pi);
602 }
603}
604
605//! Return the theta angle for slice defined by \b index
606template <class T>
607r_8 SphereThetaPhi<T>::ThetaOfSlice(int_4 index) const
608{
609 if(index < 0 || index >= 2*NTheta_)
610 throw RangeCheckError("SphereThetaPhi::ThetaOfSlice() index out of range");
611 double tet1, tet2;
612 Theta(index, tet1, tet2);
613 return 0.5*(tet1+tet2);
614}
615
616//! Return true : All theta slices have a symmetric slice at Pi-Theta in SphereThetaPhi
617template <class T>
618bool SphereThetaPhi<T>::HasSymThetaSlice() const
619{
620 return true;
621}
622//! Return the slice index for the symmetric slice at theta=Pi-ThetaOfSlice(idx)
623template <class T>
624int_4 SphereThetaPhi<T>::GetSymThetaSliceIndex(int_4 idx) const
625{
626 if(idx < 0 || idx >= (int_4)NbThetaSlices())
627 throw RangeCheckError("SphereThetaPhi::GetSymThetaSliceIndex index out of range");
628 return (NbThetaSlices()-1-idx);
629}
630
631/*!
632 \brief return a Theta slice information
633 For a theta-slice with index 'index', return :
634 the corresponding "theta"
635 a vector containing the phi's of the pixels of the slice
636 a vector containing the corresponding values of pixels
637*/
638template <class T>
639void SphereThetaPhi<T>::GetThetaSlice(int_4 index,r_8& theta, TVector<r_8>& phi, TVector<T>& value) const
640
641{
642
643 if(index < 0 || index >= (int_4)NbThetaSlices())
644 throw RangeCheckError("SphereThetaPhi::GetThetaSlice(idx...) index out of range");
645
646
647 int_4 iring= Index(index,0);
648 int_4 lring = NPhi(index);
649
650 phi.ReSize(lring);
651 value.ReSize(lring);
652 double Te= 0.;
653 double Fi= 0.;
654 PixThetaPhi(iring,Te,Fi);
655 double DFi = DeuxPi/(double)NPhi(index);
656 for(int_4 kk = 0; kk < lring; kk++) {
657 value(kk)= pixels_(kk+iring);
658 phi(kk)= Fi;
659 Fi += DFi;
660 }
661 theta= Te;
662}
663
664/*
665 \brief return information on a theta slice
666 For a theta-slice with index 'index', return :
667 the corresponding "theta"
668 the corresponding "phi" for first pixel of the slice
669 a vector containing the indices of the pixels of the slice
670 (equally distributed in phi)
671 a vector containing the corresponding values of pixels
672*/
673template <class T>
674void SphereThetaPhi<T>::GetThetaSlice(int_4 index,r_8& theta, r_8& phi0,TVector<int_4>& pixelIndices, TVector<T>& value) const
675
676{
677
678 if(index < 0 || index >= (int_4)NbThetaSlices())
679 throw RangeCheckError("SphereThetaPhi::GetThetaSlice(idx...) idx out of range");
680
681 int_4 iring= Index(index,0);
682 int_4 lring = NPhi(index);
683
684 pixelIndices.ReSize(lring);
685 value.ReSize(lring);
686 for(int_4 kk = 0; kk < lring; kk++) {
687 pixelIndices(kk)=kk+iring ;
688 value(kk)= pixels_(kk+iring);
689 }
690 PixThetaPhi(iring,theta,phi0);
691}
692
693//! return a pointer to the specified slice pixel data
694template <class T>
695T* SphereThetaPhi<T>::GetThetaSliceDataPtr(int_4 index)
696{
697 if(index < 0 || index >= (int_4)NbThetaSlices())
698 throw RangeCheckError("SphereThetaPhi::GetThetaSliceDataPtr(idx) idx out of range");
699 return pixels_.Begin()+Index(index,0);
700}
701
702
703template <class T>
704void SphereThetaPhi<T>::print(ostream& os) const
705{
706 this->Show(os);
707 os << "SphereThetaPhi<T> NTheta_= " << NTheta_ << " NPix_ = " << NPix_
708 << " Omega_ = " << Omega_ << endl;
709 if(this->mInfo_) os << " DVList Info= " << *(this->mInfo_) << endl;
710
711 os << "... NPhi_ Values : ";
712 int_4 i;
713 for(i=0; i < NTheta_; i++)
714 {
715 if(i%5 == 0) os << endl;
716 os << NPhi_(i) <<", ";
717 }
718 os << endl;
719
720 os << "... Theta_ Values : ";
721 for(i=0; i < NTheta_+1; i++)
722 {
723 if(i%5 == 0) os << endl;
724 os << Theta_(i) <<", ";
725 }
726 os << endl;
727
728 os << "... TNphi_ Values : ";
729 for(i=0; i < NTheta_+1; i++)
730 {
731 if(i%5 == 0) os << endl;
732 os << TNphi_(i) <<", ";
733 }
734 os << endl;
735
736 os << "... Pixel Values : ";
737 for(i=0; i < NPix_; i++)
738 {
739 if(i%5 == 0) os << endl;
740 os << pixels_(i) <<", ";
741 }
742 os << endl;
743}
744
745// ...... Operations de calcul ......
746
747
748//! Fill a SphereThetaPhi with a constant value \b a
749template <class T>
750SphereThetaPhi<T>& SphereThetaPhi<T>::SetT(T a)
751{
752 if (NbPixels() < 1)
753 throw RangeCheckError("SphereThetaPhi<T>::SetT(T ) - SphereThetaPhi not dimensionned ! ");
754 pixels_ = a;
755 return (*this);
756}
757
758/*! Add a constant value \b x to a SphereThetaPhi */
759template <class T>
760SphereThetaPhi<T>& SphereThetaPhi<T>::Add(T a)
761 {
762 if (NbPixels()< 1)
763 throw RangeCheckError("SphereThetaPhi<T>::Add(T ) - SphereThetaPhi not dimensionned ! ");
764 pixels_ += a;
765 return (*this);
766}
767
768/*! Substract a constant value \b a to a SphereThetaPhi */
769template <class T>
770SphereThetaPhi<T>& SphereThetaPhi<T>::Sub(T a,bool fginv)
771{
772 if (NbPixels()< 1)
773 throw RangeCheckError("SphereThetaPhi<T>::Sub(T ) - SphereThetaPhi not dimensionned ! ");
774 pixels_.Sub(a,fginv);
775 return (*this);
776}
777
778/*! multiply a SphereThetaPhi by a constant value \b a */
779template <class T>
780SphereThetaPhi<T>& SphereThetaPhi<T>::Mul(T a)
781{
782 if (NbPixels()< 1)
783 throw RangeCheckError("SphereThetaPhi<T>::Mul(T ) - SphereThetaPhi not dimensionned ! ");
784 pixels_ *= a;
785 return (*this);
786}
787
788/*! divide a SphereThetaPhi by a constant value \b a */
789template <class T>
790SphereThetaPhi<T>& SphereThetaPhi<T>::Div(T a)
791{
792 if (NbPixels()< 1)
793 throw RangeCheckError("SphereThetaPhi<T>::Div(T ) - SphereThetaPhi not dimensionned ! ");
794 pixels_ /= a;
795 return (*this);
796}
797
798// >>>> Operations avec 2nd membre de type SphereThetaPhi
799//! Add two SphereThetaPhi
800
801template <class T>
802SphereThetaPhi<T>& SphereThetaPhi<T>::AddElt(const SphereThetaPhi<T>& a)
803{
804 if (NbPixels()!= a.NbPixels())
805 {
806 throw(SzMismatchError("SphereThetaPhi<T>::AddElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
807 }
808 pixels_ += a.pixels_;
809 return (*this);
810}
811
812//! Substract two SphereThetaPhi
813template <class T>
814SphereThetaPhi<T>& SphereThetaPhi<T>::SubElt(const SphereThetaPhi<T>& a)
815{
816 if (NbPixels()!= a.NbPixels())
817 {
818 throw(SzMismatchError("SphereThetaPhi<T>::SubElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
819 }
820 pixels_ -= a.pixels_;
821 return (*this);
822}
823
824//! Multiply two SphereThetaPhi (elements by elements)
825template <class T>
826SphereThetaPhi<T>& SphereThetaPhi<T>::MulElt(const SphereThetaPhi<T>& a)
827{
828 if (NbPixels()!= a.NbPixels())
829 {
830 throw(SzMismatchError("SphereThetaPhi<T>::MulElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
831 }
832 pixels_ *= a.pixels_;
833 return (*this);
834}
835
836//! Divide two SphereThetaPhi (elements by elements) - No protection for divide by 0
837template <class T>
838SphereThetaPhi<T>& SphereThetaPhi<T>::DivElt(const SphereThetaPhi<T>& a)
839{
840 if (NbPixels()!= a.NbPixels())
841 {
842 throw(SzMismatchError("SphereThetaPhi<T>::DivElt(const SphereThetaPhi<T>&) SizeMismatch")) ;
843 }
844 pixels_ /= a.pixels_;
845 return (*this);
846}
847
848
849
850#ifdef __CXX_PRAGMA_TEMPLATES__
851#pragma define_template SphereThetaPhi<int_4>
852#pragma define_template SphereThetaPhi<r_8>
853#pragma define_template SphereThetaPhi<r_4>
854#pragma define_template SphereThetaPhi< complex<r_4> >
855#pragma define_template SphereThetaPhi< complex<r_8> >
856#endif
857#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
858namespace SOPHYA {
859template class SphereThetaPhi<int_4>;
860template class SphereThetaPhi<r_8>;
861template class SphereThetaPhi<r_4>;
862template class SphereThetaPhi< complex<r_4> >;
863template class SphereThetaPhi< complex<r_8> >;
864}
865#endif
Note: See TracBrowser for help on using the repository browser.