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