| [764] | 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
|  | 2 | #ifndef PIXELMAP_SEEN | 
|---|
|  | 3 | #define PIXELMAP_SEEN | 
|---|
|  | 4 |  | 
|---|
|  | 5 | #include "ppersist.h" | 
|---|
|  | 6 | #include "dvlist.h" | 
|---|
|  | 7 | #include "spherepos.h" | 
|---|
| [2973] | 8 | #include "datatype.h" | 
|---|
| [2322] | 9 | #include <iostream> | 
|---|
| [2973] | 10 | #include <typeinfo> | 
|---|
| [764] | 11 |  | 
|---|
| [1066] | 12 | namespace SOPHYA { | 
|---|
|  | 13 |  | 
|---|
| [1371] | 14 | /*! | 
|---|
| [1375] | 15 | \class PixelMap | 
|---|
| [1371] | 16 | \ingroup SkyMap | 
|---|
|  | 17 | General map of pixels on part of sphere or whole sphere. | 
|---|
|  | 18 |  | 
|---|
|  | 19 | Class hierarchy : | 
|---|
| [764] | 20 | \verbatim | 
|---|
|  | 21 | PixelMap | 
|---|
|  | 22 | SphericalMap | 
|---|
|  | 23 | SphereThetaPhi | 
|---|
| [1371] | 24 | SphereHEALPix | 
|---|
| [764] | 25 | SphereIco | 
|---|
|  | 26 | LocalMap | 
|---|
|  | 27 | \endverbatim | 
|---|
|  | 28 | */ | 
|---|
| [908] | 29 |  | 
|---|
| [764] | 30 | template<class T> | 
|---|
|  | 31 | class PixelMap  : public AnyDataObj | 
|---|
|  | 32 | { | 
|---|
|  | 33 | public: | 
|---|
|  | 34 |  | 
|---|
|  | 35 | PixelMap(SphereCoordSys* cs = NULL) : mInfo_(NULL) | 
|---|
|  | 36 | { if (cs) cs_ = cs; else cs_ = new SphereCoordSys; } | 
|---|
|  | 37 | virtual       ~PixelMap() | 
|---|
|  | 38 | { if (mInfo_) delete mInfo_; if (cs_) delete cs_; } | 
|---|
|  | 39 |  | 
|---|
|  | 40 | // Set/Change/Get the coordinate system | 
|---|
|  | 41 | virtual void  SetCoordSys(SphereCoordSys* cs) | 
|---|
|  | 42 | { if (cs) { delete cs_;  cs_ = cs; } } | 
|---|
|  | 43 | inline SphereCoordSys* GetCoordSys() const { return(cs_); } | 
|---|
|  | 44 |  | 
|---|
|  | 45 | /*! Number of pixels */ | 
|---|
|  | 46 | virtual int_4 NbPixels() const=0; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | /*! Value of pixel number k */ | 
|---|
|  | 49 | virtual T& PixVal(int_4 k)=0; | 
|---|
|  | 50 | virtual T const& PixVal(int_4 k) const=0; | 
|---|
|  | 51 |  | 
|---|
|  | 52 | // Map s coverage | 
|---|
|  | 53 | virtual bool ContainsSph(double theta, double phi) const=0; | 
|---|
|  | 54 | virtual bool Contains(const SpherePosition& spos) const; | 
|---|
|  | 55 |  | 
|---|
|  | 56 | /*! Index of pixel at (theta,phi) */ | 
|---|
|  | 57 | virtual int_4 PixIndexSph(double theta, double phi) const=0; | 
|---|
|  | 58 | // Index of pixel at a sky-position | 
|---|
|  | 59 | virtual int_4 PixIndex(const SpherePosition& spos); | 
|---|
|  | 60 |  | 
|---|
|  | 61 | /*! Value of pixel number at (theta,phi) */ | 
|---|
|  | 62 | virtual T& PixValSph(double theta, double phi) | 
|---|
|  | 63 | {return PixVal(PixIndexSph(theta,phi));} | 
|---|
|  | 64 | virtual T const& PixValSph(double theta, double phi) const | 
|---|
|  | 65 | {return PixVal(PixIndexSph(theta,phi));} | 
|---|
|  | 66 |  | 
|---|
|  | 67 | /*! Spherical coordinates of center of pixel number k */ | 
|---|
|  | 68 | virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const=0; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | /*! provides a integer characterizing the pixelization refinement | 
|---|
|  | 71 | (depending of the type of the map) | 
|---|
|  | 72 | */ | 
|---|
|  | 73 | virtual int_4 SizeIndex() const=0; | 
|---|
| [2290] | 74 | virtual string TypeOfMap() const =0; | 
|---|
| [764] | 75 |  | 
|---|
|  | 76 | /*! Pixel  (steradians) */ | 
|---|
|  | 77 | virtual double PixSolAngle(int_4 k) const =0; | 
|---|
|  | 78 |  | 
|---|
|  | 79 | /*! Setting blockdata to temporary (see ndatablock documentation) */ | 
|---|
|  | 80 | virtual void SetTemp(bool temp=false) const =0; | 
|---|
|  | 81 |  | 
|---|
|  | 82 |  | 
|---|
|  | 83 | /*! Overloading of () to access pixel number k. */ | 
|---|
|  | 84 | inline T& operator()(int_4 k) {return(PixVal(k));} | 
|---|
|  | 85 | inline T const& operator()(int_4 k) const {return(PixVal(k));} | 
|---|
|  | 86 |  | 
|---|
|  | 87 | // Overloading of () to access pixel at a sky position . | 
|---|
|  | 88 | inline T& operator()(const SpherePosition& spos) | 
|---|
|  | 89 | { return(PixVal(PixIndex(spos))); } | 
|---|
|  | 90 | inline T const& operator()(const SpherePosition& spos) const | 
|---|
|  | 91 | { return(PixVal(PixIndex(spos))); } | 
|---|
|  | 92 |  | 
|---|
|  | 93 |  | 
|---|
|  | 94 | // Note : no overloading of (double,double) to access pixel (theta,phi). | 
|---|
|  | 95 | // overloading of (double,double) in SphericalMap | 
|---|
|  | 96 | // overloading of (int,int)     in CartesianMap | 
|---|
|  | 97 |  | 
|---|
|  | 98 | /*! Setting pixel values to a constant */ | 
|---|
|  | 99 | virtual T SetPixels(T v); | 
|---|
| [1419] | 100 | PixelMap<T>& SetT(T v); | 
|---|
|  | 101 | //inline T operator = (T v) { return(SetPixels(v)); } | 
|---|
|  | 102 | inline PixelMap<T>& operator = (T v) { return(SetT(v)); } | 
|---|
| [764] | 103 |  | 
|---|
| [2973] | 104 | //! Ascii print of synthetic information about the pixelmap on stream os | 
|---|
|  | 105 | virtual void  Show(ostream& os) const; | 
|---|
|  | 106 | //! Show information on \b cout | 
|---|
|  | 107 | inline  void  Show() const { Show(cout); } | 
|---|
| [764] | 108 |  | 
|---|
|  | 109 |  | 
|---|
| [2973] | 110 | //! Return a reference to the associated DVList object | 
|---|
| [764] | 111 | DVList& Info() | 
|---|
|  | 112 | { | 
|---|
|  | 113 | if (mInfo_ == NULL)  mInfo_ = new DVList; | 
|---|
|  | 114 | return(*mInfo_); | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 | const DVList*  ptrInfo() const | 
|---|
|  | 118 | { | 
|---|
|  | 119 | return mInfo_; | 
|---|
|  | 120 | } | 
|---|
|  | 121 |  | 
|---|
|  | 122 | protected : | 
|---|
|  | 123 | SphereCoordSys *cs_;   // Coordinate system used in the map | 
|---|
|  | 124 | DVList* mInfo_;        // Infos (variables) attachees | 
|---|
|  | 125 | }; | 
|---|
|  | 126 |  | 
|---|
| [2973] | 127 | template <class T> | 
|---|
|  | 128 | inline ostream& operator << (ostream& s,  const PixelMap<T> & a) | 
|---|
|  | 129 | { a.Show(s);   return(s); } | 
|---|
| [764] | 130 |  | 
|---|
|  | 131 | template <class T> | 
|---|
|  | 132 | int_4 PixelMap<T>::PixIndex(const SpherePosition& spos) | 
|---|
|  | 133 | { | 
|---|
|  | 134 | UnitVector v = spos.Transform(*cs_); | 
|---|
|  | 135 | return(PixIndexSph(v.Theta(), v.Phi())); | 
|---|
|  | 136 | } | 
|---|
|  | 137 |  | 
|---|
|  | 138 | template <class T> | 
|---|
|  | 139 | bool PixelMap<T>::Contains(const SpherePosition& spos) const | 
|---|
|  | 140 | { | 
|---|
|  | 141 | UnitVector v = spos.Transform(*cs_); | 
|---|
|  | 142 | return(ContainsSph(v.Theta(), v.Phi())); | 
|---|
|  | 143 | } | 
|---|
|  | 144 | template <class T> | 
|---|
|  | 145 | T PixelMap<T>::SetPixels(T v) | 
|---|
|  | 146 | { | 
|---|
|  | 147 | int k; | 
|---|
|  | 148 | for(k=0; k<NbPixels(); k++) PixVal(k) = v; | 
|---|
|  | 149 | return(v); | 
|---|
|  | 150 | } | 
|---|
| [1419] | 151 | template <class T> | 
|---|
|  | 152 | PixelMap<T>& PixelMap<T>::SetT(T v) | 
|---|
|  | 153 | { | 
|---|
|  | 154 | int k; | 
|---|
|  | 155 | for(k=0; k<NbPixels(); k++) PixVal(k) = v; | 
|---|
|  | 156 | return(*this); | 
|---|
|  | 157 | } | 
|---|
| [764] | 158 |  | 
|---|
| [2973] | 159 | template <class T> | 
|---|
|  | 160 | void PixelMap<T>::Show(ostream& os) const | 
|---|
|  | 161 | { | 
|---|
|  | 162 | os << "PixelMap<T>::Show() class: " << typeid(*this).name() | 
|---|
| [2978] | 163 | << " T= " << DataTypeInfo<T>::getTypeName() | 
|---|
|  | 164 | << " TypeOfMap= " << TypeOfMap() << endl; | 
|---|
| [2973] | 165 | double solang = 0.; | 
|---|
|  | 166 | if (NbPixels() > 0) solang = PixSolAngle(NbPixels()/2); | 
|---|
|  | 167 | double frac = NbPixels()*solang*100/(4.*M_PI); | 
|---|
|  | 168 | if (frac > 100.) frac = 100.; | 
|---|
|  | 169 | os << " NbPixels()= " << NbPixels() << " ResolArcMin ~=" | 
|---|
|  | 170 | << Angle(sqrt(solang)).ToArcMin() << " SphereFrac ~= " | 
|---|
|  | 171 | << frac << " % of 4Pi" << endl; | 
|---|
|  | 172 | } | 
|---|
| [908] | 173 |  | 
|---|
| [2973] | 174 |  | 
|---|
| [908] | 175 | } // Fin du namespace | 
|---|
|  | 176 |  | 
|---|
| [764] | 177 | #endif | 
|---|