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