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

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

1/ Nettoyage+commentaires/doxygen ds Vector3d, UnitVector, LongLat,
SphereCoordSys ...
2/ Ajout de la classe angle pour faciliter les conversions rad<>deg<>arcmin
dans le fichier vector3d.h .cc
3/ nettoyage/uniformisation methodes print pour pixelmap, ajout de la
methode PixelMap<T>::Show()
4/ Ajout methodes SphericalMap<T>::HasSymThetaSlice() et
GetSymThetaSliceIndex(int_4 idx) et leurs implementations pour
SphereHEALPix et SphereThetaPhi en vue de l'optimisation du calcul
transforme Ylm
5/ Ajout methode ResolToSizeIndex ds SphereThetaPhi , SphereHEALPix et
SphereECP

Reza , 20 Juin 2006

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