[518] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
[228] | 2 | #ifndef LOCALMAP_SEEN
|
---|
| 3 | #define LOCALMAP_SEEN
|
---|
| 4 |
|
---|
| 5 | #include "pixelmap.h"
|
---|
| 6 | #include "sphericalmap.h"
|
---|
[470] | 7 | #include "ndatablock.h"
|
---|
[228] | 8 |
|
---|
[470] | 9 | #include "anydataobj.h"
|
---|
| 10 | #include "ppersist.h"
|
---|
| 11 |
|
---|
[568] | 12 | //! A local map of a region of the sky, in cartesian coordinates.
|
---|
| 13 | /*! A local map has an origin in (theta0, phi0), mapped to pixel(x0, y0)
|
---|
| 14 | (x0, y0 might be outside of this local map)
|
---|
| 15 | default value of (x0, y0) is middle of the map, center of pixel(nx/2, ny/2)
|
---|
| 16 | A local map is a 2 dimensional array, with i as column index and j
|
---|
| 17 | as row index. The map is supposed to lie on a plan tangent to the
|
---|
| 18 | celestial sphere in a point whose coordinates are (x0,y0) on the local
|
---|
| 19 | map and (theta0, phi0) on the sphere. The range of the map is defined
|
---|
| 20 | by two values of angles covered respectively by all the pixels in
|
---|
| 21 | x direction and all the pixels in y direction (SetSize()).
|
---|
| 22 |
|
---|
| 23 | A "reference plane" is considered : this plane is tangent to the
|
---|
| 24 | celestial sphere in a point with angles theta=Pi/2 and phi=0. This
|
---|
| 25 | point is the origine of coordinates is of the reference plane. The
|
---|
| 26 | x-axis is the tangent parallel to the equatorial line and oriented
|
---|
| 27 | toward the increasing phi's ; the y-axis is parallel to the meridian
|
---|
| 28 | line and oriented toward the north pole.
|
---|
| 29 |
|
---|
| 30 | Internally, a map is first defined within this reference plane and
|
---|
| 31 | tranported until the point (theta0, phi0) in such a way that both
|
---|
| 32 | axes are kept parallel to meridian and parallel lines of the sphere.
|
---|
| 33 | The user can define its own map with axes rotated with respect to
|
---|
| 34 | reference axes (this rotation is characterized by angle between
|
---|
| 35 | the local parallel line and the wanted x-axis-- see method
|
---|
| 36 | SetOrigin(...))
|
---|
| 37 | */
|
---|
[228] | 38 | //
|
---|
| 39 | // la carte est consideree comme un tableau a deux indices i et j, i etant
|
---|
| 40 | // indice de colonne et j indice de ligne. La carte est supposee resider
|
---|
| 41 | // dans un plan tangent, dont le point de tangence est repere (x0,y0) dans
|
---|
[470] | 42 | // la carte et (theta0, phi0) sur la sphere celeste. L extension de la
|
---|
[228] | 43 | // carte est definie par les valeurs de deux angles couverts respectivement
|
---|
| 44 | // par la totalite des pixels en x de la carte et la totalite des pixels
|
---|
| 45 | // en y. (SetSize()).
|
---|
| 46 | // On considere un "plan de reference" : plan tangent a la sphere celeste
|
---|
[470] | 47 | // aux angles theta=Pi/2 et phi=0. Dans ce plan L origine des coordonnees
|
---|
| 48 | // est le point de tangence. L axe Ox est la tangente parallele a
|
---|
| 49 | // lequateur, dirige vers les phi croissants, l axe Oy est parallele
|
---|
[228] | 50 | // au meridien, dirige vers le pole nord.
|
---|
| 51 | // De maniere interne a la classe une carte est definie dans ce plan de
|
---|
[470] | 52 | // reference et transportee jusqu au point (theta0, phi0) de sorte que les // axes restent paralleles aux meridiens et paralleles. L utilisateur peut
|
---|
[228] | 53 | // definir sa carte selon un repere en rotation par rapport au repere de
|
---|
[470] | 54 | // reference (par l angle entre le parallele et l axe Ox souhaite --
|
---|
[228] | 55 | // methode SetOrigin(...))
|
---|
| 56 |
|
---|
| 57 |
|
---|
[470] | 58 | // ***************** Class LocalMap *****************************
|
---|
[228] | 59 |
|
---|
[470] | 60 | template<class T>
|
---|
[592] | 61 | class LocalMap : public PixelMap<T>
|
---|
[470] | 62 | {
|
---|
[228] | 63 |
|
---|
[470] | 64 | public:
|
---|
[228] | 65 |
|
---|
[470] | 66 | LocalMap();
|
---|
[473] | 67 | LocalMap(int nx, int ny);
|
---|
[574] | 68 | LocalMap(const LocalMap<T>& lm, bool share=false);
|
---|
[470] | 69 | virtual ~LocalMap();
|
---|
[228] | 70 |
|
---|
[470] | 71 | // ---------- Overloading of () to access pixel number k ----
|
---|
[228] | 72 |
|
---|
[473] | 73 | inline T& operator()(int k) {return(PixVal(k));}
|
---|
| 74 | inline T const& operator()(int k) const {return(PixVal(k));}
|
---|
[470] | 75 | inline T& operator()(int ix, int iy) {return PixVal(iy*nSzX_+ix);};
|
---|
| 76 | inline T const& operator()(int ix, int iy) const {return PixVal(iy*nSzX_+ix);};
|
---|
[228] | 77 |
|
---|
[470] | 78 | // ---------- Definition of PixelMap abstract methods -------
|
---|
| 79 |
|
---|
| 80 | /* return/set the number of pixels */
|
---|
[568] | 81 | /*! Return number of pixels */
|
---|
[473] | 82 | virtual int NbPixels() const;
|
---|
| 83 | inline void setNbPixels(int n) {nPix_= n;}
|
---|
[470] | 84 |
|
---|
| 85 | /* return the value of pixel number k */
|
---|
[568] | 86 | /*! Return value of pixel with index k */
|
---|
[473] | 87 | virtual T& PixVal(int k);
|
---|
[568] | 88 | /*! const version of previous method */
|
---|
[473] | 89 | virtual T const& PixVal(int k) const;
|
---|
[470] | 90 |
|
---|
[518] | 91 | /* Return true if teta,phi in map */
|
---|
| 92 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
[470] | 93 | /* return the index of pixel at (theta,phi) */
|
---|
[568] | 94 | /*! Return index of the pixel with spherical coordinates (theta,phi) */
|
---|
[473] | 95 | virtual int PixIndexSph(double theta,double phi) const;
|
---|
[228] | 96 |
|
---|
[470] | 97 | /* return the spherical coordinates of center of pixel number k */
|
---|
[568] | 98 | /*! Return (theta, phi) coordinates of pixel with index k */
|
---|
[473] | 99 | virtual void PixThetaPhi(int k,double& theta,double& phi) const;
|
---|
[228] | 100 |
|
---|
[574] | 101 | /*! Set all pixels to value v */
|
---|
| 102 | virtual T SetPixels(T v);
|
---|
| 103 |
|
---|
[470] | 104 | /* return the Pixel Solid angle (steradians) */
|
---|
[568] | 105 | /*! Pixel Solid angle (steradians)
|
---|
| 106 |
|
---|
| 107 | All the pixels have not necessarly the same size in (theta, phi)
|
---|
| 108 | because of the projection scheme which is not yet fixed.
|
---|
| 109 | */
|
---|
[473] | 110 | virtual double PixSolAngle(int k) const;
|
---|
[228] | 111 |
|
---|
[470] | 112 | // ---------- Specific methods ------------------------------
|
---|
[228] | 113 |
|
---|
[568] | 114 | /*! Resize storage area for pixels */
|
---|
[473] | 115 | void ReSize(int nx, int ny);
|
---|
[228] | 116 |
|
---|
[470] | 117 | inline virtual char* TypeOfMap() const {return "LOCAL";};
|
---|
| 118 |
|
---|
| 119 | /* Origin (with angle between x axis and phi axis, in degrees) x0,y0 the default: middle of map*/
|
---|
[568] | 120 | /*! set the referential of the map (angles in degrees)
|
---|
| 121 |
|
---|
| 122 | (default x0=siz_x/2, y0=siz_y/2)
|
---|
| 123 | */
|
---|
[473] | 124 | virtual void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
|
---|
[568] | 125 | /*! set the referential of the map (angles in degrees) */
|
---|
[473] | 126 | virtual void SetOrigin(double theta,double phi,int x0,int y0,double angle=0.);
|
---|
[228] | 127 |
|
---|
[470] | 128 | /* Pixel size (degres) */
|
---|
[568] | 129 | /*! angle range of tthe map (angles in degrees) */
|
---|
[473] | 130 | virtual void SetSize(double angleX,double angleY);
|
---|
[228] | 131 |
|
---|
[470] | 132 | /* Check to see if the local mapping is done */
|
---|
| 133 | inline bool LocalMap_isDone() const {return(originFlag_ && extensFlag_);};
|
---|
[228] | 134 |
|
---|
[568] | 135 | /*! Projection to a spherical map */
|
---|
[470] | 136 | virtual void Project(SphericalMap<T>& sphere) const;
|
---|
[228] | 137 |
|
---|
[470] | 138 | /* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere.
|
---|
| 139 | -> static method, or separate class */
|
---|
| 140 |
|
---|
| 141 | /* provides a integer characterizing the pixelization refinement (here : number of pixels) */
|
---|
[473] | 142 | inline virtual int SizeIndex() const {return(nPix_);}
|
---|
| 143 | inline int Size_x() const {return nSzX_;}
|
---|
[592] | 144 | inline int XSize() const {return nSzX_;}
|
---|
[473] | 145 | inline void setSize_x(int n) {nSzX_= n;}
|
---|
| 146 | inline int Size_y() const {return nSzY_;}
|
---|
[592] | 147 | inline int YSize() const {return nSzY_;}
|
---|
[473] | 148 | inline void setSize_y(int n) {nSzY_= n;}
|
---|
[228] | 149 |
|
---|
[473] | 150 | inline void Origin(double& theta,double& phi,int& x0,int& y0,double& angle) const {theta= theta0_; phi= phi0_; x0= x0_; y0= y0_;angle= angle_;}
|
---|
[228] | 151 |
|
---|
[473] | 152 | inline void Aperture(double& anglex,double& angley) const {anglex= angleX_; angley= angleY_;}
|
---|
[470] | 153 |
|
---|
| 154 | /* retourne le pointeur vers/remplit le vecteur des contenus des pixels */
|
---|
| 155 | inline const NDataBlock<T>* getDataBlock() const {return (&pixels_);}
|
---|
[473] | 156 | inline void setDataBlock(T* data, int n) {pixels_.FillFrom(n,data);}
|
---|
[470] | 157 |
|
---|
[604] | 158 | /* Acces to the DataBlock */
|
---|
| 159 | inline NDataBlock<T>& DataBlock() {return pixels_;}
|
---|
| 160 | inline const NDataBlock<T>& DataBlock() const {return pixels_;}
|
---|
| 161 |
|
---|
[470] | 162 | /* impression */
|
---|
| 163 | void print(ostream& os) const;
|
---|
| 164 |
|
---|
| 165 | // ---------- Méthodes internes -----------------------------
|
---|
[228] | 166 |
|
---|
| 167 | private :
|
---|
| 168 |
|
---|
[470] | 169 | void InitNul();
|
---|
[568] | 170 | /*! Return 2 indices corresponding to the pixel number k */
|
---|
[473] | 171 | void Getij(int k,int& i,int& j) const;
|
---|
[568] | 172 | /*! Transform a pair of coordinates (theta, phi) given in
|
---|
| 173 | reference coordinates into map coordinates
|
---|
| 174 | */
|
---|
[473] | 175 | void ReferenceToUser(double& theta,double& phi) const;
|
---|
[568] | 176 | /*! Transform a pair of coordinates (theta, phi) given in
|
---|
| 177 | map coordinates into reference coordinates
|
---|
| 178 | */
|
---|
[473] | 179 | void UserToReference(double& theta,double& phi) const;
|
---|
[568] | 180 | /*! Given coordinates in pixel units in the REFERENCE PLANE, return
|
---|
| 181 | (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.
|
---|
| 182 | */
|
---|
[473] | 183 | void PixProjToAngle(double x,double y,double& theta,double& phi) const;
|
---|
[568] | 184 | /*! Given coordinates (theta, phi) in "absolute" referential
|
---|
| 185 | theta=pi/2 ,phi=0 return pixel indices (i,j) in the REFERENCE PLANE.
|
---|
| 186 | */
|
---|
[473] | 187 | void AngleProjToPix(double theta,double phi,double& x,double& y) const;
|
---|
[228] | 188 |
|
---|
[470] | 189 | // ---------- Variables internes ----------------------------
|
---|
| 190 |
|
---|
[473] | 191 | int nSzX_;
|
---|
| 192 | int nSzY_;
|
---|
| 193 | int nPix_;
|
---|
[470] | 194 | bool originFlag_;
|
---|
| 195 | bool extensFlag_;
|
---|
[473] | 196 | int x0_;
|
---|
| 197 | int y0_;
|
---|
| 198 | double theta0_;
|
---|
| 199 | double phi0_;
|
---|
| 200 | double angle_;
|
---|
| 201 | double cos_angle_;
|
---|
| 202 | double sin_angle_;
|
---|
| 203 | double angleX_;
|
---|
| 204 | double angleY_;
|
---|
| 205 | double tgAngleX_;
|
---|
| 206 | double tgAngleY_;
|
---|
[470] | 207 | NDataBlock<T> pixels_;
|
---|
[228] | 208 | };
|
---|
| 209 |
|
---|
[470] | 210 | // ------------- Classe pour la gestion de persistance --
|
---|
[568] | 211 | //! Delegated objects for persitance management
|
---|
[470] | 212 | template <class T>
|
---|
| 213 | class FIO_LocalMap : public PPersist
|
---|
| 214 | {
|
---|
| 215 |
|
---|
| 216 | public:
|
---|
| 217 |
|
---|
| 218 | FIO_LocalMap();
|
---|
| 219 | FIO_LocalMap(string const & filename);
|
---|
| 220 | FIO_LocalMap(const LocalMap<T>& obj);
|
---|
| 221 | FIO_LocalMap(LocalMap<T>* obj);
|
---|
| 222 | virtual ~FIO_LocalMap();
|
---|
| 223 | virtual AnyDataObj* DataObj();
|
---|
| 224 | inline operator LocalMap<T>() { return(*dobj); }
|
---|
[568] | 225 | //inline LocalMap<T> getObj() { return(*dobj); }
|
---|
[470] | 226 |
|
---|
| 227 | protected :
|
---|
| 228 |
|
---|
| 229 | virtual void ReadSelf(PInPersist&);
|
---|
| 230 | virtual void WriteSelf(POutPersist&) const;
|
---|
| 231 | LocalMap<T>* dobj;
|
---|
| 232 | bool ownobj;
|
---|
| 233 | };
|
---|
| 234 |
|
---|
[228] | 235 | #endif
|
---|