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