| [843] | 1 | #ifndef SPHEREHEALPIX_SEEN | 
|---|
|  | 2 | #define SPHEREHEALPIX_SEEN | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include "sphericalmap.h" | 
|---|
|  | 5 | #include "tvector.h" | 
|---|
|  | 6 | #include "ndatablock.h" | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include "anydataobj.h" | 
|---|
|  | 9 | #include "ppersist.h" | 
|---|
|  | 10 |  | 
|---|
| [1196] | 11 | #include "HEALPixUtils.h" | 
|---|
| [843] | 12 |  | 
|---|
|  | 13 | namespace SOPHYA { | 
|---|
|  | 14 |  | 
|---|
|  | 15 |  | 
|---|
| [853] | 16 | // ***************** CLASSE SphereHEALPix ***************************** | 
|---|
| [843] | 17 |  | 
|---|
| [1217] | 18 | /*! Class SphereHEALPix */ | 
|---|
| [843] | 19 |  | 
|---|
|  | 20 |  | 
|---|
|  | 21 | template<class T> | 
|---|
| [853] | 22 | class FIO_SphereHEALPix; | 
|---|
| [843] | 23 |  | 
|---|
|  | 24 | template<class T> | 
|---|
| [853] | 25 | class FITS_SphereHEALPix; | 
|---|
| [843] | 26 |  | 
|---|
|  | 27 | template<class T> | 
|---|
| [853] | 28 | class SphereHEALPix : public SphericalMap<T> | 
|---|
| [843] | 29 | { | 
|---|
| [1196] | 30 | public : | 
|---|
|  | 31 | // Static Methods to ease the use of HEALPix index <> angle conversion methods | 
|---|
| [843] | 32 |  | 
|---|
| [1196] | 33 | static inline int_4  nest2ring(int_4 nside,int_4 ipnest) | 
|---|
|  | 34 | { return HEALPix::nest2ring(nside, ipnest); } | 
|---|
|  | 35 | static inline int_4  ring2nest(int_4 nside,int_4 ipring) | 
|---|
|  | 36 | { return HEALPix::ring2nest(nside, ipring); } | 
|---|
|  | 37 | static inline int_4  ang2pix_ring(int_4 nside,double theta,double phi) | 
|---|
|  | 38 | { return HEALPix::ang2pix_ring(nside, theta, phi); } | 
|---|
|  | 39 | static inline int_4  ang2pix_nest(int_4 nside,double theta,double phi) | 
|---|
|  | 40 | { return HEALPix::ang2pix_nest(nside, theta, phi); } | 
|---|
|  | 41 | static inline void   pix2ang_ring(int_4 nside,int_4 ipix,double& theta,double& phi) | 
|---|
|  | 42 | { HEALPix::pix2ang_ring(nside, ipix, theta, phi); } | 
|---|
|  | 43 | static inline void   pix2ang_nest(int_4 nside,int_4 ipix,double& theta,double& phi) | 
|---|
|  | 44 | { HEALPix::pix2ang_nest(nside, ipix, theta, phi); } | 
|---|
| [843] | 45 |  | 
|---|
| [853] | 46 | SphereHEALPix(); | 
|---|
|  | 47 | SphereHEALPix(int_4 m); | 
|---|
| [906] | 48 | SphereHEALPix(const SphereHEALPix<T>& s, bool share); | 
|---|
|  | 49 | SphereHEALPix(const SphereHEALPix<T>& s); | 
|---|
| [853] | 50 | virtual ~SphereHEALPix(); | 
|---|
| [843] | 51 |  | 
|---|
| [908] | 52 | inline virtual bool   IsTemp(void) const { | 
|---|
|  | 53 |  | 
|---|
|  | 54 | if (sliceBeginIndex_.IsTemp() != pixels_.IsTemp() || sliceLenght_.IsTemp() != pixels_.IsTemp() ) | 
|---|
|  | 55 | throw PException(" l'etat 'temporaire' de la spherehealpix est incoherent"); | 
|---|
|  | 56 | return pixels_.IsTemp(); | 
|---|
|  | 57 | } | 
|---|
| [1217] | 58 |  | 
|---|
| [843] | 59 | inline virtual void SetTemp(bool temp=false) const | 
|---|
|  | 60 | { | 
|---|
|  | 61 | pixels_.SetTemp(temp); | 
|---|
|  | 62 | sliceBeginIndex_.SetTemp(temp); | 
|---|
|  | 63 | sliceLenght_.SetTemp(temp); | 
|---|
|  | 64 | }; | 
|---|
|  | 65 | // ------------------ Definition of PixelMap abstract methods | 
|---|
|  | 66 |  | 
|---|
|  | 67 | virtual int_4 NbPixels() const; | 
|---|
|  | 68 |  | 
|---|
|  | 69 | virtual T& PixVal(int_4 k); | 
|---|
|  | 70 | virtual T const& PixVal(int_4 k) const; | 
|---|
|  | 71 |  | 
|---|
|  | 72 | uint_4 NbThetaSlices() const; | 
|---|
|  | 73 | virtual void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const; | 
|---|
|  | 74 | virtual void GetThetaSlice(int_4 sliceIndex,r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const ; | 
|---|
|  | 75 |  | 
|---|
|  | 76 | virtual bool ContainsSph(double theta, double phi) const; | 
|---|
|  | 77 | virtual int_4 PixIndexSph(double theta,double phi) const; | 
|---|
|  | 78 |  | 
|---|
|  | 79 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const; | 
|---|
|  | 80 |  | 
|---|
|  | 81 | virtual T SetPixels(T v); | 
|---|
|  | 82 |  | 
|---|
| [1217] | 83 | /*! Pixel Solid angle  (steradians) | 
|---|
| [843] | 84 |  | 
|---|
|  | 85 | All the pixels have the same solid angle. The dummy argument is | 
|---|
|  | 86 | for compatibility with eventual pixelizations which would not | 
|---|
|  | 87 | fulfil this requirement. | 
|---|
|  | 88 | */ | 
|---|
| [1217] | 89 | inline virtual double PixSolAngle(int_4 dummy=0) const {return omeg_;} | 
|---|
| [843] | 90 |  | 
|---|
|  | 91 | /*  Acces to the DataBlock  */ | 
|---|
|  | 92 | inline       NDataBlock<T>& DataBlock()       {return pixels_;} | 
|---|
|  | 93 | inline const NDataBlock<T>& DataBlock() const {return pixels_;} | 
|---|
|  | 94 |  | 
|---|
|  | 95 | // --------------- Specific methods | 
|---|
|  | 96 |  | 
|---|
| [1217] | 97 | virtual void Resize(int_4 m); | 
|---|
| [843] | 98 |  | 
|---|
| [1217] | 99 | /*! | 
|---|
| [843] | 100 |  | 
|---|
| [1217] | 101 | \return type of storage of the map : RING or NESTED | 
|---|
|  | 102 |  | 
|---|
|  | 103 | at the moment, always RING | 
|---|
| [843] | 104 | */ | 
|---|
| [2290] | 105 | inline virtual string TypeOfMap() const {return string("RING");}; | 
|---|
| [843] | 106 |  | 
|---|
|  | 107 |  | 
|---|
|  | 108 | virtual T& PixValNest(int_4 k); | 
|---|
|  | 109 | virtual T const& PixValNest(int_4 k) const; | 
|---|
|  | 110 |  | 
|---|
|  | 111 | virtual int_4 PixIndexSphNest(double theta,double phi) const; | 
|---|
|  | 112 |  | 
|---|
|  | 113 | virtual void PixThetaPhiNest(int_4 k,double& theta,double& phi) const; | 
|---|
|  | 114 |  | 
|---|
|  | 115 | void Pixelize(int_4); | 
|---|
|  | 116 |  | 
|---|
|  | 117 | int_4 NestToRing(int_4) const; | 
|---|
|  | 118 |  | 
|---|
|  | 119 | int_4 RingToNest(int_4) const; | 
|---|
|  | 120 |  | 
|---|
|  | 121 |  | 
|---|
| [1217] | 122 | /*! \return value of healpix nside */ | 
|---|
| [843] | 123 | inline virtual int_4 SizeIndex() const {return(nSide_);} | 
|---|
|  | 124 |  | 
|---|
|  | 125 | void print(ostream& os) const; | 
|---|
| [892] | 126 |  | 
|---|
|  | 127 |  | 
|---|
|  | 128 |  | 
|---|
| [1419] | 129 |  | 
|---|
|  | 130 |  | 
|---|
|  | 131 |  | 
|---|
|  | 132 |  | 
|---|
|  | 133 |  | 
|---|
|  | 134 | // Operations diverses  = , +=, ... | 
|---|
|  | 135 |  | 
|---|
|  | 136 |  | 
|---|
|  | 137 | SphereHEALPix<T>& Set(const SphereHEALPix<T>& a); | 
|---|
| [892] | 138 | inline  SphereHEALPix<T>& operator = (const SphereHEALPix<T>& a) | 
|---|
| [980] | 139 | {return Set(a);} | 
|---|
| [1195] | 140 |  | 
|---|
| [1419] | 141 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements) | 
|---|
|  | 142 |  | 
|---|
|  | 143 | //! Fill SphereHEALPix with all elements equal to \b x | 
|---|
|  | 144 | virtual SphereHEALPix<T>& SetT(T a); | 
|---|
|  | 145 | inline  SphereHEALPix<T>& operator = (T a) {return SetT(a);} | 
|---|
|  | 146 |  | 
|---|
|  | 147 | //! Add \b x to all elements | 
|---|
|  | 148 | virtual SphereHEALPix<T>& Add(T a); | 
|---|
| [2290] | 149 | inline  SphereHEALPix<T>&  operator += (T x)  { pixels_ += x; return *this; } | 
|---|
| [1419] | 150 | //! Substract \b x to all elements | 
|---|
| [1624] | 151 | virtual SphereHEALPix<T>& Sub(T a,bool fginv=false); | 
|---|
| [2290] | 152 | inline   SphereHEALPix<T>&  operator -= (T x)  { pixels_ -= x; return *this; } | 
|---|
| [1419] | 153 | //! Multiply all elements by \b x | 
|---|
|  | 154 | virtual SphereHEALPix<T>& Mul(T a); | 
|---|
| [2290] | 155 | inline  SphereHEALPix<T>&  operator *= (T x)  {pixels_ *= x; return *this; } | 
|---|
| [1419] | 156 | //! Divide all elements by \b x | 
|---|
|  | 157 | virtual SphereHEALPix<T>& Div(T a); | 
|---|
| [2290] | 158 | inline  SphereHEALPix<T>&  operator /= (T x)  {pixels_ /= x; return *this; } | 
|---|
| [1419] | 159 |  | 
|---|
|  | 160 | // A += -=  (ajoute, soustrait element par element les deux spheres ) | 
|---|
|  | 161 | //! Operator SphereHEALPix += SphereHEALPix | 
|---|
|  | 162 | virtual SphereHEALPix<T>&  AddElt(const SphereHEALPix<T>& a); | 
|---|
|  | 163 | inline  SphereHEALPix<T>&  operator += (const SphereHEALPix<T>& a)  { return AddElt(a); } | 
|---|
|  | 164 |  | 
|---|
|  | 165 |  | 
|---|
|  | 166 |  | 
|---|
|  | 167 | virtual SphereHEALPix<T>&  SubElt(const SphereHEALPix<T>& a); | 
|---|
|  | 168 | //! Operator SphereHEALPix -= SphereHEALPix | 
|---|
|  | 169 | inline  SphereHEALPix<T>&  operator -= (const SphereHEALPix<T>& a)  { return SubElt(a); } | 
|---|
|  | 170 | // Multiplication, division element par element les deux SphereHEALPix | 
|---|
|  | 171 | virtual SphereHEALPix<T>&  MulElt(const SphereHEALPix<T>& a); | 
|---|
|  | 172 | inline  SphereHEALPix<T>&  operator *= (const SphereHEALPix<T>& a)  { return MulElt(a); } | 
|---|
| [1551] | 173 | virtual SphereHEALPix<T>&  DivElt(const SphereHEALPix<T>& a); | 
|---|
|  | 174 | inline  SphereHEALPix<T>&  operator /= (const SphereHEALPix<T>& a)  { return DivElt(a); } | 
|---|
| [1419] | 175 |  | 
|---|
|  | 176 |  | 
|---|
| [1196] | 177 | void CloneOrShare(const SphereHEALPix<T>& a); | 
|---|
| [1419] | 178 | void Share(const SphereHEALPix<T>& a); | 
|---|
| [1196] | 179 | SphereHEALPix<T>& CopyElt(const SphereHEALPix<T>& a); | 
|---|
|  | 180 |  | 
|---|
|  | 181 |  | 
|---|
|  | 182 | // friend declaration for classes which handle persistence and FITS IO | 
|---|
|  | 183 | friend class FIO_SphereHEALPix<T>; | 
|---|
|  | 184 | friend class FITS_SphereHEALPix<T>; | 
|---|
| [1195] | 185 |  | 
|---|
| [1196] | 186 | protected : | 
|---|
| [843] | 187 |  | 
|---|
|  | 188 | // ------------- méthodes internes ---------------------- | 
|---|
|  | 189 | void InitNul(); | 
|---|
|  | 190 | void SetThetaSlices(); | 
|---|
|  | 191 |  | 
|---|
|  | 192 | inline void setParameters(int_4 nside, int_4 nbpixels, double solangle) | 
|---|
|  | 193 | { | 
|---|
|  | 194 | nSide_= nside; | 
|---|
|  | 195 | nPix_= nbpixels; | 
|---|
|  | 196 | omeg_= solangle; | 
|---|
|  | 197 | } | 
|---|
|  | 198 |  | 
|---|
|  | 199 | // ------------- variables internes ----------------------- | 
|---|
|  | 200 |  | 
|---|
|  | 201 | int_4 nSide_; | 
|---|
|  | 202 | int_4 nPix_; | 
|---|
|  | 203 | double omeg_; | 
|---|
|  | 204 |  | 
|---|
|  | 205 | NDataBlock<T> pixels_; | 
|---|
| [1217] | 206 | NDataBlock<int_4> sliceBeginIndex_;         // Rationalisation Mac. D.Y. | 
|---|
| [1145] | 207 | NDataBlock<int_4> sliceLenght_; | 
|---|
| [843] | 208 |  | 
|---|
|  | 209 | }; | 
|---|
|  | 210 |  | 
|---|
| [1419] | 211 | //////////////////////////////////////////////////////////////// | 
|---|
|  | 212 | // Surcharge d'operateurs A (+,-,*,/) (T) x | 
|---|
| [1423] | 213 | /*! \ingroup SkyMap \fn operator+(const SphereHEALPix<T>&,T) | 
|---|
| [1419] | 214 | \brief Operator SphereHEALPix = SphereHEALPix + constant */ | 
|---|
|  | 215 | template <class T> inline SphereHEALPix<T> operator + (const SphereHEALPix<T>& a, T b) | 
|---|
|  | 216 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 217 | result.Add(b); return result;} | 
|---|
| [1423] | 218 | /*! \ingroup SkyMap \fn operator+(T,const SphereHEALPix<T>&) | 
|---|
| [1419] | 219 | \brief Operator SphereHEALPix = constant + SphereHEALPix */ | 
|---|
|  | 220 | template <class T> inline SphereHEALPix<T> operator + (T b,const SphereHEALPix<T>& a) | 
|---|
|  | 221 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 222 | result.Add(b); return result;} | 
|---|
| [843] | 223 |  | 
|---|
|  | 224 |  | 
|---|
| [1419] | 225 | /*! \ingroup SphereHEALPix\fn operator-(const SphereHEALPix<T>&,T) | 
|---|
|  | 226 | \brief Operator SphereHEALPix = SphereHEALPix - constant */ | 
|---|
|  | 227 | template <class T> inline SphereHEALPix<T> operator - (const SphereHEALPix<T>& a, T b) | 
|---|
|  | 228 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 229 | result.Sub(b); return result;} | 
|---|
|  | 230 |  | 
|---|
|  | 231 | /*! \ingroup  \fn operator-(T,const SphereHEALPix<T>&) | 
|---|
|  | 232 | \brief Operator SphereHEALPix = constant - SphereHEALPix */ | 
|---|
|  | 233 | template <class T> inline SphereHEALPix<T> operator - (T b,const SphereHEALPix<T>& a) | 
|---|
|  | 234 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 235 | result.Sub(b,true); return result;} | 
|---|
|  | 236 |  | 
|---|
| [1423] | 237 | /*! \ingroup SkyMap \fn operator*(const SphereHEALPix<T>&,T) | 
|---|
| [1419] | 238 | \brief Operator SphereHEALPix = SphereHEALPix * constant */ | 
|---|
|  | 239 | template <class T> inline SphereHEALPix<T> operator * (const SphereHEALPix<T>& a, T b) | 
|---|
|  | 240 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 241 | result.Mul(b); return result;} | 
|---|
|  | 242 |  | 
|---|
| [1423] | 243 | /*! \ingroup SkyMap \fn operator*(T,const SphereHEALPix<T>&) | 
|---|
| [1419] | 244 | \brief Operator SphereHEALPix = constant * SphereHEALPix */ | 
|---|
|  | 245 | template <class T> inline SphereHEALPix<T> operator * (T b,const SphereHEALPix<T>& a) | 
|---|
|  | 246 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 247 | result.Mul(b); return result;} | 
|---|
|  | 248 |  | 
|---|
| [1423] | 249 | /*! \ingroup SkyMap \fn operator/(const SphereHEALPix<T>&,T) | 
|---|
| [1419] | 250 | \brief Operator SphereHEALPix = SphereHEALPix / constant */ | 
|---|
|  | 251 | template <class T> inline SphereHEALPix<T> operator / (const SphereHEALPix<T>& a, T b) | 
|---|
|  | 252 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 253 | result.Div(b); return result;} | 
|---|
|  | 254 |  | 
|---|
| [1423] | 255 | /*! \ingroup SkyMap \fn operator/(T,const SphereHEALPix<T>&) | 
|---|
| [1419] | 256 | \brief Operator SphereHEALPix = constant / SphereHEALPix  */ | 
|---|
|  | 257 | template <class T> inline SphereHEALPix<T> operator / (T b, const SphereHEALPix<T>& a) | 
|---|
|  | 258 | {SphereHEALPix<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
|  | 259 | result.Div(b, true); return result;} | 
|---|
|  | 260 |  | 
|---|
|  | 261 | //////////////////////////////////////////////////////////////// | 
|---|
|  | 262 | // Surcharge d'operateurs C = A (+,-) B | 
|---|
|  | 263 |  | 
|---|
| [1423] | 264 | /*! \ingroup SkyMap \fn operator+(const SphereHEALPix<T>&,const SphereHEALPix<T>&) | 
|---|
| [1419] | 265 | \brief Operator SphereHEALPix = SphereHEALPix + SphereHEALPix */ | 
|---|
|  | 266 | template <class T> | 
|---|
|  | 267 | inline SphereHEALPix<T> operator + (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b) | 
|---|
|  | 268 | { SphereHEALPix<T> result; result.SetTemp(true); | 
|---|
|  | 269 | if (b.IsTemp())  { result.Share(b); result.AddElt(a); } | 
|---|
|  | 270 | else { result.CloneOrShare(a); result.AddElt(b); } | 
|---|
|  | 271 | return result; } | 
|---|
|  | 272 |  | 
|---|
| [1423] | 273 | /*! \ingroup SkyMap \fn operator-(const SphereHEALPix<T>&,const SphereHEALPix<T>&) | 
|---|
| [1419] | 274 | \brief Operator SphereHEALPix = SphereHEALPix - SphereHEALPix */ | 
|---|
|  | 275 | template <class T> | 
|---|
|  | 276 | inline SphereHEALPix<T> operator - (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b) | 
|---|
|  | 277 | { SphereHEALPix<T> result; result.SetTemp(true); | 
|---|
| [2965] | 278 | result.CloneOrShare(a); result.SubElt(b); | 
|---|
| [1419] | 279 | return result; } | 
|---|
|  | 280 |  | 
|---|
| [1551] | 281 | //////////////////////////////////////////////////////////////// | 
|---|
|  | 282 | // Surcharge d'operateurs C = A (*,/) B | 
|---|
|  | 283 |  | 
|---|
|  | 284 | /*! \ingroup SkyMap \fn operator*(const SphereHEALPix<T>&,const SphereHEALPix<T>&) | 
|---|
|  | 285 | \brief Operator SphereHEALPix = SphereHEALPix * SphereHEALPix (pixel by pixel multiply) */ | 
|---|
|  | 286 | template <class T> | 
|---|
|  | 287 | inline SphereHEALPix<T> operator * (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b) | 
|---|
|  | 288 | { SphereHEALPix<T> result; result.SetTemp(true); | 
|---|
|  | 289 | if (b.IsTemp())  { result.Share(b); result.MulElt(a); } | 
|---|
|  | 290 | else { result.CloneOrShare(a); result.MulElt(b); } | 
|---|
|  | 291 | return result; } | 
|---|
|  | 292 |  | 
|---|
|  | 293 | /*! \ingroup SkyMap \fn operator/(const SphereHEALPix<T>&,const SphereHEALPix<T>&) | 
|---|
|  | 294 | \brief Operator SphereHEALPix = SphereHEALPix / SphereHEALPix (pixel by pixel divide) */ | 
|---|
|  | 295 | template <class T> | 
|---|
|  | 296 | inline SphereHEALPix<T> operator / (const SphereHEALPix<T>& a,const SphereHEALPix<T>& b) | 
|---|
|  | 297 | { SphereHEALPix<T> result; result.SetTemp(true); | 
|---|
| [2433] | 298 | result.CloneOrShare(a); result.DivElt(b); | 
|---|
| [1551] | 299 | return result; } | 
|---|
|  | 300 |  | 
|---|
| [843] | 301 | } // Fin du namespace | 
|---|
|  | 302 |  | 
|---|
|  | 303 | #endif | 
|---|