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

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

petites corrections + doc(xygen) / Protection Resize() ds SphereHEALPix et SphereThetaPhi - Reza 1/06/2006

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