| 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"
 | 
|---|
| 8 | #include <iostream.h>
 | 
|---|
| 9 | 
 | 
|---|
| 10 | //! General map of pixels on part of sphere or whole sphere
 | 
|---|
| 11 | /*! Class hierarchy :
 | 
|---|
| 12 | \verbatim
 | 
|---|
| 13 |    PixelMap
 | 
|---|
| 14 |      SphericalMap
 | 
|---|
| 15 |          SphereThetaPhi
 | 
|---|
| 16 |          SphereGorski
 | 
|---|
| 17 |          SphereIco
 | 
|---|
| 18 |       LocalMap
 | 
|---|
| 19 | \endverbatim
 | 
|---|
| 20 | */
 | 
|---|
| 21 | template<class T>
 | 
|---|
| 22 | class PixelMap  : public AnyDataObj 
 | 
|---|
| 23 | {
 | 
|---|
| 24 | 
 | 
|---|
| 25 | public:
 | 
|---|
| 26 |   
 | 
|---|
| 27 |               PixelMap(SphereCoordSys* cs = NULL) : mInfo_(NULL) 
 | 
|---|
| 28 |                     { if (cs) cs_ = cs; else cs_ = new SphereCoordSys; }
 | 
|---|
| 29 | virtual       ~PixelMap() 
 | 
|---|
| 30 |                     { if (mInfo_) delete mInfo_; if (cs_) delete cs_; }
 | 
|---|
| 31 | 
 | 
|---|
| 32 | // Set/Change/Get the coordinate system
 | 
|---|
| 33 | virtual void  SetCoordSys(SphereCoordSys* cs)
 | 
|---|
| 34 |                     { if (cs) { delete cs_;  cs_ = cs; } }
 | 
|---|
| 35 | inline SphereCoordSys* GetCoordSys() const { return(cs_); }
 | 
|---|
| 36 | 
 | 
|---|
| 37 | /*! Number of pixels */
 | 
|---|
| 38 | virtual int_4 NbPixels() const=0;
 | 
|---|
| 39 |    
 | 
|---|
| 40 | /*! Value of pixel number k */
 | 
|---|
| 41 | virtual T& PixVal(int_4 k)=0;
 | 
|---|
| 42 | virtual T const& PixVal(int_4 k) const=0;
 | 
|---|
| 43 | 
 | 
|---|
| 44 | // Map s coverage
 | 
|---|
| 45 | virtual bool ContainsSph(double theta, double phi) const=0;
 | 
|---|
| 46 | virtual bool Contains(const SpherePosition& spos) const;
 | 
|---|
| 47 | 
 | 
|---|
| 48 | /*! Index of pixel at (theta,phi) */
 | 
|---|
| 49 | virtual int_4 PixIndexSph(double theta, double phi) const=0;
 | 
|---|
| 50 | // Index of pixel at a sky-position 
 | 
|---|
| 51 | virtual int_4 PixIndex(const SpherePosition& spos);
 | 
|---|
| 52 | 
 | 
|---|
| 53 | /*! Value of pixel number at (theta,phi) */
 | 
|---|
| 54 | virtual T& PixValSph(double theta, double phi)
 | 
|---|
| 55 |                            {return PixVal(PixIndexSph(theta,phi));}
 | 
|---|
| 56 | virtual T const& PixValSph(double theta, double phi) const
 | 
|---|
| 57 |                            {return PixVal(PixIndexSph(theta,phi));}
 | 
|---|
| 58 | 
 | 
|---|
| 59 | /*! Spherical coordinates of center of pixel number k */
 | 
|---|
| 60 | virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const=0;
 | 
|---|
| 61 | 
 | 
|---|
| 62 | /*! provides a integer characterizing the pixelization refinement 
 | 
|---|
| 63 |  (depending of the type of the map) 
 | 
|---|
| 64 | */             
 | 
|---|
| 65 | virtual int_4 SizeIndex() const=0;
 | 
|---|
| 66 | virtual char* TypeOfMap() const =0;
 | 
|---|
| 67 | 
 | 
|---|
| 68 | /*! Pixel  (steradians) */
 | 
|---|
| 69 | virtual double PixSolAngle(int_4 k) const =0; 
 | 
|---|
| 70 | 
 | 
|---|
| 71 | /*! Setting blockdata to temporary (see ndatablock documentation) */
 | 
|---|
| 72 | virtual void SetTemp(bool temp=false) const =0;
 | 
|---|
| 73 | 
 | 
|---|
| 74 | 
 | 
|---|
| 75 | /*! Overloading of () to access pixel number k. */
 | 
|---|
| 76 | inline T& operator()(int_4 k) {return(PixVal(k));}
 | 
|---|
| 77 | inline T const& operator()(int_4 k) const {return(PixVal(k));}
 | 
|---|
| 78 | 
 | 
|---|
| 79 | // Overloading of () to access pixel at a sky position .
 | 
|---|
| 80 | inline T& operator()(const SpherePosition& spos) 
 | 
|---|
| 81 |                      { return(PixVal(PixIndex(spos))); }
 | 
|---|
| 82 | inline T const& operator()(const SpherePosition& spos) const 
 | 
|---|
| 83 |                      { return(PixVal(PixIndex(spos))); }
 | 
|---|
| 84 | 
 | 
|---|
| 85 | 
 | 
|---|
| 86 | // Note : no overloading of (double,double) to access pixel (theta,phi).
 | 
|---|
| 87 | // overloading of (double,double) in SphericalMap
 | 
|---|
| 88 | // overloading of (int,int)     in CartesianMap
 | 
|---|
| 89 | 
 | 
|---|
| 90 | /*! Setting pixel values to a constant */
 | 
|---|
| 91 | virtual T SetPixels(T v);
 | 
|---|
| 92 | inline T operator = (T v) { return(SetPixels(v)); }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | 
 | 
|---|
| 95 |                      
 | 
|---|
| 96 | //++
 | 
|---|
| 97 | DVList& Info()
 | 
|---|
| 98 | //
 | 
|---|
| 99 | // Renvoie une reference sur l''objet DVList Associe
 | 
|---|
| 100 | //--
 | 
|---|
| 101 |   {
 | 
|---|
| 102 |     if (mInfo_ == NULL)  mInfo_ = new DVList;
 | 
|---|
| 103 |     return(*mInfo_);
 | 
|---|
| 104 |   }
 | 
|---|
| 105 | 
 | 
|---|
| 106 | const DVList*  ptrInfo() const
 | 
|---|
| 107 |   {
 | 
|---|
| 108 |     return mInfo_;
 | 
|---|
| 109 |   }
 | 
|---|
| 110 | 
 | 
|---|
| 111 | protected :
 | 
|---|
| 112 |     SphereCoordSys *cs_;   // Coordinate system used in the map
 | 
|---|
| 113 |     DVList* mInfo_;        // Infos (variables) attachees 
 | 
|---|
| 114 | };
 | 
|---|
| 115 | 
 | 
|---|
| 116 | 
 | 
|---|
| 117 | template <class T>
 | 
|---|
| 118 | int_4 PixelMap<T>::PixIndex(const SpherePosition& spos)
 | 
|---|
| 119 | {
 | 
|---|
| 120 | UnitVector v = spos.Transform(*cs_);
 | 
|---|
| 121 | return(PixIndexSph(v.Theta(), v.Phi()));
 | 
|---|
| 122 | }
 | 
|---|
| 123 | 
 | 
|---|
| 124 | template <class T>
 | 
|---|
| 125 | bool PixelMap<T>::Contains(const SpherePosition& spos) const
 | 
|---|
| 126 | {
 | 
|---|
| 127 | UnitVector v = spos.Transform(*cs_);
 | 
|---|
| 128 | return(ContainsSph(v.Theta(), v.Phi()));
 | 
|---|
| 129 | }
 | 
|---|
| 130 | template <class T>
 | 
|---|
| 131 | T PixelMap<T>::SetPixels(T v)
 | 
|---|
| 132 | {
 | 
|---|
| 133 | int k;
 | 
|---|
| 134 | for(k=0; k<NbPixels(); k++) PixVal(k) = v;
 | 
|---|
| 135 | return(v);
 | 
|---|
| 136 | }
 | 
|---|
| 137 | 
 | 
|---|
| 138 | #endif
 | 
|---|