[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] | 11 | namespace SOPHYA {
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 |
|
---|
[764] | 15 | template <class T>
|
---|
| 16 | class FIO_SphereThetaPhi;
|
---|
| 17 |
|
---|
[980] | 18 | template<class T>
|
---|
| 19 | class FITS_SphereThetaPhi;
|
---|
[764] | 20 |
|
---|
[980] | 21 |
|
---|
[764] | 22 | // ***************** Class SphereThetaPhi *****************************
|
---|
| 23 | template <class T>
|
---|
| 24 | class SphereThetaPhi : public SphericalMap<T>
|
---|
| 25 | {
|
---|
| 26 |
|
---|
| 27 | public :
|
---|
| 28 |
|
---|
[2985] | 29 | //! return the size index value corresponding to resolution \b res (in radian)
|
---|
[2973] | 30 | static 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
|
---|
| 33 | static inline double SizeIndexToResol(int_4 m)
|
---|
| 34 | { return (M_PI/(2.*(double)m)); }
|
---|
[2973] | 35 |
|
---|
[764] | 36 | SphereThetaPhi();
|
---|
| 37 | SphereThetaPhi(int_4 m);
|
---|
[908] | 38 | SphereThetaPhi(const SphereThetaPhi<T>& s, bool share);
|
---|
| 39 | SphereThetaPhi(const SphereThetaPhi<T>& s);
|
---|
[764] | 40 | virtual ~SphereThetaPhi();
|
---|
| 41 |
|
---|
[908] | 42 | // Temporaire?
|
---|
| 43 | inline 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] | 52 | inline 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 */
|
---|
| 63 | virtual int_4 NbPixels() const;
|
---|
| 64 |
|
---|
| 65 | /* retourne la valeur du pixel d'indice k */
|
---|
| 66 | virtual T& PixVal(int_4 k);
|
---|
| 67 | virtual T const& PixVal(int_4 k) const;
|
---|
| 68 |
|
---|
| 69 | /* Return true if teta,phi in map */
|
---|
| 70 | virtual 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). */
|
---|
| 73 | virtual int_4 PixIndexSph(double theta, double phi) const;
|
---|
| 74 |
|
---|
| 75 | /* retourne les coordonnees Spheriques du centre du pixel d'indice k */
|
---|
| 76 | virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const;
|
---|
| 77 |
|
---|
[2960] | 78 | /* Setting pixel values to a constant */
|
---|
[764] | 79 | virtual T SetPixels(T v);
|
---|
| 80 |
|
---|
| 81 | /* retourne/fixe l'angle Solide de Pixel (steradians) */
|
---|
| 82 | virtual 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] | 86 | inline virtual int_4 SizeIndex() const { return( NTheta_); }
|
---|
| 87 |
|
---|
| 88 | /* Acces to the DataBlock */
|
---|
[2960] | 89 | //! Acces to the pixel data NDataBlock<T> object
|
---|
[764] | 90 | inline NDataBlock<T>& DataBlock() {return pixels_;}
|
---|
[2960] | 91 | //! Acces to the pixel data NDataBlock<T> object (const version)
|
---|
[764] | 92 | inline const NDataBlock<T>& DataBlock() const {return pixels_;}
|
---|
| 93 |
|
---|
| 94 | // ------------- Specific methods ----------------------
|
---|
| 95 |
|
---|
| 96 | virtual void Resize(int_4 m);
|
---|
| 97 |
|
---|
[2290] | 98 | inline 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 */
|
---|
| 102 | virtual 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] | 106 | uint_4 NbThetaSlices() const;
|
---|
| 107 |
|
---|
| 108 | /* Nombre de pixels en phi de la tranche d'indice kt */
|
---|
| 109 | int_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] | 113 | void 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] | 117 | void 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 */
|
---|
| 121 | int_4 Index(int_4 kt, int_4 jp) const;
|
---|
| 122 |
|
---|
| 123 | /* Indice kt de la tranche et indice jp du pixel d'indice k */
|
---|
| 124 | void ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp);
|
---|
| 125 |
|
---|
| 126 | void Pixelize(int_4);
|
---|
| 127 |
|
---|
[2968] | 128 | virtual r_8 ThetaOfSlice(int_4 index) const;
|
---|
[2973] | 129 | virtual int_4 GetSymThetaSliceIndex(int_4 idx) const;
|
---|
| 130 | virtual bool HasSymThetaSlice() const;
|
---|
| 131 |
|
---|
[840] | 132 | virtual void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const;
|
---|
| 133 | virtual void GetThetaSlice(int_4 index, r_8& theta, r_8& phi0,TVector<int_4>& pixelIndices, TVector<T>& value) const ;
|
---|
[2990] | 134 | virtual T* GetThetaSliceDataPtr(int_4 sliceIndex);
|
---|
[764] | 135 |
|
---|
| 136 |
|
---|
[2973] | 137 | //! ASCII dump (print) of the pixel map on stream \b os
|
---|
[764] | 138 | void print(ostream& os) const;
|
---|
[2973] | 139 | //! ASCII dump (print) of the pixel map
|
---|
| 140 | inline void Print(ostream& os) const { print(os); }
|
---|
| 141 | //! ASCII dump (print) of the pixel map on cout
|
---|
| 142 | inline void Print() const { print(cout); }
|
---|
[764] | 143 |
|
---|
[1419] | 144 |
|
---|
| 145 |
|
---|
| 146 | // Operations diverses = , +=, ...
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a);
|
---|
| 150 | inline SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a)
|
---|
| 151 | {return Set(a);}
|
---|
| 152 |
|
---|
| 153 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
| 154 |
|
---|
| 155 | //! Fill SphereThetaPhi with all elements equal to \b x
|
---|
| 156 | virtual SphereThetaPhi<T>& SetT(T a);
|
---|
| 157 | inline SphereThetaPhi<T>& operator = (T a) {return SetT(a);}
|
---|
| 158 |
|
---|
| 159 | //! Add \b x to all elements
|
---|
| 160 | virtual SphereThetaPhi<T>& Add(T a);
|
---|
| 161 | inline SphereThetaPhi<T>& operator += (T x) { return Add(x); }
|
---|
| 162 | //! Substract \b x to all elements
|
---|
[1624] | 163 | virtual SphereThetaPhi<T>& Sub(T a,bool fginv=false);
|
---|
[1419] | 164 | inline SphereThetaPhi<T>& operator -= (T x) { return Sub(x); }
|
---|
| 165 | //! Multiply all elements by \b x
|
---|
| 166 | virtual SphereThetaPhi<T>& Mul(T a);
|
---|
| 167 | inline SphereThetaPhi<T>& operator *= (T x) { return Mul(x); }
|
---|
| 168 | //! Divide all elements by \b x
|
---|
| 169 | virtual SphereThetaPhi<T>& Div(T a);
|
---|
| 170 | inline SphereThetaPhi<T>& operator /= (T x) { return Div(x); }
|
---|
| 171 |
|
---|
| 172 | // A += -= (ajoute, soustrait element par element les deux spheres )
|
---|
| 173 | //! Operator SphereThetaPhi += SphereThetaPhi
|
---|
| 174 | virtual SphereThetaPhi<T>& AddElt(const SphereThetaPhi<T>& a);
|
---|
| 175 | inline SphereThetaPhi<T>& operator += (const SphereThetaPhi<T>& a) { return AddElt(a); }
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | virtual SphereThetaPhi<T>& SubElt(const SphereThetaPhi<T>& a);
|
---|
| 180 | //! Operator SphereThetaPhi -= SphereThetaPhi
|
---|
| 181 | inline SphereThetaPhi<T>& operator -= (const SphereThetaPhi<T>& a) { return SubElt(a); }
|
---|
| 182 | // Multiplication, division element par element les deux SphereThetaPhi
|
---|
| 183 | virtual SphereThetaPhi<T>& MulElt(const SphereThetaPhi<T>& a);
|
---|
| 184 | inline SphereThetaPhi<T>& operator *= (const SphereThetaPhi<T>& a) { return MulElt(a); }
|
---|
[1551] | 185 | virtual SphereThetaPhi<T>& DivElt(const SphereThetaPhi<T>& a);
|
---|
| 186 | inline SphereThetaPhi<T>& operator /= (const SphereThetaPhi<T>& a) { return DivElt(a); }
|
---|
[1419] | 187 |
|
---|
| 188 |
|
---|
[1196] | 189 | void CloneOrShare(const SphereThetaPhi<T>& a);
|
---|
[1419] | 190 | void Share(const SphereThetaPhi<T>& a);
|
---|
[1196] | 191 |
|
---|
| 192 | SphereThetaPhi<T>& CopyElt(const SphereThetaPhi<T>& a);
|
---|
| 193 |
|
---|
[3174] | 194 | //! assign a new object Id (or DataRef Id) - useful for PPF write operations
|
---|
| 195 | // Reza 02/2007 : Est-il suffisant de faire l'operation sur pixels_ ?
|
---|
| 196 | inline void RenewObjId() { pixels_.RenewObjId(); }
|
---|
[908] | 197 |
|
---|
[1419] | 198 |
|
---|
[1196] | 199 | // friend declaration for classes which handle persistence and FITS IO
|
---|
| 200 | friend class FIO_SphereThetaPhi<T>;
|
---|
| 201 | friend class FITS_SphereThetaPhi<T>;
|
---|
[908] | 202 |
|
---|
[1196] | 203 | protected :
|
---|
[764] | 204 |
|
---|
| 205 | // ------------- méthodes internes ----------------------
|
---|
| 206 | void InitNul();
|
---|
[840] | 207 | inline void setParameters( int nbThetaIndex, int nbpix, double omega)
|
---|
[764] | 208 | {
|
---|
| 209 | NPix_= nbpix;
|
---|
| 210 | Omega_= omega;
|
---|
| 211 | NTheta_= nbThetaIndex;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | // ------------- variables internes ---------------------
|
---|
| 215 | int_4 NTheta_; // nombre de tranches en theta, pour une demi-sphere
|
---|
| 216 | int_4 NPix_; // nombre total de pixels
|
---|
| 217 | double Omega_; // angle solide constant pour chaque pixel
|
---|
| 218 | NDataBlock<int_4> NPhi_; // tableau donnant, pour chaque bande en theta,
|
---|
| 219 | //le nombre de pixels selon phi
|
---|
[2198] | 220 | NDataBlock<int_4> TNphi_; // tableau donnant ke nombre de pixels cumule,
|
---|
| 221 | // jusqu'au debut de chaque tranche
|
---|
[764] | 222 | NDataBlock<r_8> Theta_;
|
---|
| 223 | NDataBlock<T> pixels_;
|
---|
| 224 | };
|
---|
| 225 |
|
---|
[1419] | 226 | ////////////////////////////////////////////////////////////////
|
---|
| 227 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
[1423] | 228 | /*! \ingroup SkyMap \fn operator+(const SphereThetaPhi<T>&,T)
|
---|
[1419] | 229 | \brief Operator SphereThetaPhi = SphereThetaPhi + constant */
|
---|
| 230 | template <class T> inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a, T b)
|
---|
| 231 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 232 | result.Add(b); return result;}
|
---|
[1423] | 233 | /*! \ingroup SkyMap \fn operator+(T,const SphereThetaPhi<T>&)
|
---|
[1419] | 234 | \brief Operator SphereThetaPhi = constant + SphereThetaPhi */
|
---|
| 235 | template <class T> inline SphereThetaPhi<T> operator + (T b,const SphereThetaPhi<T>& a)
|
---|
| 236 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 237 | result.Add(b); return result;}
|
---|
[764] | 238 |
|
---|
| 239 |
|
---|
[1419] | 240 | /*! \ingroup SphereThetaPhi\fn operator-(const SphereThetaPhi<T>&,T)
|
---|
| 241 | \brief Operator SphereThetaPhi = SphereThetaPhi - constant */
|
---|
| 242 | template <class T> inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a, T b)
|
---|
| 243 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 244 | result.Sub(b); return result;}
|
---|
| 245 |
|
---|
| 246 | /*! \ingroup \fn operator-(T,const SphereThetaPhi<T>&)
|
---|
| 247 | \brief Operator SphereThetaPhi = constant - SphereThetaPhi */
|
---|
| 248 | template <class T> inline SphereThetaPhi<T> operator - (T b,const SphereThetaPhi<T>& a)
|
---|
| 249 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 250 | result.Sub(b,true); return result;}
|
---|
| 251 |
|
---|
[1423] | 252 | /*! \ingroup SkyMap \fn operator*(const SphereThetaPhi<T>&,T)
|
---|
[1419] | 253 | \brief Operator SphereThetaPhi = SphereThetaPhi * constant */
|
---|
| 254 | template <class T> inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a, T b)
|
---|
| 255 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 256 | result.Mul(b); return result;}
|
---|
| 257 |
|
---|
[1423] | 258 | /*! \ingroup SkyMap \fn operator*(T,const SphereThetaPhi<T>&)
|
---|
[1419] | 259 | \brief Operator SphereThetaPhi = constant * SphereThetaPhi */
|
---|
| 260 | template <class T> inline SphereThetaPhi<T> operator * (T b,const SphereThetaPhi<T>& a)
|
---|
| 261 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 262 | result.Mul(b); return result;}
|
---|
| 263 |
|
---|
[1423] | 264 | /*! \ingroup SkyMap \fn operator/(const SphereThetaPhi<T>&,T)
|
---|
[1419] | 265 | \brief Operator SphereThetaPhi = SphereThetaPhi / constant */
|
---|
| 266 | template <class T> inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a, T b)
|
---|
| 267 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 268 | result.Div(b); return result;}
|
---|
| 269 |
|
---|
[1423] | 270 | /*! \ingroup SkyMap \fn operator/(T,const SphereThetaPhi<T>&)
|
---|
[1419] | 271 | \brief Operator SphereThetaPhi = constant / SphereThetaPhi */
|
---|
| 272 | template <class T> inline SphereThetaPhi<T> operator / (T b, const SphereThetaPhi<T>& a)
|
---|
| 273 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 274 | result.Div(b, true); return result;}
|
---|
| 275 |
|
---|
| 276 | ////////////////////////////////////////////////////////////////
|
---|
| 277 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 278 |
|
---|
[1423] | 279 | /*! \ingroup SkyMap \fn operator+(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
[1419] | 280 | \brief Operator SphereThetaPhi = SphereThetaPhi + SphereThetaPhi */
|
---|
| 281 | template <class T>
|
---|
| 282 | inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 283 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
| 284 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
| 285 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
| 286 | return result; }
|
---|
| 287 |
|
---|
[1423] | 288 | /*! \ingroup SkyMap \fn operator-(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
[1419] | 289 | \brief Operator SphereThetaPhi = SphereThetaPhi - SphereThetaPhi */
|
---|
| 290 | template <class T>
|
---|
| 291 | inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 292 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
[2960] | 293 | result.CloneOrShare(a); result.SubElt(b);
|
---|
[1419] | 294 | return result; }
|
---|
| 295 |
|
---|
[1551] | 296 | ////////////////////////////////////////////////////////////////
|
---|
| 297 | // Surcharge d'operateurs C = A (*,/) B
|
---|
[1419] | 298 |
|
---|
[1551] | 299 | /*! \ingroup SkyMap \fn operator*(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
| 300 | \brief Operator SphereThetaPhi = SphereThetaPhi * SphereThetaPhi (pixel by pixel multiply)*/
|
---|
| 301 | template <class T>
|
---|
| 302 | inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 303 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
| 304 | if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
|
---|
| 305 | else { result.CloneOrShare(a); result.MulElt(b); }
|
---|
| 306 | return result; }
|
---|
| 307 |
|
---|
| 308 | /*! \ingroup SkyMap \fn operator/(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
| 309 | \brief Operator SphereThetaPhi = SphereThetaPhi / SphereThetaPhi (pixel by pixel divide) */
|
---|
| 310 | template <class T>
|
---|
| 311 | inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 312 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
[2433] | 313 | result.CloneOrShare(a); result.DivElt(b);
|
---|
[1551] | 314 | return result; }
|
---|
| 315 |
|
---|
| 316 |
|
---|
[3836] | 317 | //--------- extern template declarations (if needed) -----------
|
---|
| 318 | #if defined ( NEED_EXT_DECL_TEMP ) && !defined( SPHERETHETAPHI_CC_BFILE )
|
---|
| 319 | extern template class SphereThetaPhi<int_4>;
|
---|
| 320 | extern template class SphereThetaPhi<r_8>;
|
---|
| 321 | extern template class SphereThetaPhi<r_4>;
|
---|
| 322 | extern template class SphereThetaPhi< complex<r_4> >;
|
---|
| 323 | extern template class SphereThetaPhi< complex<r_8> >;
|
---|
| 324 | #endif // Fin de if defined ( NEED_EXT_DECL_TEMP )
|
---|
| 325 |
|
---|
[840] | 326 | } // Fin du namespace
|
---|
[764] | 327 |
|
---|
| 328 | #endif
|
---|