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