source: Sophya/trunk/SophyaLib/Samba/localmap.h@ 748

Last change on this file since 748 was 727, checked in by ansari, 26 years ago

nouvelle gestion thetaslices

File size: 8.6 KB
Line 
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/*! 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*/
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
42// la carte et (theta0, phi0) sur la sphere celeste. L extension de la
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
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
50// au meridien, dirige vers le pole nord.
51// De maniere interne a la classe une carte est definie dans ce plan de
52// reference et transportee jusqu au point (theta0, phi0) de sorte que les // axes restent paralleles aux meridiens et paralleles. L utilisateur peut
53// definir sa carte selon un repere en rotation par rapport au repere de
54// reference (par l angle entre le parallele et l axe Ox souhaite --
55// methode SetOrigin(...))
56
57
58// ***************** Class LocalMap *****************************
59
60template<class T>
61class LocalMap : public PixelMap<T>
62{
63
64public:
65
66LocalMap();
67LocalMap(int_4 nx, int_4 ny);
68LocalMap(const LocalMap<T>& lm, bool share=false);
69virtual ~LocalMap();
70
71/*! Setting blockdata to temporary (see ndatablock documentation) */
72inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);};
73
74
75// ---------- Overloading of () to access pixel number k ----
76
77inline T& operator()(int_4 k) {return(PixVal(k));}
78inline T const& operator()(int_4 k) const {return(PixVal(k));}
79inline T& operator()(int_4 ix, int_4 iy) {return PixVal(iy*nSzX_+ix);};
80inline T const& operator()(int_4 ix, int_4 iy) const {return PixVal(iy*nSzX_+ix);};
81
82// ---------- Definition of PixelMap abstract methods -------
83
84/* return/set the number of pixels */
85/*! Return number of pixels */
86virtual int_4 NbPixels() const; // D.Y. int change en int_4 rationalisation Mac
87
88/* return the value of pixel number k */
89/*! Return value of pixel with index k */
90virtual T& PixVal(int_4 k);
91/*! const version of previous method */
92virtual T const& PixVal(int_4 k) const;
93
94/* Return true if teta,phi in map */
95virtual bool ContainsSph(double theta, double phi) const;
96/* return the index of pixel at (theta,phi) */
97/*! Return index of the pixel with spherical coordinates (theta,phi) */
98virtual int_4 PixIndexSph(double theta,double phi) const;
99
100/* return the spherical coordinates of center of pixel number k */
101/*! Return (theta, phi) coordinates of pixel with index k */
102virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const;
103
104/*! Set all pixels to value v */
105virtual T SetPixels(T v);
106
107/* return the Pixel Solid angle (steradians) */
108/*! Pixel Solid angle (steradians)
109
110 All the pixels have not necessarly the same size in (theta, phi)
111 because of the projection scheme which is not yet fixed.
112*/
113virtual double PixSolAngle(int_4 k) const;
114
115// ---------- Specific methods ------------------------------
116
117/*! Resize storage area for pixels */
118void ReSize(int_4 nx, int_4 ny);
119
120inline virtual char* TypeOfMap() const {return "LOCAL";};
121
122/* Origin (with angle between x axis and phi axis, in degrees) x0,y0 the default: middle of map*/
123/*! set the referential of the map (angles in degrees)
124
125 (default x0=siz_x/2, y0=siz_y/2)
126*/
127virtual void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
128/*! set the referential of the map (angles in degrees) */
129virtual void SetOrigin(double theta,double phi,int_4 x0,int_4 y0,double angle=0.);
130
131/* Pixel size (degres) */
132/*! angle range of tthe map (angles in degrees) */
133virtual void SetSize(double angleX,double angleY);
134
135/* Check to see if the local mapping is done */
136inline bool LocalMap_isDone() const {return(originFlag_ && extensFlag_);};
137
138/*! Projection to a spherical map */
139virtual void Project(SphericalMap<T>& sphere) const;
140
141/* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere.
142 -> static method, or separate class */
143
144/* provides a integer characterizing the pixelization refinement (here : number of pixels) */
145inline virtual int_4 SizeIndex() const {return(nPix_);}
146inline int_4 Size_x() const {return nSzX_;}
147inline int_4 XSize() const {return nSzX_;}
148inline int_4 Size_y() const {return nSzY_;}
149inline int_4 YSize() const {return nSzY_;}
150
151inline void Origin(double& theta,double& phi,int_4& x0,int_4& y0,double& angle) const {theta= theta0_; phi= phi0_; x0= x0_; y0= y0_;angle= angle_;}
152
153inline void Aperture(double& anglex,double& angley) const {anglex= angleX_; angley= angleY_;}
154
155
156/* Acces to the DataBlock */
157inline NDataBlock<T>& DataBlock() {return pixels_;}
158inline const NDataBlock<T>& DataBlock() const {return pixels_;}
159
160/* impression */
161void print(ostream& os) const;
162
163// ---------- Méthodes internes -----------------------------
164
165private :
166
167void InitNul();
168/*! Return 2 indices corresponding to the pixel number k */
169void Getij(int_4 k,int_4& i,int_4& j) const;
170/*! Transform a pair of coordinates (theta, phi) given in
171 reference coordinates into map coordinates
172*/
173void ReferenceToUser(double& theta,double& phi) const;
174/*! Transform a pair of coordinates (theta, phi) given in
175 map coordinates into reference coordinates
176*/
177void UserToReference(double& theta,double& phi) const;
178/*! Given coordinates in pixel units in the REFERENCE PLANE, return
179 (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.
180*/
181void PixProjToAngle(double x,double y,double& theta,double& phi) const;
182/*! Given coordinates (theta, phi) in "absolute" referential
183 theta=pi/2 ,phi=0 return pixel indices (i,j) in the REFERENCE PLANE.
184*/
185void AngleProjToPix(double theta,double phi,double& x,double& y) const;
186
187// ---------- Variables internes ----------------------------
188
189int_4 nSzX_;
190int_4 nSzY_;
191int_4 nPix_;
192bool originFlag_;
193bool extensFlag_;
194int_4 x0_;
195int_4 y0_;
196double theta0_;
197double phi0_;
198double angle_;
199double cos_angle_;
200double sin_angle_;
201double angleX_;
202double angleY_;
203double tgAngleX_;
204double tgAngleY_;
205NDataBlock<T> pixels_;
206};
207
208// ------------- Classe pour la gestion de persistance --
209//! Delegated objects for persitance management
210template <class T>
211class FIO_LocalMap : public PPersist
212{
213
214public:
215
216FIO_LocalMap();
217FIO_LocalMap(string const & filename);
218FIO_LocalMap(const LocalMap<T>& obj);
219FIO_LocalMap(LocalMap<T>* obj);
220virtual ~FIO_LocalMap();
221virtual AnyDataObj* DataObj();
222inline operator LocalMap<T>() { return(*dobj); }
223//inline LocalMap<T> getObj() { return(*dobj); }
224
225protected :
226
227virtual void ReadSelf(PInPersist&);
228virtual void WriteSelf(POutPersist&) const;
229LocalMap<T>* dobj;
230bool ownobj;
231};
232
233#endif
Note: See TracBrowser for help on using the repository browser.