| 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 | 
 | 
|---|
| 11 | template <class T>
 | 
|---|
| 12 | class FIO_SphereThetaPhi;  
 | 
|---|
| 13 | 
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // ***************** Class SphereThetaPhi *****************************
 | 
|---|
| 16 | /*!    sphere splitted with respect to theta, phi : each hemisphere is 
 | 
|---|
| 17 |     splitted into (m-1) parallels (equator does not enter into account).
 | 
|---|
| 18 |    This operation defines m slices, each of which is splitted into 
 | 
|---|
| 19 |     equidistant meridians. This splitting is realized in such a way that 
 | 
|---|
| 20 |     all pixels have the same area and are as square as possible.
 | 
|---|
| 21 | 
 | 
|---|
| 22 |     One begins with the hemisphere with positive z, starting from the pole
 | 
|---|
| 23 |     toward the equator. The first pixel is the polar cap ; it is circular
 | 
|---|
| 24 |     and centered on theta=0. 
 | 
|---|
| 25 | */
 | 
|---|
| 26 | template <class T>
 | 
|---|
| 27 | class SphereThetaPhi : public SphericalMap<T>
 | 
|---|
| 28 | {
 | 
|---|
| 29 | 
 | 
|---|
| 30 |   friend class FIO_SphereThetaPhi<T>;
 | 
|---|
| 31 | 
 | 
|---|
| 32 | public :
 | 
|---|
| 33 | 
 | 
|---|
| 34 | SphereThetaPhi();
 | 
|---|
| 35 | /*!    m is the number of slices in theta on an hemisphere (the polar cap
 | 
|---|
| 36 |    forms the first slice).
 | 
|---|
| 37 |     pet is a dummy parameter at the moment. 
 | 
|---|
| 38 | */
 | 
|---|
| 39 | SphereThetaPhi(int_4 m);
 | 
|---|
| 40 | SphereThetaPhi(const SphereThetaPhi<T>& s, bool share=false);
 | 
|---|
| 41 | virtual ~SphereThetaPhi();
 | 
|---|
| 42 | 
 | 
|---|
| 43 | /*! Setting blockdata to temporary (see ndatablock documentation) */
 | 
|---|
| 44 | inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);};
 | 
|---|
| 45 | 
 | 
|---|
| 46 | // ------------ Definition of PixelMap abstract methods -
 | 
|---|
| 47 | 
 | 
|---|
| 48 | /* retourne le nombre de pixels */ 
 | 
|---|
| 49 | /*!    Return total number of pixels  */
 | 
|---|
| 50 | virtual int_4 NbPixels() const;
 | 
|---|
| 51 | 
 | 
|---|
| 52 | /* retourne la valeur du pixel d'indice k */ 
 | 
|---|
| 53 | /*!    Return value of pixel with index k */
 | 
|---|
| 54 | virtual T&       PixVal(int_4 k);
 | 
|---|
| 55 | virtual T const& PixVal(int_4 k) const;
 | 
|---|
| 56 | 
 | 
|---|
| 57 | /* Return true if teta,phi in map  */
 | 
|---|
| 58 | virtual bool ContainsSph(double theta, double phi) const;
 | 
|---|
| 59 | /* retourne l'indice du pixel a (theta,phi) */ 
 | 
|---|
| 60 | /*    Return index of the pixel corresponding to direction (theta, phi). */
 | 
|---|
| 61 | virtual int_4 PixIndexSph(double theta, double phi) const;
 | 
|---|
| 62 | 
 | 
|---|
| 63 | /* retourne les coordonnees Spheriques du centre du pixel d'indice k */ 
 | 
|---|
| 64 | /*!   Return (theta,phi) coordinates of middle of  pixel with  index k */
 | 
|---|
| 65 | virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const;
 | 
|---|
| 66 | 
 | 
|---|
| 67 | /*! Setting pixel values to a constant */
 | 
|---|
| 68 | virtual T SetPixels(T v);
 | 
|---|
| 69 | 
 | 
|---|
| 70 | /* retourne/fixe l'angle Solide de Pixel   (steradians) */ 
 | 
|---|
| 71 | /*!   Pixel Solid angle  (steradians)
 | 
|---|
| 72 | 
 | 
|---|
| 73 |     All the pixels have the same solid angle. The dummy argument is
 | 
|---|
| 74 |    for compatibility with eventual pixelizations which would not 
 | 
|---|
| 75 |     fulfil this requirement.
 | 
|---|
| 76 | */
 | 
|---|
| 77 | virtual double PixSolAngle(int_4 dummy=0) const;
 | 
|---|
| 78 |  
 | 
|---|
| 79 | /* retourne/fixe la valeur du parametre de decoupage m */ 
 | 
|---|
| 80 | inline virtual int_4 SizeIndex() const { return( NTheta_); }
 | 
|---|
| 81 | 
 | 
|---|
| 82 | /*  Acces to the DataBlock  */
 | 
|---|
| 83 | inline       NDataBlock<T>& DataBlock()       {return pixels_;}
 | 
|---|
| 84 | inline const NDataBlock<T>& DataBlock() const {return pixels_;}
 | 
|---|
| 85 | 
 | 
|---|
| 86 | // ------------- Specific methods  ----------------------
 | 
|---|
| 87 | 
 | 
|---|
| 88 | /*!   re-pixelize the sphere */
 | 
|---|
| 89 | virtual void Resize(int_4 m);
 | 
|---|
| 90 | 
 | 
|---|
| 91 | inline virtual char* TypeOfMap() const {return "TETAFI";};
 | 
|---|
| 92 | 
 | 
|---|
| 93 | /* Valeurs de theta des paralleles et phi des meridiens limitant le pixel d'indice k */
 | 
|---|
| 94 | /*   Return values of theta,phi which limit the pixel with  index k */
 | 
|---|
| 95 | virtual void Limits(int_4 k,double& th1,double& th2,double& phi1,double& phi2);
 | 
|---|
| 96 | 
 | 
|---|
| 97 | /* Nombre de tranches en theta */ 
 | 
|---|
| 98 | /*!    Return number of theta-slices on the sphere */
 | 
|---|
| 99 | uint_4 NbThetaSlices() const;
 | 
|---|
| 100 | 
 | 
|---|
| 101 | /* Nombre de pixels en phi de la tranche d'indice kt */ 
 | 
|---|
| 102 | int_4 NPhi(int_4 kt) const;
 | 
|---|
| 103 | 
 | 
|---|
| 104 | /* Renvoie dans t1,t2 les valeurs respectives de theta min et theta max  */
 | 
|---|
| 105 | /* de la tranche d'indice kt  */ 
 | 
|---|
| 106 | /*!    Return  theta values which limit the slice kt */
 | 
|---|
| 107 | void Theta(int_4 kt, double& t1, double& t2);
 | 
|---|
| 108 | 
 | 
|---|
| 109 | /* Renvoie dans p1,p2 les valeurs phimin et phimax du pixel d'indice jp  */
 | 
|---|
| 110 | /* dans la tranche d'indice kt  */ 
 | 
|---|
| 111 | /*!   Return values of phi which limit the jp-th pixel of the kt-th slice */
 | 
|---|
| 112 | void Phi(int_4 kt, int_4 jp, double& p1, double& p2);
 | 
|---|
| 113 | 
 | 
|---|
| 114 | /* Renvoie l'indice k du pixel d'indice jp dans la tranche d'indice kt   */
 | 
|---|
| 115 | /*!   Return pixel index  with sequence index jp in the slice kt */
 | 
|---|
| 116 | int_4 Index(int_4 kt, int_4 jp) const;
 | 
|---|
| 117 | 
 | 
|---|
| 118 | /* Indice kt de la tranche et indice jp du pixel d'indice k  */ 
 | 
|---|
| 119 | /*!    Return indices kt (theta) and jp (phi) of  pixel with index k */
 | 
|---|
| 120 | void ThetaPhiIndex(int_4 k,int_4& kt,int_4& jp);
 | 
|---|
| 121 | 
 | 
|---|
| 122 | /*!    achieve the splitting into pixels (m has the same signification 
 | 
|---|
| 123 |     as for the constructor)
 | 
|---|
| 124 | 
 | 
|---|
| 125 |     Each theta-slice of the north hemisphere will be spitted starting f
 | 
|---|
| 126 |     from  phi=0 ...
 | 
|---|
| 127 | 
 | 
|---|
| 128 |     South hemisphere is scanned in the same direction according to phi
 | 
|---|
| 129 |     and from equator to the pole (the pixel following the last one of
 | 
|---|
| 130 |     the slice closest to the equator with z>0, is the pixel with lowest 
 | 
|---|
| 131 |     phi of the slice closest of the equator with z<0).
 | 
|---|
| 132 | */
 | 
|---|
| 133 | void Pixelize(int_4); 
 | 
|---|
| 134 | 
 | 
|---|
| 135 | /*!   For a theta-slice with index 'index', return : 
 | 
|---|
| 136 | 
 | 
|---|
| 137 |    the corresponding "theta" 
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     a vector containing the phi's of the pixels of the slice
 | 
|---|
| 140 | 
 | 
|---|
| 141 |     a vector containing the corresponding values of pixels 
 | 
|---|
| 142 | */
 | 
|---|
| 143 | void GetThetaSlice(int_4 index,r_8& theta,TVector<r_8>& phi,TVector<T>& value) const; 
 | 
|---|
| 144 | 
 | 
|---|
| 145 | /*!   For a theta-slice with index 'index', return : 
 | 
|---|
| 146 | 
 | 
|---|
| 147 |    the corresponding "theta" 
 | 
|---|
| 148 | 
 | 
|---|
| 149 |    the corresponding "phi" for first pixel of the slice 
 | 
|---|
| 150 | 
 | 
|---|
| 151 |     a vector containing indices of the pixels of the slice
 | 
|---|
| 152 | 
 | 
|---|
| 153 |    (equally distributed in phi)
 | 
|---|
| 154 | 
 | 
|---|
| 155 |     a vector containing the corresponding values of pixels 
 | 
|---|
| 156 | */
 | 
|---|
| 157 |  void GetThetaSlice(int_4 index, r_8& theta, r_8& phi0,TVector<int_4>& pixelIndices, TVector<T>& value) const ;
 | 
|---|
| 158 | 
 | 
|---|
| 159 | 
 | 
|---|
| 160 | /* impression */ 
 | 
|---|
| 161 | void print(ostream& os) const;
 | 
|---|
| 162 | 
 | 
|---|
| 163 | private :
 | 
|---|
| 164 | 
 | 
|---|
| 165 | // ------------- méthodes internes ----------------------          
 | 
|---|
| 166 | void InitNul();
 | 
|---|
| 167 | inline void setParameters(int nbpix, double omega, int nbThetaIndex) 
 | 
|---|
| 168 |   {
 | 
|---|
| 169 |     NPix_= nbpix;
 | 
|---|
| 170 |     Omega_= omega;
 | 
|---|
| 171 |     NTheta_= nbThetaIndex;
 | 
|---|
| 172 |   }
 | 
|---|
| 173 | 
 | 
|---|
| 174 | // ------------- variables internes ---------------------
 | 
|---|
| 175 |  int_4 NTheta_;   // nombre de tranches en theta, pour une demi-sphere
 | 
|---|
| 176 |  int_4 NPix_;     // nombre total de pixels
 | 
|---|
| 177 |  double Omega_; // angle solide constant pour chaque pixel
 | 
|---|
| 178 |  NDataBlock<int_4>  NPhi_;  // tableau donnant, pour chaque bande en theta, 
 | 
|---|
| 179 |                          //le nombre de pixels selon phi
 | 
|---|
| 180 |  NDataBlock<int_4> TNphi_;
 | 
|---|
| 181 |  NDataBlock<r_8> Theta_;
 | 
|---|
| 182 |  NDataBlock<T> pixels_;
 | 
|---|
| 183 | };
 | 
|---|
| 184 | 
 | 
|---|
| 185 | // ------------- Classe pour la gestion de persistance --
 | 
|---|
| 186 | template <class T>
 | 
|---|
| 187 | class FIO_SphereThetaPhi : public PPersist  
 | 
|---|
| 188 | {
 | 
|---|
| 189 | public:
 | 
|---|
| 190 | 
 | 
|---|
| 191 | FIO_SphereThetaPhi();
 | 
|---|
| 192 | FIO_SphereThetaPhi(string const & filename); 
 | 
|---|
| 193 | FIO_SphereThetaPhi(const SphereThetaPhi<T>& obj);
 | 
|---|
| 194 | FIO_SphereThetaPhi(SphereThetaPhi<T>* obj);
 | 
|---|
| 195 | virtual ~FIO_SphereThetaPhi();
 | 
|---|
| 196 | virtual AnyDataObj* DataObj();
 | 
|---|
| 197 | virtual void        SetDataObj(AnyDataObj & o);
 | 
|---|
| 198 | inline operator SphereThetaPhi<T>() { return(*dobj); }
 | 
|---|
| 199 | 
 | 
|---|
| 200 | protected :
 | 
|---|
| 201 | 
 | 
|---|
| 202 | virtual void ReadSelf(PInPersist&);           
 | 
|---|
| 203 | virtual void WriteSelf(POutPersist&) const;  
 | 
|---|
| 204 | SphereThetaPhi<T>* dobj;
 | 
|---|
| 205 | bool ownobj;
 | 
|---|
| 206 | };
 | 
|---|
| 207 | 
 | 
|---|
| 208 | #endif
 | 
|---|