| 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 |  | 
|---|
| 12 | namespace SOPHYA { | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | // ***************** CLASSE SphereHEALPix ***************************** | 
|---|
| 16 |  | 
|---|
| 17 | //!  class SphereHEALPix | 
|---|
| 18 | /*! | 
|---|
| 19 | Pixelisation Gorski | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | ----------------------------------------------------------------------- | 
|---|
| 23 | version 0.8.2  Aug97 TAC  Eric Hivon, Kris Gorski | 
|---|
| 24 | ----------------------------------------------------------------------- | 
|---|
| 25 |  | 
|---|
| 26 | the sphere is split in 12 diamond-faces containing nside**2 pixels each | 
|---|
| 27 |  | 
|---|
| 28 | the numbering of the pixels (in the nested scheme) is similar to | 
|---|
| 29 | quad-cube | 
|---|
| 30 | In each face the first pixel is in the lowest corner of the diamond | 
|---|
| 31 |  | 
|---|
| 32 | the faces are                    (x,y) coordinate on each face | 
|---|
| 33 | \verbatim | 
|---|
| 34 | .   .   .   .   <--- North Pole | 
|---|
| 35 | / \ / \ / \ / \                          ^        ^ | 
|---|
| 36 | . 0 . 1 . 2 . 3 . <--- z = 2/3             \      / | 
|---|
| 37 | \ / \ / \ / \ /                        y   \    /  x | 
|---|
| 38 | 4 . 5 . 6 . 7 . 4 <--- equator               \  / | 
|---|
| 39 | / \ / \ / \ / \                              \/ | 
|---|
| 40 | . 8 . 9 .10 .11 . <--- z = -2/3              (0,0) : lowest corner | 
|---|
| 41 | \ / \ / \ / \ / | 
|---|
| 42 | .   .   .   .   <--- South Pole | 
|---|
| 43 | \endverbatim | 
|---|
| 44 | phi:0               2Pi | 
|---|
| 45 |  | 
|---|
| 46 | in the ring scheme pixels are numbered along the parallels | 
|---|
| 47 | the first parallel is the one closest to the north pole and so on | 
|---|
| 48 | on each parallel, pixels are numbered starting from the one closest | 
|---|
| 49 | to phi = 0 | 
|---|
| 50 |  | 
|---|
| 51 | nside MUST be a power of 2 (<= 8192) | 
|---|
| 52 |  | 
|---|
| 53 | */ | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | template<class T> | 
|---|
| 57 | class FIO_SphereHEALPix; | 
|---|
| 58 |  | 
|---|
| 59 | template<class T> | 
|---|
| 60 | class FITS_SphereHEALPix; | 
|---|
| 61 |  | 
|---|
| 62 | template<class T> | 
|---|
| 63 | class SphereHEALPix : public SphericalMap<T> | 
|---|
| 64 | { | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 | friend class FIO_SphereHEALPix<T>; | 
|---|
| 68 | friend class FITS_SphereHEALPix<T>; | 
|---|
| 69 |  | 
|---|
| 70 | public : | 
|---|
| 71 |  | 
|---|
| 72 | SphereHEALPix(); | 
|---|
| 73 | /*! | 
|---|
| 74 | m is the "nside" of the Gorski algorithm | 
|---|
| 75 |  | 
|---|
| 76 | The total number of pixels will be Npix =  12*nside**2 | 
|---|
| 77 |  | 
|---|
| 78 | nside MUST be a power of 2 (<= 8192) | 
|---|
| 79 | */ | 
|---|
| 80 | SphereHEALPix(int_4 m); | 
|---|
| 81 | SphereHEALPix(const SphereHEALPix<T>& s, bool share); | 
|---|
| 82 | SphereHEALPix(const SphereHEALPix<T>& s); | 
|---|
| 83 | //!     Destructor | 
|---|
| 84 | virtual ~SphereHEALPix(); | 
|---|
| 85 |  | 
|---|
| 86 | // Temporaire? | 
|---|
| 87 | inline virtual bool   IsTemp(void) const { | 
|---|
| 88 |  | 
|---|
| 89 | if (sliceBeginIndex_.IsTemp() != pixels_.IsTemp() || sliceLenght_.IsTemp() != pixels_.IsTemp() ) | 
|---|
| 90 | throw PException(" l'etat 'temporaire' de la spherehealpix est incoherent"); | 
|---|
| 91 | return pixels_.IsTemp(); | 
|---|
| 92 | } | 
|---|
| 93 | /*! Setting blockdata to temporary (see ndatablock documentation) */ | 
|---|
| 94 | inline virtual void SetTemp(bool temp=false) const | 
|---|
| 95 | { | 
|---|
| 96 | pixels_.SetTemp(temp); | 
|---|
| 97 | sliceBeginIndex_.SetTemp(temp); | 
|---|
| 98 | sliceLenght_.SetTemp(temp); | 
|---|
| 99 | }; | 
|---|
| 100 | // ------------------ Definition of PixelMap abstract methods | 
|---|
| 101 |  | 
|---|
| 102 | /* Nombre de pixels du decoupage */ | 
|---|
| 103 | /*!    Return number of  pixels of the  splitting */ | 
|---|
| 104 | virtual int_4 NbPixels() const; | 
|---|
| 105 |  | 
|---|
| 106 | /* Valeur du contenu du pixel d'indice "RING" k  */ | 
|---|
| 107 | /*!    Return value of  pixel with "RING" index k */ | 
|---|
| 108 | virtual T& PixVal(int_4 k); | 
|---|
| 109 | virtual T const& PixVal(int_4 k) const; | 
|---|
| 110 |  | 
|---|
| 111 | /* Nombre de tranches en theta */ | 
|---|
| 112 | /*!    Return number of slices in theta direction on the  sphere */ | 
|---|
| 113 | uint_4 NbThetaSlices() const; | 
|---|
| 114 | /*!   For a theta-slice with index 'index', return : | 
|---|
| 115 |  | 
|---|
| 116 | the corresponding "theta" | 
|---|
| 117 |  | 
|---|
| 118 | a vector containing the phi's of the pixels of the slice | 
|---|
| 119 |  | 
|---|
| 120 | a vector containing the corresponding values of pixels | 
|---|
| 121 | */ | 
|---|
| 122 | virtual void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const; | 
|---|
| 123 | /*!   For a theta-slice with index 'index', return : | 
|---|
| 124 |  | 
|---|
| 125 | the corresponding "theta" | 
|---|
| 126 |  | 
|---|
| 127 | the corresponding "phi" for first pixel of the slice | 
|---|
| 128 |  | 
|---|
| 129 | a vector containing indices of the pixels of the slice | 
|---|
| 130 |  | 
|---|
| 131 | (equally distributed in phi) | 
|---|
| 132 |  | 
|---|
| 133 | a vector containing the corresponding values of pixels | 
|---|
| 134 | */ | 
|---|
| 135 | virtual void GetThetaSlice(int_4 sliceIndex,r_8& theta, r_8& phi0, TVector<int_4>& pixelIndices,TVector<T>& value) const ; | 
|---|
| 136 |  | 
|---|
| 137 | /* Return true if teta,phi in map  */ | 
|---|
| 138 | virtual bool ContainsSph(double theta, double phi) const; | 
|---|
| 139 | /* Indice "RING" du pixel vers lequel pointe une direction definie par | 
|---|
| 140 | ses  coordonnees spheriques */ | 
|---|
| 141 | /*!  Return "RING" index of the pixel corresponding to direction (theta, phi). | 
|---|
| 142 | */ | 
|---|
| 143 | virtual int_4 PixIndexSph(double theta,double phi) const; | 
|---|
| 144 |  | 
|---|
| 145 | /* Coordonnees spheriques du milieu du pixel d'indice "RING" k   */ | 
|---|
| 146 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const; | 
|---|
| 147 |  | 
|---|
| 148 | /*! Set all pixels to value v */ | 
|---|
| 149 | virtual T SetPixels(T v); | 
|---|
| 150 |  | 
|---|
| 151 | /* Pixel Solid angle  (steradians) */ | 
|---|
| 152 | /*!    Pixel Solid angle  (steradians) | 
|---|
| 153 |  | 
|---|
| 154 | All the pixels have the same solid angle. The dummy argument is | 
|---|
| 155 | for compatibility with eventual pixelizations which would not | 
|---|
| 156 | fulfil this requirement. | 
|---|
| 157 | */ | 
|---|
| 158 | virtual double PixSolAngle(int_4 dummy=0) const; | 
|---|
| 159 |  | 
|---|
| 160 | /*  Acces to the DataBlock  */ | 
|---|
| 161 | inline       NDataBlock<T>& DataBlock()       {return pixels_;} | 
|---|
| 162 | inline const NDataBlock<T>& DataBlock() const {return pixels_;} | 
|---|
| 163 |  | 
|---|
| 164 | // --------------- Specific methods | 
|---|
| 165 |  | 
|---|
| 166 | /*! | 
|---|
| 167 | m is the "nside" of the Gorski algorithm | 
|---|
| 168 |  | 
|---|
| 169 | The total number of pixels will be Npix =  12*nside**2 | 
|---|
| 170 |  | 
|---|
| 171 | nside MUST be a power of 2 (<= 8192) | 
|---|
| 172 | */ | 
|---|
| 173 | virtual void Resize(int_4 m); | 
|---|
| 174 |  | 
|---|
| 175 | // pour l'instant le tableau est ordonne selon RING, uniquement | 
|---|
| 176 | inline virtual char* TypeOfMap() const {return "RING";}; | 
|---|
| 177 |  | 
|---|
| 178 |  | 
|---|
| 179 | /* Valeur du contenu du pixel d'indice "NEST" k */ | 
|---|
| 180 | /*!    Return value of  pixel with "NESTED" index k */ | 
|---|
| 181 | virtual T& PixValNest(int_4 k); | 
|---|
| 182 | /*!    Return value of  pixel with "NESTED" index k */ | 
|---|
| 183 | virtual T const& PixValNest(int_4 k) const; | 
|---|
| 184 |  | 
|---|
| 185 | /* Indice "NEST" du pixel vers lequel pointe une direction definie par | 
|---|
| 186 | ses  coordonnees spheriques */ | 
|---|
| 187 | /*! Return "NESTED" index of the pixel corresponding to direction (theta, phi). | 
|---|
| 188 | */ | 
|---|
| 189 | virtual int_4 PixIndexSphNest(double theta,double phi) const; | 
|---|
| 190 |  | 
|---|
| 191 | /* Coordonnees spheriques du milieu du pixel d'indice "NEST" k       */ | 
|---|
| 192 | /*!   Return (theta,phi) coordinates of middle of  pixel with "NESTED" index k | 
|---|
| 193 | */ | 
|---|
| 194 | virtual void PixThetaPhiNest(int_4 k,double& theta,double& phi) const; | 
|---|
| 195 |  | 
|---|
| 196 | /* algorithme de pixelisation */ | 
|---|
| 197 | void Pixelize(int_4); | 
|---|
| 198 |  | 
|---|
| 199 | /* convertit index nested en ring  */ | 
|---|
| 200 | /*!    translation from NESTED index  into RING index */ | 
|---|
| 201 | int_4 NestToRing(int_4) const; | 
|---|
| 202 |  | 
|---|
| 203 | /* convertit index ring en nested" */ | 
|---|
| 204 | /*!    translation from  RING index  into NESTED index */ | 
|---|
| 205 | int_4 RingToNest(int_4) const; | 
|---|
| 206 |  | 
|---|
| 207 |  | 
|---|
| 208 | /* retourne la valeur du parametre Gorski */ | 
|---|
| 209 | inline virtual int_4 SizeIndex() const {return(nSide_);} | 
|---|
| 210 |  | 
|---|
| 211 | /* impression */ | 
|---|
| 212 | void print(ostream& os) const; | 
|---|
| 213 |  | 
|---|
| 214 |  | 
|---|
| 215 |  | 
|---|
| 216 | inline  SphereHEALPix<T>& operator = (const SphereHEALPix<T>& a) | 
|---|
| 217 | {return Set(a);} | 
|---|
| 218 |  | 
|---|
| 219 | private : | 
|---|
| 220 |  | 
|---|
| 221 | // ------------- méthodes internes ---------------------- | 
|---|
| 222 | void InitNul(); | 
|---|
| 223 | void SetThetaSlices(); | 
|---|
| 224 |  | 
|---|
| 225 | int_4  nest2ring(int_4 nside,int_4 ipnest) const; | 
|---|
| 226 | int_4  ring2nest(int_4 nside,int_4 ipring) const; | 
|---|
| 227 |  | 
|---|
| 228 | int_4  ang2pix_ring(int_4 nside,double theta,double phi) const; | 
|---|
| 229 | int_4  ang2pix_nest(int_4 nside,double theta,double phi) const; | 
|---|
| 230 | void pix2ang_ring(int_4 nside,int_4 ipix,double& theta,double& phi) const; | 
|---|
| 231 | void pix2ang_nest(int_4 nside,int_4 ipix,double& theta,double& phi) const; | 
|---|
| 232 | inline void setParameters(int_4 nside, int_4 nbpixels, double solangle) | 
|---|
| 233 | { | 
|---|
| 234 | nSide_= nside; | 
|---|
| 235 | nPix_= nbpixels; | 
|---|
| 236 | omeg_= solangle; | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | void CloneOrShare(const SphereHEALPix<T>& a); | 
|---|
| 240 | SphereHEALPix<T>& Set(const SphereHEALPix<T>& a); | 
|---|
| 241 |  | 
|---|
| 242 | // ------------- variables internes ----------------------- | 
|---|
| 243 |  | 
|---|
| 244 | int_4 nSide_; | 
|---|
| 245 | int_4 nPix_; | 
|---|
| 246 | double omeg_; | 
|---|
| 247 |  | 
|---|
| 248 | NDataBlock<T> pixels_; | 
|---|
| 249 | NDataBlock<int> sliceBeginIndex_; | 
|---|
| 250 | NDataBlock<int> sliceLenght_; | 
|---|
| 251 |  | 
|---|
| 252 | }; | 
|---|
| 253 |  | 
|---|
| 254 |  | 
|---|
| 255 | ////////////////////////////////////////////////////////////////////////// | 
|---|
| 256 | // | 
|---|
| 257 | // ------------- Classe PIXELS_XY ----------------------- | 
|---|
| 258 | // | 
|---|
| 259 | class PIXELS_XY | 
|---|
| 260 | { | 
|---|
| 261 |  | 
|---|
| 262 | public : | 
|---|
| 263 |  | 
|---|
| 264 | static PIXELS_XY& instance(); | 
|---|
| 265 |  | 
|---|
| 266 | NDataBlock<int_4> pix2x_; | 
|---|
| 267 | NDataBlock<int_4> pix2y_; | 
|---|
| 268 | NDataBlock<int_4> x2pix_; | 
|---|
| 269 | NDataBlock<int_4> y2pix_; | 
|---|
| 270 |  | 
|---|
| 271 | private : | 
|---|
| 272 |  | 
|---|
| 273 | PIXELS_XY(); | 
|---|
| 274 | void mk_pix2xy(); | 
|---|
| 275 | void mk_xy2pix(); | 
|---|
| 276 | }; | 
|---|
| 277 |  | 
|---|
| 278 | } // Fin du namespace | 
|---|
| 279 |  | 
|---|
| 280 | #endif | 
|---|