1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | #ifndef LOCALMAP_SEEN
|
---|
3 | #define LOCALMAP_SEEN
|
---|
4 |
|
---|
5 | #include "pixelmap.h"
|
---|
6 | #include "sphericalmap.h"
|
---|
7 | #include "ndatablock.h"
|
---|
8 |
|
---|
9 | #include "anydataobj.h"
|
---|
10 | #include "ppersist.h"
|
---|
11 |
|
---|
12 | // A local map of a region of the sky, in cartesian coordinates.
|
---|
13 | // It 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 | //
|
---|
17 | // la carte est consideree comme un tableau a deux indices i et j, i etant
|
---|
18 | // indice de colonne et j indice de ligne. La carte est supposee resider
|
---|
19 | // dans un plan tangent, dont le point de tangence est repere (x0,y0) dans
|
---|
20 | // la carte et (theta0, phi0) sur la sphere celeste. L extension de la
|
---|
21 | // carte est definie par les valeurs de deux angles couverts respectivement
|
---|
22 | // par la totalite des pixels en x de la carte et la totalite des pixels
|
---|
23 | // en y. (SetSize()).
|
---|
24 | // On considere un "plan de reference" : plan tangent a la sphere celeste
|
---|
25 | // aux angles theta=Pi/2 et phi=0. Dans ce plan L origine des coordonnees
|
---|
26 | // est le point de tangence. L axe Ox est la tangente parallele a
|
---|
27 | // lequateur, dirige vers les phi croissants, l axe Oy est parallele
|
---|
28 | // au meridien, dirige vers le pole nord.
|
---|
29 | // De maniere interne a la classe une carte est definie dans ce plan de
|
---|
30 | // reference et transportee jusqu au point (theta0, phi0) de sorte que les // axes restent paralleles aux meridiens et paralleles. L utilisateur peut
|
---|
31 | // definir sa carte selon un repere en rotation par rapport au repere de
|
---|
32 | // reference (par l angle entre le parallele et l axe Ox souhaite --
|
---|
33 | // methode SetOrigin(...))
|
---|
34 |
|
---|
35 |
|
---|
36 | // ***************** Class LocalMap *****************************
|
---|
37 |
|
---|
38 | template<class T>
|
---|
39 | class LocalMap : public PixelMap<T>, public AnyDataObj
|
---|
40 | {
|
---|
41 |
|
---|
42 | public:
|
---|
43 |
|
---|
44 | LocalMap();
|
---|
45 | LocalMap(int nx, int ny);
|
---|
46 | LocalMap(const LocalMap<T>& lm);
|
---|
47 | virtual ~LocalMap();
|
---|
48 |
|
---|
49 | // ---------- Overloading of () to access pixel number k ----
|
---|
50 |
|
---|
51 | inline T& operator()(int k) {return(PixVal(k));}
|
---|
52 | inline T const& operator()(int k) const {return(PixVal(k));}
|
---|
53 | inline T& operator()(int ix, int iy) {return PixVal(iy*nSzX_+ix);};
|
---|
54 | inline T const& operator()(int ix, int iy) const {return PixVal(iy*nSzX_+ix);};
|
---|
55 |
|
---|
56 | // ---------- Definition of PixelMap abstract methods -------
|
---|
57 |
|
---|
58 | /* return/set the number of pixels */
|
---|
59 | virtual int NbPixels() const;
|
---|
60 | inline void setNbPixels(int n) {nPix_= n;}
|
---|
61 |
|
---|
62 | /* return the value of pixel number k */
|
---|
63 | virtual T& PixVal(int k);
|
---|
64 | virtual T const& PixVal(int k) const;
|
---|
65 |
|
---|
66 | /* Return true if teta,phi in map */
|
---|
67 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
68 | /* return the index of pixel at (theta,phi) */
|
---|
69 | virtual int PixIndexSph(double theta,double phi) const;
|
---|
70 |
|
---|
71 | /* return the spherical coordinates of center of pixel number k */
|
---|
72 | virtual void PixThetaPhi(int k,double& theta,double& phi) const;
|
---|
73 |
|
---|
74 | /* return the Pixel Solid angle (steradians) */
|
---|
75 | virtual double PixSolAngle(int k) const;
|
---|
76 |
|
---|
77 | // ---------- Specific methods ------------------------------
|
---|
78 |
|
---|
79 | void ReSize(int nx, int ny);
|
---|
80 |
|
---|
81 | inline virtual char* TypeOfMap() const {return "LOCAL";};
|
---|
82 |
|
---|
83 | /* Origin (with angle between x axis and phi axis, in degrees) x0,y0 the default: middle of map*/
|
---|
84 | virtual void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
|
---|
85 | virtual void SetOrigin(double theta,double phi,int x0,int y0,double angle=0.);
|
---|
86 |
|
---|
87 | /* Pixel size (degres) */
|
---|
88 | virtual void SetSize(double angleX,double angleY);
|
---|
89 |
|
---|
90 | /* Check to see if the local mapping is done */
|
---|
91 | inline bool LocalMap_isDone() const {return(originFlag_ && extensFlag_);};
|
---|
92 |
|
---|
93 | /* Projection to/from spherical map */
|
---|
94 | virtual void Project(SphericalMap<T>& sphere) const;
|
---|
95 |
|
---|
96 | /* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere.
|
---|
97 | -> static method, or separate class */
|
---|
98 |
|
---|
99 | /* provides a integer characterizing the pixelization refinement (here : number of pixels) */
|
---|
100 | inline virtual int SizeIndex() const {return(nPix_);}
|
---|
101 | inline int Size_x() const {return nSzX_;}
|
---|
102 | inline void setSize_x(int n) {nSzX_= n;}
|
---|
103 | inline int Size_y() const {return nSzY_;}
|
---|
104 | inline void setSize_y(int n) {nSzY_= n;}
|
---|
105 |
|
---|
106 | inline void Origin(double& theta,double& phi,int& x0,int& y0,double& angle) const {theta= theta0_; phi= phi0_; x0= x0_; y0= y0_;angle= angle_;}
|
---|
107 |
|
---|
108 | inline void Aperture(double& anglex,double& angley) const {anglex= angleX_; angley= angleY_;}
|
---|
109 |
|
---|
110 | /* retourne le pointeur vers/remplit le vecteur des contenus des pixels */
|
---|
111 | inline const NDataBlock<T>* getDataBlock() const {return (&pixels_);}
|
---|
112 | inline void setDataBlock(T* data, int n) {pixels_.FillFrom(n,data);}
|
---|
113 |
|
---|
114 | /* impression */
|
---|
115 | void print(ostream& os) const;
|
---|
116 |
|
---|
117 | // ---------- Méthodes internes -----------------------------
|
---|
118 |
|
---|
119 | private :
|
---|
120 |
|
---|
121 | void InitNul();
|
---|
122 | void Getij(int k,int& i,int& j) const;
|
---|
123 | void ReferenceToUser(double& theta,double& phi) const;
|
---|
124 | void UserToReference(double& theta,double& phi) const;
|
---|
125 | void PixProjToAngle(double x,double y,double& theta,double& phi) const;
|
---|
126 | void AngleProjToPix(double theta,double phi,double& x,double& y) const;
|
---|
127 |
|
---|
128 | // ---------- Variables internes ----------------------------
|
---|
129 |
|
---|
130 | int nSzX_;
|
---|
131 | int nSzY_;
|
---|
132 | int nPix_;
|
---|
133 | bool originFlag_;
|
---|
134 | bool extensFlag_;
|
---|
135 | int x0_;
|
---|
136 | int y0_;
|
---|
137 | double theta0_;
|
---|
138 | double phi0_;
|
---|
139 | double angle_;
|
---|
140 | double cos_angle_;
|
---|
141 | double sin_angle_;
|
---|
142 | double angleX_;
|
---|
143 | double angleY_;
|
---|
144 | double tgAngleX_;
|
---|
145 | double tgAngleY_;
|
---|
146 | NDataBlock<T> pixels_;
|
---|
147 | };
|
---|
148 |
|
---|
149 | // ------------- Classe pour la gestion de persistance --
|
---|
150 | template <class T>
|
---|
151 | class FIO_LocalMap : public PPersist
|
---|
152 | {
|
---|
153 |
|
---|
154 | public:
|
---|
155 |
|
---|
156 | FIO_LocalMap();
|
---|
157 | FIO_LocalMap(string const & filename);
|
---|
158 | FIO_LocalMap(const LocalMap<T>& obj);
|
---|
159 | FIO_LocalMap(LocalMap<T>* obj);
|
---|
160 | virtual ~FIO_LocalMap();
|
---|
161 | virtual AnyDataObj* DataObj();
|
---|
162 | inline operator LocalMap<T>() { return(*dobj); }
|
---|
163 | inline LocalMap<T> getObj() { return(*dobj); }
|
---|
164 |
|
---|
165 | protected :
|
---|
166 |
|
---|
167 | virtual void ReadSelf(PInPersist&);
|
---|
168 | virtual void WriteSelf(POutPersist&) const;
|
---|
169 | LocalMap<T>* dobj;
|
---|
170 | bool ownobj;
|
---|
171 | };
|
---|
172 |
|
---|
173 | #endif
|
---|