[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 | /*! sphere splitted with respect to theta, phi : each hemisphere is
|
---|
| 24 | splitted into (m-1) parallels (equator does not enter into account).
|
---|
| 25 | This operation defines m slices, each of which is splitted into
|
---|
| 26 | equidistant meridians. This splitting is realized in such a way that
|
---|
| 27 | all pixels have the same area and are as square as possible.
|
---|
| 28 |
|
---|
| 29 | One begins with the hemisphere with positive z, starting from the pole
|
---|
| 30 | toward the equator. The first pixel is the polar cap ; it is circular
|
---|
| 31 | and centered on theta=0.
|
---|
| 32 | */
|
---|
| 33 | template <class T>
|
---|
| 34 | class SphereThetaPhi : public SphericalMap<T>
|
---|
| 35 | {
|
---|
| 36 |
|
---|
| 37 | public :
|
---|
| 38 |
|
---|
| 39 | SphereThetaPhi();
|
---|
| 40 | /*! m is the number of slices in theta on an hemisphere (the polar cap
|
---|
| 41 | forms the first slice).
|
---|
| 42 | pet is a dummy parameter at the moment.
|
---|
| 43 | */
|
---|
| 44 | SphereThetaPhi(int_4 m);
|
---|
[908] | 45 | SphereThetaPhi(const SphereThetaPhi<T>& s, bool share);
|
---|
| 46 | SphereThetaPhi(const SphereThetaPhi<T>& s);
|
---|
[764] | 47 | virtual ~SphereThetaPhi();
|
---|
| 48 |
|
---|
[908] | 49 | // Temporaire?
|
---|
| 50 | inline virtual bool IsTemp(void) const {
|
---|
| 51 |
|
---|
| 52 | if ( NPhi_.IsTemp() != pixels_.IsTemp() ||
|
---|
| 53 | TNphi_.IsTemp() != pixels_.IsTemp()||
|
---|
| 54 | Theta_.IsTemp() != pixels_.IsTemp() )
|
---|
| 55 | throw PException(" l'etat 'temporaire' de la spherethetaphi est incoherent");
|
---|
| 56 | return pixels_.IsTemp();
|
---|
| 57 | }
|
---|
[764] | 58 | /*! Setting blockdata to temporary (see ndatablock documentation) */
|
---|
[908] | 59 | inline virtual void SetTemp(bool temp=false) const
|
---|
| 60 | {
|
---|
| 61 | NPhi_.SetTemp(temp);
|
---|
| 62 | TNphi_.SetTemp(temp);
|
---|
| 63 | Theta_.SetTemp(temp);
|
---|
| 64 | pixels_.SetTemp(temp);
|
---|
| 65 | };
|
---|
[764] | 66 |
|
---|
| 67 | // ------------ Definition of PixelMap abstract methods -
|
---|
| 68 |
|
---|
| 69 | /* retourne le nombre de pixels */
|
---|
| 70 | /*! Return total number of pixels */
|
---|
| 71 | virtual int_4 NbPixels() const;
|
---|
| 72 |
|
---|
| 73 | /* retourne la valeur du pixel d'indice k */
|
---|
| 74 | /*! Return value of pixel with index k */
|
---|
| 75 | virtual T& PixVal(int_4 k);
|
---|
| 76 | virtual T const& PixVal(int_4 k) const;
|
---|
| 77 |
|
---|
| 78 | /* Return true if teta,phi in map */
|
---|
| 79 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
| 80 | /* retourne l'indice du pixel a (theta,phi) */
|
---|
| 81 | /* Return index of the pixel corresponding to direction (theta, phi). */
|
---|
| 82 | virtual int_4 PixIndexSph(double theta, double phi) const;
|
---|
| 83 |
|
---|
| 84 | /* retourne les coordonnees Spheriques du centre du pixel d'indice k */
|
---|
| 85 | /*! Return (theta,phi) coordinates of middle of pixel with index k */
|
---|
| 86 | virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const;
|
---|
| 87 |
|
---|
| 88 | /*! Setting pixel values to a constant */
|
---|
| 89 | virtual T SetPixels(T v);
|
---|
| 90 |
|
---|
| 91 | /* retourne/fixe l'angle Solide de Pixel (steradians) */
|
---|
| 92 | /*! Pixel Solid angle (steradians)
|
---|
| 93 |
|
---|
| 94 | All the pixels have the same solid angle. The dummy argument is
|
---|
| 95 | for compatibility with eventual pixelizations which would not
|
---|
| 96 | fulfil this requirement.
|
---|
| 97 | */
|
---|
| 98 | virtual double PixSolAngle(int_4 dummy=0) const;
|
---|
| 99 |
|
---|
| 100 | /* retourne/fixe la valeur du parametre de decoupage m */
|
---|
| 101 | inline virtual int_4 SizeIndex() const { return( NTheta_); }
|
---|
| 102 |
|
---|
| 103 | /* Acces to the DataBlock */
|
---|
| 104 | inline NDataBlock<T>& DataBlock() {return pixels_;}
|
---|
| 105 | inline const NDataBlock<T>& DataBlock() const {return pixels_;}
|
---|
| 106 |
|
---|
| 107 | // ------------- Specific methods ----------------------
|
---|
| 108 |
|
---|
| 109 | /*! re-pixelize the sphere */
|
---|
| 110 | virtual void Resize(int_4 m);
|
---|
| 111 |
|
---|
| 112 | inline virtual char* TypeOfMap() const {return "TETAFI";};
|
---|
| 113 |
|
---|
| 114 | /* Valeurs de theta des paralleles et phi des meridiens limitant le pixel d'indice k */
|
---|
| 115 | /* Return values of theta,phi which limit the pixel with index k */
|
---|
| 116 | virtual void Limits(int_4 k,double& th1,double& th2,double& phi1,double& phi2);
|
---|
| 117 |
|
---|
| 118 | /* Nombre de tranches en theta */
|
---|
| 119 | /*! Return number of theta-slices on the sphere */
|
---|
| 120 | uint_4 NbThetaSlices() const;
|
---|
| 121 |
|
---|
| 122 | /* Nombre de pixels en phi de la tranche d'indice kt */
|
---|
| 123 | int_4 NPhi(int_4 kt) const;
|
---|
| 124 |
|
---|
| 125 | /* Renvoie dans t1,t2 les valeurs respectives de theta min et theta max */
|
---|
| 126 | /* de la tranche d'indice kt */
|
---|
| 127 | /*! Return theta values which limit the slice kt */
|
---|
| 128 | void Theta(int_4 kt, double& t1, double& t2);
|
---|
| 129 |
|
---|
| 130 | /* Renvoie dans p1,p2 les valeurs phimin et phimax du pixel d'indice jp */
|
---|
| 131 | /* dans la tranche d'indice kt */
|
---|
| 132 | /*! Return values of phi which limit the jp-th pixel of the kt-th slice */
|
---|
| 133 | void Phi(int_4 kt, int_4 jp, double& p1, double& p2);
|
---|
| 134 |
|
---|
| 135 | /* Renvoie l'indice k du pixel d'indice jp dans la tranche d'indice kt */
|
---|
| 136 | /*! Return pixel index with sequence index jp in the slice kt */
|
---|
| 137 | int_4 Index(int_4 kt, int_4 jp) const;
|
---|
| 138 |
|
---|
| 139 | /* Indice kt de la tranche et indice jp du pixel d'indice k */
|
---|
| 140 | /*! Return indices kt (theta) and jp (phi) of pixel with index k */
|
---|
| 141 | void ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp);
|
---|
| 142 |
|
---|
| 143 | /*! achieve the splitting into pixels (m has the same signification
|
---|
| 144 | as for the constructor)
|
---|
| 145 |
|
---|
| 146 | Each theta-slice of the north hemisphere will be spitted starting f
|
---|
| 147 | from phi=0 ...
|
---|
| 148 |
|
---|
| 149 | South hemisphere is scanned in the same direction according to phi
|
---|
| 150 | and from equator to the pole (the pixel following the last one of
|
---|
| 151 | the slice closest to the equator with z>0, is the pixel with lowest
|
---|
| 152 | phi of the slice closest of the equator with z<0).
|
---|
| 153 | */
|
---|
| 154 | void Pixelize(int_4);
|
---|
| 155 |
|
---|
| 156 | /*! For a theta-slice with index 'index', return :
|
---|
| 157 |
|
---|
| 158 | the corresponding "theta"
|
---|
| 159 |
|
---|
| 160 | a vector containing the phi's of the pixels of the slice
|
---|
| 161 |
|
---|
| 162 | a vector containing the corresponding values of pixels
|
---|
| 163 | */
|
---|
[840] | 164 | virtual void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const;
|
---|
[764] | 165 |
|
---|
| 166 | /*! For a theta-slice with index 'index', return :
|
---|
| 167 |
|
---|
| 168 | the corresponding "theta"
|
---|
| 169 |
|
---|
| 170 | the corresponding "phi" for first pixel of the slice
|
---|
| 171 |
|
---|
| 172 | a vector containing indices of the pixels of the slice
|
---|
| 173 |
|
---|
| 174 | (equally distributed in phi)
|
---|
| 175 |
|
---|
| 176 | a vector containing the corresponding values of pixels
|
---|
| 177 | */
|
---|
[840] | 178 | virtual void GetThetaSlice(int_4 index, r_8& theta, r_8& phi0,TVector<int_4>& pixelIndices, TVector<T>& value) const ;
|
---|
[764] | 179 |
|
---|
| 180 |
|
---|
| 181 | /* impression */
|
---|
| 182 | void print(ostream& os) const;
|
---|
| 183 |
|
---|
[1419] | 184 |
|
---|
| 185 |
|
---|
| 186 | // Operations diverses = , +=, ...
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | SphereThetaPhi<T>& Set(const SphereThetaPhi<T>& a);
|
---|
| 190 | inline SphereThetaPhi<T>& operator = (const SphereThetaPhi<T>& a)
|
---|
| 191 | {return Set(a);}
|
---|
| 192 |
|
---|
| 193 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
| 194 |
|
---|
| 195 | //! Fill SphereThetaPhi with all elements equal to \b x
|
---|
| 196 | virtual SphereThetaPhi<T>& SetT(T a);
|
---|
| 197 | inline SphereThetaPhi<T>& operator = (T a) {return SetT(a);}
|
---|
| 198 |
|
---|
| 199 | //! Add \b x to all elements
|
---|
| 200 | virtual SphereThetaPhi<T>& Add(T a);
|
---|
| 201 | inline SphereThetaPhi<T>& operator += (T x) { return Add(x); }
|
---|
| 202 | //! Substract \b x to all elements
|
---|
[1624] | 203 | virtual SphereThetaPhi<T>& Sub(T a,bool fginv=false);
|
---|
[1419] | 204 | inline SphereThetaPhi<T>& operator -= (T x) { return Sub(x); }
|
---|
| 205 | //! Multiply all elements by \b x
|
---|
| 206 | virtual SphereThetaPhi<T>& Mul(T a);
|
---|
| 207 | inline SphereThetaPhi<T>& operator *= (T x) { return Mul(x); }
|
---|
| 208 | //! Divide all elements by \b x
|
---|
| 209 | virtual SphereThetaPhi<T>& Div(T a);
|
---|
| 210 | inline SphereThetaPhi<T>& operator /= (T x) { return Div(x); }
|
---|
| 211 |
|
---|
| 212 | // A += -= (ajoute, soustrait element par element les deux spheres )
|
---|
| 213 | //! Operator SphereThetaPhi += SphereThetaPhi
|
---|
| 214 | virtual SphereThetaPhi<T>& AddElt(const SphereThetaPhi<T>& a);
|
---|
| 215 | inline SphereThetaPhi<T>& operator += (const SphereThetaPhi<T>& a) { return AddElt(a); }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | virtual SphereThetaPhi<T>& SubElt(const SphereThetaPhi<T>& a);
|
---|
| 220 | //! Operator SphereThetaPhi -= SphereThetaPhi
|
---|
| 221 | inline SphereThetaPhi<T>& operator -= (const SphereThetaPhi<T>& a) { return SubElt(a); }
|
---|
| 222 | // Multiplication, division element par element les deux SphereThetaPhi
|
---|
| 223 | virtual SphereThetaPhi<T>& MulElt(const SphereThetaPhi<T>& a);
|
---|
| 224 | inline SphereThetaPhi<T>& operator *= (const SphereThetaPhi<T>& a) { return MulElt(a); }
|
---|
[1551] | 225 | virtual SphereThetaPhi<T>& DivElt(const SphereThetaPhi<T>& a);
|
---|
| 226 | inline SphereThetaPhi<T>& operator /= (const SphereThetaPhi<T>& a) { return DivElt(a); }
|
---|
[1419] | 227 |
|
---|
| 228 |
|
---|
[1196] | 229 | void CloneOrShare(const SphereThetaPhi<T>& a);
|
---|
[1419] | 230 | void Share(const SphereThetaPhi<T>& a);
|
---|
[1196] | 231 |
|
---|
| 232 | SphereThetaPhi<T>& CopyElt(const SphereThetaPhi<T>& a);
|
---|
| 233 |
|
---|
[908] | 234 |
|
---|
[1419] | 235 |
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 |
|
---|
[1196] | 239 | // friend declaration for classes which handle persistence and FITS IO
|
---|
| 240 | friend class FIO_SphereThetaPhi<T>;
|
---|
| 241 | friend class FITS_SphereThetaPhi<T>;
|
---|
[908] | 242 |
|
---|
[1196] | 243 | protected :
|
---|
[764] | 244 |
|
---|
| 245 | // ------------- méthodes internes ----------------------
|
---|
| 246 | void InitNul();
|
---|
[840] | 247 | inline void setParameters( int nbThetaIndex, int nbpix, double omega)
|
---|
[764] | 248 | {
|
---|
| 249 | NPix_= nbpix;
|
---|
| 250 | Omega_= omega;
|
---|
| 251 | NTheta_= nbThetaIndex;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | // ------------- variables internes ---------------------
|
---|
| 255 | int_4 NTheta_; // nombre de tranches en theta, pour une demi-sphere
|
---|
| 256 | int_4 NPix_; // nombre total de pixels
|
---|
| 257 | double Omega_; // angle solide constant pour chaque pixel
|
---|
| 258 | NDataBlock<int_4> NPhi_; // tableau donnant, pour chaque bande en theta,
|
---|
| 259 | //le nombre de pixels selon phi
|
---|
| 260 | NDataBlock<int_4> TNphi_;
|
---|
| 261 | NDataBlock<r_8> Theta_;
|
---|
| 262 | NDataBlock<T> pixels_;
|
---|
| 263 | };
|
---|
| 264 |
|
---|
[1419] | 265 | ////////////////////////////////////////////////////////////////
|
---|
| 266 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
[1423] | 267 | /*! \ingroup SkyMap \fn operator+(const SphereThetaPhi<T>&,T)
|
---|
[1419] | 268 | \brief Operator SphereThetaPhi = SphereThetaPhi + constant */
|
---|
| 269 | template <class T> inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a, T b)
|
---|
| 270 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 271 | result.Add(b); return result;}
|
---|
[1423] | 272 | /*! \ingroup SkyMap \fn operator+(T,const SphereThetaPhi<T>&)
|
---|
[1419] | 273 | \brief Operator SphereThetaPhi = constant + SphereThetaPhi */
|
---|
| 274 | template <class T> inline SphereThetaPhi<T> operator + (T b,const SphereThetaPhi<T>& a)
|
---|
| 275 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 276 | result.Add(b); return result;}
|
---|
[764] | 277 |
|
---|
| 278 |
|
---|
[1419] | 279 | /*! \ingroup SphereThetaPhi\fn operator-(const SphereThetaPhi<T>&,T)
|
---|
| 280 | \brief Operator SphereThetaPhi = SphereThetaPhi - constant */
|
---|
| 281 | template <class T> inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a, T b)
|
---|
| 282 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 283 | result.Sub(b); return result;}
|
---|
| 284 |
|
---|
| 285 | /*! \ingroup \fn operator-(T,const SphereThetaPhi<T>&)
|
---|
| 286 | \brief Operator SphereThetaPhi = constant - SphereThetaPhi */
|
---|
| 287 | template <class T> inline SphereThetaPhi<T> operator - (T b,const SphereThetaPhi<T>& a)
|
---|
| 288 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 289 | result.Sub(b,true); return result;}
|
---|
| 290 |
|
---|
[1423] | 291 | /*! \ingroup SkyMap \fn operator*(const SphereThetaPhi<T>&,T)
|
---|
[1419] | 292 | \brief Operator SphereThetaPhi = SphereThetaPhi * constant */
|
---|
| 293 | template <class T> inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a, T b)
|
---|
| 294 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 295 | result.Mul(b); return result;}
|
---|
| 296 |
|
---|
[1423] | 297 | /*! \ingroup SkyMap \fn operator*(T,const SphereThetaPhi<T>&)
|
---|
[1419] | 298 | \brief Operator SphereThetaPhi = constant * SphereThetaPhi */
|
---|
| 299 | template <class T> inline SphereThetaPhi<T> operator * (T b,const SphereThetaPhi<T>& a)
|
---|
| 300 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 301 | result.Mul(b); return result;}
|
---|
| 302 |
|
---|
[1423] | 303 | /*! \ingroup SkyMap \fn operator/(const SphereThetaPhi<T>&,T)
|
---|
[1419] | 304 | \brief Operator SphereThetaPhi = SphereThetaPhi / constant */
|
---|
| 305 | template <class T> inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a, T b)
|
---|
| 306 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 307 | result.Div(b); return result;}
|
---|
| 308 |
|
---|
[1423] | 309 | /*! \ingroup SkyMap \fn operator/(T,const SphereThetaPhi<T>&)
|
---|
[1419] | 310 | \brief Operator SphereThetaPhi = constant / SphereThetaPhi */
|
---|
| 311 | template <class T> inline SphereThetaPhi<T> operator / (T b, const SphereThetaPhi<T>& a)
|
---|
| 312 | {SphereThetaPhi<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 313 | result.Div(b, true); return result;}
|
---|
| 314 |
|
---|
| 315 | ////////////////////////////////////////////////////////////////
|
---|
| 316 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 317 |
|
---|
[1423] | 318 | /*! \ingroup SkyMap \fn operator+(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
[1419] | 319 | \brief Operator SphereThetaPhi = SphereThetaPhi + SphereThetaPhi */
|
---|
| 320 | template <class T>
|
---|
| 321 | inline SphereThetaPhi<T> operator + (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 322 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
| 323 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
| 324 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
| 325 | return result; }
|
---|
| 326 |
|
---|
[1423] | 327 | /*! \ingroup SkyMap \fn operator-(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
[1419] | 328 | \brief Operator SphereThetaPhi = SphereThetaPhi - SphereThetaPhi */
|
---|
| 329 | template <class T>
|
---|
| 330 | inline SphereThetaPhi<T> operator - (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 331 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
| 332 | if (b.IsTemp()) { result.Share(b); result.SubElt(a, true); }
|
---|
| 333 | else { result.CloneOrShare(a); result.SubElt(b); }
|
---|
| 334 | return result; }
|
---|
| 335 |
|
---|
[1551] | 336 | ////////////////////////////////////////////////////////////////
|
---|
| 337 | // Surcharge d'operateurs C = A (*,/) B
|
---|
[1419] | 338 |
|
---|
[1551] | 339 | /*! \ingroup SkyMap \fn operator*(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
| 340 | \brief Operator SphereThetaPhi = SphereThetaPhi * SphereThetaPhi (pixel by pixel multiply)*/
|
---|
| 341 | template <class T>
|
---|
| 342 | inline SphereThetaPhi<T> operator * (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 343 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
| 344 | if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
|
---|
| 345 | else { result.CloneOrShare(a); result.MulElt(b); }
|
---|
| 346 | return result; }
|
---|
| 347 |
|
---|
| 348 | /*! \ingroup SkyMap \fn operator/(const SphereThetaPhi<T>&,const SphereThetaPhi<T>&)
|
---|
| 349 | \brief Operator SphereThetaPhi = SphereThetaPhi / SphereThetaPhi (pixel by pixel divide) */
|
---|
| 350 | template <class T>
|
---|
| 351 | inline SphereThetaPhi<T> operator / (const SphereThetaPhi<T>& a,const SphereThetaPhi<T>& b)
|
---|
| 352 | { SphereThetaPhi<T> result; result.SetTemp(true);
|
---|
| 353 | if (b.IsTemp()) { result.Share(b); result.DivElt(a, true); }
|
---|
| 354 | else { result.CloneOrShare(a); result.DivElt(b); }
|
---|
| 355 | return result; }
|
---|
| 356 |
|
---|
| 357 |
|
---|
[840] | 358 | } // Fin du namespace
|
---|
[764] | 359 |
|
---|
| 360 | #endif
|
---|