source: Sophya/trunk/SophyaLib/SkyMap/spherethetaphi.h@ 2985

Last change on this file since 2985 was 2985, checked in by ansari, 19 years ago

1/ Suite codage HEALPix-NEST , test avec transforme Ylm OK
2/ Petites modifs et corrections diverses (ajout SizeIndex2Resol() par exemple)

Reza 21 Juin 2006

File size: 12.2 KB
RevLine 
[764]1#ifndef SPHERETHETAPHI_SEEN
2#define SPHERETHETAPHI_SEEN
3
4#include "sphericalmap.h"
5#include "ndatablock.h"
6#include "tvector.h"
7
8#include "anydataobj.h"
9#include "ppersist.h"
10
[840]11namespace SOPHYA {
12
13
14
[764]15template <class T>
16class FIO_SphereThetaPhi;
17
[980]18template<class T>
19class FITS_SphereThetaPhi;
[764]20
[980]21
[764]22// ***************** Class SphereThetaPhi *****************************
23template <class T>
24class SphereThetaPhi : public SphericalMap<T>
25{
26
27public :
28
[2985]29//! return the size index value corresponding to resolution \b res (in radian)
[2973]30static inline int_4 ResolToSizeIndex(double res)
[2978]31 { return (int_4)((M_PI/2./res)+0.5); }
[2985]32//! return the pixel resolution (in radian) for the size index \b m
33static inline double SizeIndexToResol(int_4 m)
34 { return (M_PI/(2.*(double)m)); }
[2973]35
[764]36SphereThetaPhi();
37SphereThetaPhi(int_4 m);
[908]38SphereThetaPhi(const SphereThetaPhi<T>& s, bool share);
39SphereThetaPhi(const SphereThetaPhi<T>& s);
[764]40virtual ~SphereThetaPhi();
41
[908]42 // Temporaire?
43inline virtual bool IsTemp(void) const {
44
45 if ( NPhi_.IsTemp() != pixels_.IsTemp() ||
46 TNphi_.IsTemp() != pixels_.IsTemp()||
47 Theta_.IsTemp() != pixels_.IsTemp() )
48 throw PException(" l'etat 'temporaire' de la spherethetaphi est incoherent");
49 return pixels_.IsTemp();
50}
[764]51/*! Setting blockdata to temporary (see ndatablock documentation) */
[908]52inline virtual void SetTemp(bool temp=false) const
53 {
54 NPhi_.SetTemp(temp);
55 TNphi_.SetTemp(temp);
56 Theta_.SetTemp(temp);
57 pixels_.SetTemp(temp);
58 };
[764]59
60// ------------ Definition of PixelMap abstract methods -
61
62/* retourne le nombre de pixels */
63virtual int_4 NbPixels() const;
64
65/* retourne la valeur du pixel d'indice k */
66virtual T& PixVal(int_4 k);
67virtual T const& PixVal(int_4 k) const;
68
69/* Return true if teta,phi in map */
70virtual bool ContainsSph(double theta, double phi) const;
71/* retourne l'indice du pixel a (theta,phi) */
72/* Return index of the pixel corresponding to direction (theta, phi). */
73virtual int_4 PixIndexSph(double theta, double phi) const;
74
75/* retourne les coordonnees Spheriques du centre du pixel d'indice k */
76virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const;
77
[2960]78/* Setting pixel values to a constant */
[764]79virtual T SetPixels(T v);
80
81/* retourne/fixe l'angle Solide de Pixel (steradians) */
82virtual double PixSolAngle(int_4 dummy=0) const;
83
84/* retourne/fixe la valeur du parametre de decoupage m */
[2960]85//! Return the pixelisation parameter (number of slices in a hemisphere)
[764]86inline virtual int_4 SizeIndex() const { return( NTheta_); }
87
88/* Acces to the DataBlock */
[2960]89//! Acces to the pixel data NDataBlock<T> object
[764]90inline NDataBlock<T>& DataBlock() {return pixels_;}
[2960]91//! Acces to the pixel data NDataBlock<T> object (const version)
[764]92inline const NDataBlock<T>& DataBlock() const {return pixels_;}
93
94// ------------- Specific methods ----------------------
95
96virtual void Resize(int_4 m);
97
[2290]98inline virtual string TypeOfMap() const {return string("TETAFI");};
[764]99
100/* Valeurs de theta des paralleles et phi des meridiens limitant le pixel d'indice k */
101/* Return values of theta,phi which limit the pixel with index k */
102virtual void Limits(int_4 k,double& th1,double& th2,double& phi1,double& phi2);
103
104/* Nombre de tranches en theta */
[2960]105/* Return number of theta-slices on the sphere */
[764]106uint_4 NbThetaSlices() const;
107
108/* Nombre de pixels en phi de la tranche d'indice kt */
109int_4 NPhi(int_4 kt) const;
110
111/* Renvoie dans t1,t2 les valeurs respectives de theta min et theta max */
112/* de la tranche d'indice kt */
[2969]113void Theta(int_4 kt, double& t1, double& t2) const;
[764]114
115/* Renvoie dans p1,p2 les valeurs phimin et phimax du pixel d'indice jp */
116/* dans la tranche d'indice kt */
[2969]117void Phi(int_4 kt, int_4 jp, double& p1, double& p2) const;
[764]118
119/* Renvoie l'indice k du pixel d'indice jp dans la tranche d'indice kt */
120/*! Return pixel index with sequence index jp in the slice kt */
121int_4 Index(int_4 kt, int_4 jp) const;
122
123/* Indice kt de la tranche et indice jp du pixel d'indice k */
124void ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp);
125
126void Pixelize(int_4);
127
[2968]128virtual r_8 ThetaOfSlice(int_4 index) const;
[2973]129virtual int_4 GetSymThetaSliceIndex(int_4 idx) const;
130virtual bool HasSymThetaSlice() const;
131
[840]132virtual void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const;
133virtual void GetThetaSlice(int_4 index, r_8& theta, r_8& phi0,TVector<int_4>& pixelIndices, TVector<T>& value) const ;
[764]134
135
[2973]136//! ASCII dump (print) of the pixel map on stream \b os
[764]137void print(ostream& os) const;
[2973]138//! ASCII dump (print) of the pixel map
139inline void Print(ostream& os) const { print(os); }
140//! ASCII dump (print) of the pixel map on cout
141inline void Print() const { print(cout); }
[764]142
[1419]143
144
145// Operations diverses = , +=, ...
146
147
148SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a);
149inline SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a)
150 {return Set(a);}
151
152// A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
153
154 //! Fill SphereThetaPhi with all elements equal to \b x
155virtual SphereThetaPhi<T>& SetT(T a);
156inline SphereThetaPhi<T>& operator = (T a) {return SetT(a);}
157
158//! Add \b x to all elements
159virtual SphereThetaPhi<T>& Add(T a);
160inline SphereThetaPhi<T>& operator += (T x) { return Add(x); }
161//! Substract \b x to all elements
[1624]162virtual SphereThetaPhi<T>& Sub(T a,bool fginv=false);
[1419]163inline SphereThetaPhi<T>& operator -= (T x) { return Sub(x); }
164//! Multiply all elements by \b x
165virtual SphereThetaPhi<T>& Mul(T a);
166inline SphereThetaPhi<T>& operator *= (T x) { return Mul(x); }
167//! Divide all elements by \b x
168virtual SphereThetaPhi<T>& Div(T a);
169inline SphereThetaPhi<T>& operator /= (T x) { return Div(x); }
170
171// A += -= (ajoute, soustrait element par element les deux spheres )
172 //! Operator SphereThetaPhi += SphereThetaPhi
173 virtual SphereThetaPhi<T>& AddElt(const SphereThetaPhi<T>& a);
174 inline SphereThetaPhi<T>& operator += (const SphereThetaPhi<T>& a) { return AddElt(a); }
175
176
177
178 virtual SphereThetaPhi<T>& SubElt(const SphereThetaPhi<T>& a);
179 //! Operator SphereThetaPhi -= SphereThetaPhi
180 inline SphereThetaPhi<T>& operator -= (const SphereThetaPhi<T>& a) { return SubElt(a); }
181// Multiplication, division element par element les deux SphereThetaPhi
182 virtual SphereThetaPhi<T>& MulElt(const SphereThetaPhi<T>& a);
183 inline SphereThetaPhi<T>& operator *= (const SphereThetaPhi<T>& a) { return MulElt(a); }
[1551]184 virtual SphereThetaPhi<T>& DivElt(const SphereThetaPhi<T>& a);
185 inline SphereThetaPhi<T>& operator /= (const SphereThetaPhi<T>& a) { return DivElt(a); }
[1419]186
187
[1196]188 void CloneOrShare(const SphereThetaPhi<T>& a);
[1419]189 void Share(const SphereThetaPhi<T>& a);
[1196]190
191 SphereThetaPhi<T>& CopyElt(const SphereThetaPhi<T>& a);
192
[908]193
[1419]194
195
196
197
[1196]198 // friend declaration for classes which handle persistence and FITS IO
199 friend class FIO_SphereThetaPhi<T>;
200 friend class FITS_SphereThetaPhi<T>;
[908]201
[1196]202protected :
[764]203
204// ------------- méthodes internes ----------------------
205void InitNul();
[840]206inline void setParameters( int nbThetaIndex, int nbpix, double omega)
[764]207 {
208 NPix_= nbpix;
209 Omega_= omega;
210 NTheta_= nbThetaIndex;
211 }
212
213// ------------- variables internes ---------------------
214 int_4 NTheta_; // nombre de tranches en theta, pour une demi-sphere
215 int_4 NPix_; // nombre total de pixels
216 double Omega_; // angle solide constant pour chaque pixel
217 NDataBlock<int_4> NPhi_; // tableau donnant, pour chaque bande en theta,
218 //le nombre de pixels selon phi
[2198]219 NDataBlock<int_4> TNphi_; // tableau donnant ke nombre de pixels cumule,
220 // jusqu'au debut de chaque tranche
[764]221 NDataBlock<r_8> Theta_;
222 NDataBlock<T> pixels_;
223};
224
[1419]225////////////////////////////////////////////////////////////////
226// Surcharge d'operateurs A (+,-,*,/) (T) x
[1423]227/*! \ingroup SkyMap \fn operator+(const SphereThetaPhi<T>&,T)
[1419]228 \brief Operator SphereThetaPhi = SphereThetaPhi + constant */
229template <class T> inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a, T b)
230 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
231 result.Add(b); return result;}
[1423]232/*! \ingroup SkyMap \fn operator+(T,const SphereThetaPhi<T>&)
[1419]233 \brief Operator SphereThetaPhi = constant + SphereThetaPhi */
234template <class T> inline SphereThetaPhi<T> operator + (T b,const SphereThetaPhi<T>& a)
235 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
236 result.Add(b); return result;}
[764]237
238
[1419]239/*! \ingroup SphereThetaPhi\fn operator-(const SphereThetaPhi<T>&,T)
240 \brief Operator SphereThetaPhi = SphereThetaPhi - constant */
241template <class T> inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a, T b)
242 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
243 result.Sub(b); return result;}
244
245/*! \ingroup \fn operator-(T,const SphereThetaPhi<T>&)
246 \brief Operator SphereThetaPhi = constant - SphereThetaPhi */
247template <class T> inline SphereThetaPhi<T> operator - (T b,const SphereThetaPhi<T>& a)
248 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
249 result.Sub(b,true); return result;}
250
[1423]251/*! \ingroup SkyMap \fn operator*(const SphereThetaPhi<T>&,T)
[1419]252 \brief Operator SphereThetaPhi = SphereThetaPhi * constant */
253template <class T> inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a, T b)
254 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
255 result.Mul(b); return result;}
256
[1423]257/*! \ingroup SkyMap \fn operator*(T,const SphereThetaPhi<T>&)
[1419]258 \brief Operator SphereThetaPhi = constant * SphereThetaPhi */
259template <class T> inline SphereThetaPhi<T> operator * (T b,const SphereThetaPhi<T>& a)
260 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
261 result.Mul(b); return result;}
262
[1423]263/*! \ingroup SkyMap \fn operator/(const SphereThetaPhi<T>&,T)
[1419]264 \brief Operator SphereThetaPhi = SphereThetaPhi / constant */
265template <class T> inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a, T b)
266 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
267 result.Div(b); return result;}
268
[1423]269/*! \ingroup SkyMap \fn operator/(T,const SphereThetaPhi<T>&)
[1419]270 \brief Operator SphereThetaPhi = constant / SphereThetaPhi */
271template <class T> inline SphereThetaPhi<T> operator / (T b, const SphereThetaPhi<T>& a)
272 {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
273 result.Div(b, true); return result;}
274
275////////////////////////////////////////////////////////////////
276// Surcharge d'operateurs C = A (+,-) B
277
[1423]278/*! \ingroup SkyMap \fn operator+(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
[1419]279 \brief Operator SphereThetaPhi = SphereThetaPhi + SphereThetaPhi */
280template <class T>
281inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
282 { SphereThetaPhi<T> result; result.SetTemp(true);
283 if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
284 else { result.CloneOrShare(a); result.AddElt(b); }
285 return result; }
286
[1423]287/*! \ingroup SkyMap \fn operator-(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
[1419]288 \brief Operator SphereThetaPhi = SphereThetaPhi - SphereThetaPhi */
289template <class T>
290inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
291 { SphereThetaPhi<T> result; result.SetTemp(true);
[2960]292 result.CloneOrShare(a); result.SubElt(b);
[1419]293 return result; }
294
[1551]295////////////////////////////////////////////////////////////////
296// Surcharge d'operateurs C = A (*,/) B
[1419]297
[1551]298/*! \ingroup SkyMap \fn operator*(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
299 \brief Operator SphereThetaPhi = SphereThetaPhi * SphereThetaPhi (pixel by pixel multiply)*/
300template <class T>
301inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
302 { SphereThetaPhi<T> result; result.SetTemp(true);
303 if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
304 else { result.CloneOrShare(a); result.MulElt(b); }
305 return result; }
306
307/*! \ingroup SkyMap \fn operator/(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
308 \brief Operator SphereThetaPhi = SphereThetaPhi / SphereThetaPhi (pixel by pixel divide) */
309template <class T>
310inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
311 { SphereThetaPhi<T> result; result.SetTemp(true);
[2433]312 result.CloneOrShare(a); result.DivElt(b);
[1551]313 return result; }
314
315
[840]316} // Fin du namespace
[764]317
318#endif
Note: See TracBrowser for help on using the repository browser.