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 |
|
---|
13 |
|
---|
14 | // ***************** Class LocalMap *****************************
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 | namespace SOPHYA {
|
---|
19 |
|
---|
20 |
|
---|
21 | template <class T>
|
---|
22 | class FIO_LocalMap;
|
---|
23 |
|
---|
24 | template<class T>
|
---|
25 | class FITS_LocalMap;
|
---|
26 |
|
---|
27 | /* Class LocalMap */
|
---|
28 |
|
---|
29 |
|
---|
30 | template<class T>
|
---|
31 | class LocalMap : public PixelMap<T>
|
---|
32 | {
|
---|
33 |
|
---|
34 | // friend declaration for classes which handle persistence and FITS IO
|
---|
35 | friend class FIO_LocalMap<T>;
|
---|
36 | friend class FITS_LocalMap<T>;
|
---|
37 |
|
---|
38 | public:
|
---|
39 |
|
---|
40 | LocalMap();
|
---|
41 | LocalMap(int_4 nx, int_4 ny);
|
---|
42 | LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle=0.);
|
---|
43 | LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle=0.);
|
---|
44 | LocalMap(const LocalMap<T>& lm, bool share);
|
---|
45 | LocalMap(const LocalMap<T>& lm);
|
---|
46 | virtual ~LocalMap();
|
---|
47 |
|
---|
48 | inline virtual bool IsTemp(void) const { return pixels_.IsTemp();}
|
---|
49 |
|
---|
50 | /*! Setting blockdata to temporary (see ndatablock documentation) */
|
---|
51 | inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);};
|
---|
52 |
|
---|
53 |
|
---|
54 | // ---------- Overloading of () to access pixel number k ----
|
---|
55 |
|
---|
56 | inline T& operator()(int_4 k) {return(PixVal(k));}
|
---|
57 | inline T const& operator()(int_4 k) const {return(PixVal(k));}
|
---|
58 | inline T& operator()(int_4 ix, int_4 iy) {return PixVal(iy*nSzX_+ix);};
|
---|
59 | inline T const& operator()(int_4 ix, int_4 iy) const {return PixVal(iy*nSzX_+ix);};
|
---|
60 |
|
---|
61 | // Acces a un pixel
|
---|
62 | inline T& operator()(double theta,double phi) {return(PixValSph(theta,phi));};
|
---|
63 | inline T const& operator()(double theta,double phi) const {return(PixValSph(theta,phi));};
|
---|
64 |
|
---|
65 | // ---------- Definition of PixelMap abstract methods -------
|
---|
66 |
|
---|
67 | virtual int_4 NbPixels() const; // D.Y. int change en int_4 rationalisation Mac
|
---|
68 |
|
---|
69 | virtual T& PixVal(int_4 k);
|
---|
70 | virtual T const& PixVal(int_4 k) const;
|
---|
71 | //! if fg = true, will generate exceptions , when theta-phi out of range
|
---|
72 | inline void SetThrowExceptionWhenOutofMapFlag(bool fg = false) { exc_outofmap_ = fg; }
|
---|
73 |
|
---|
74 | //! true --> exceptions wil be active when theta-phi out of range
|
---|
75 | inline bool GetThrowExceptionWhenOutofMapFlag() { return exc_outofmap_; }
|
---|
76 |
|
---|
77 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
78 | //! return pixel number correspoinding to (theta,phi)
|
---|
79 | virtual int_4 PixIndexSph(double theta,double phi) const;
|
---|
80 |
|
---|
81 | //! return (theta,phi) correspoinding to pixel number k
|
---|
82 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const;
|
---|
83 |
|
---|
84 | //! set all pixel values equal to v
|
---|
85 | virtual T SetPixels(T v);
|
---|
86 |
|
---|
87 | // return the solid angle covered by pixel k (steradians)
|
---|
88 | virtual double PixSolAngle(int_4 k) const;
|
---|
89 |
|
---|
90 | // ---------- Specific methods ------------------------------
|
---|
91 |
|
---|
92 | void ReSize(int_4 nx, int_4 ny);
|
---|
93 |
|
---|
94 | void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
|
---|
95 | void SetOrigin(double theta,double phi,int_4 x0,int_4 y0,double angle=0.);
|
---|
96 | void SetSize(double angleX,double angleY);
|
---|
97 |
|
---|
98 | /*! \fn TypeOfMap()
|
---|
99 | return the string "LOCAL"
|
---|
100 | */
|
---|
101 | inline virtual string TypeOfMap() const {return string("LOCAL");};
|
---|
102 |
|
---|
103 |
|
---|
104 | /*! Check to see if the local mapping is done */
|
---|
105 | inline bool LocalMap_isDone() const {return( originSet_ && angleSized_ && pixelSized_);};
|
---|
106 |
|
---|
107 | void PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const;
|
---|
108 |
|
---|
109 |
|
---|
110 | void ProjectionToSphere(SphericalMap<T>&) const;
|
---|
111 |
|
---|
112 | /* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere.
|
---|
113 | -> static method, or separate class */
|
---|
114 |
|
---|
115 | /*! provides a integer characterizing the pixelization refinement (here : number of pixels) */
|
---|
116 | inline virtual int_4 SizeIndex() const {return(nPix_);}
|
---|
117 | inline int_4 Size_x() const {return nSzX_;}
|
---|
118 | inline int_4 Size_y() const {return nSzY_;}
|
---|
119 |
|
---|
120 | /* Je rajoute ces 2 fonctions inlines pour compatibilite d'interface
|
---|
121 | avec TArray - Reza 30/8/2000 */
|
---|
122 | inline int_4 SizeX() const {return nSzX_;}
|
---|
123 | inline int_4 SizeY() const {return nSzY_;}
|
---|
124 |
|
---|
125 | inline void Origin(double& theta,double& phi,int_4& x0,int_4& y0,double& angle) const {theta= thetaDegresC_; phi= phiDegresC_; x0= x0_; y0= y0_;angle= angleDegres_;}
|
---|
126 |
|
---|
127 | /*! total aperture in theta and phi, in degrees ( from SetSize() ) */
|
---|
128 | inline void Aperture(double& anglex,double& angley) const {anglex= angleDegresX_; angley= angleDegresY_;}
|
---|
129 |
|
---|
130 |
|
---|
131 | /* Acces to the DataBlock */
|
---|
132 | inline NDataBlock<T>& DataBlock() {return pixels_.DataBlock();}
|
---|
133 | inline const NDataBlock<T>& DataBlock() const {return pixels_.DataBlock();}
|
---|
134 |
|
---|
135 | /* Acces to the matrix */
|
---|
136 | //! access to matrix
|
---|
137 | /*!
|
---|
138 | \warning : a pixel is defined by the pair of a phi-like index
|
---|
139 | (x-axis) and a theta-like index (y-axis). The phi-like index denotes
|
---|
140 | the column number in the matrix ; the theta-like index denotes the
|
---|
141 | row number.
|
---|
142 | */
|
---|
143 | inline TMatrix<T>& Matrix() {return pixels_;}
|
---|
144 | inline const TMatrix<T>& Matrix() const {return pixels_;}
|
---|
145 |
|
---|
146 | /* impression */
|
---|
147 | void print(ostream& os) const;
|
---|
148 |
|
---|
149 | // Operations diverses = , +=, ...
|
---|
150 |
|
---|
151 |
|
---|
152 | virtual LocalMap<T>& Set(const LocalMap<T>& a);
|
---|
153 | inline LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);}
|
---|
154 |
|
---|
155 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
156 |
|
---|
157 | //! Fill LocalMap with all elements equal to \b x
|
---|
158 | virtual LocalMap<T>& SetT(T a);
|
---|
159 | inline LocalMap<T>& operator = (T a) {return SetT(a);}
|
---|
160 |
|
---|
161 | // Add \b x to all elements
|
---|
162 | virtual LocalMap<T>& Add(T a);
|
---|
163 | inline LocalMap<T>& operator += (T x) { return Add(x); }
|
---|
164 | // Substract \b x to all elements
|
---|
165 | virtual LocalMap<T>& Sub(T a,bool fginv=false);
|
---|
166 | inline LocalMap<T>& operator -= (T x) { return Sub(x); }
|
---|
167 | // Multiply all elements by \b x
|
---|
168 | virtual LocalMap<T>& Mul(T a);
|
---|
169 | inline LocalMap<T>& operator *= (T x) { return Mul(x); }
|
---|
170 | // Divide all elements by \b x
|
---|
171 | virtual LocalMap<T>& Div(T a);
|
---|
172 | inline LocalMap<T>& operator /= (T x) { return Div(x); }
|
---|
173 |
|
---|
174 | // A += -= (ajoute, soustrait element par element les deux spheres )
|
---|
175 | //! Operator LocalMap += LocalMap
|
---|
176 | virtual LocalMap<T>& AddElt(const LocalMap<T>& a);
|
---|
177 | inline LocalMap<T>& operator += (const LocalMap<T>& a) { return AddElt(a); }
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 | virtual LocalMap<T>& SubElt(const LocalMap<T>& a);
|
---|
182 | //! Operator LocalMap -= LocalMap
|
---|
183 | inline LocalMap<T>& operator -= (const LocalMap<T>& a) { return SubElt(a); }
|
---|
184 | // Multiplication, division element par element les deux LocalMap
|
---|
185 | virtual LocalMap<T>& MulElt(const LocalMap<T>& a);
|
---|
186 | inline LocalMap<T>& operator *= (const LocalMap<T>& a) { return MulElt(a); }
|
---|
187 | virtual LocalMap<T>& DivElt(const LocalMap<T>& a);
|
---|
188 | inline LocalMap<T>& operator /= (const LocalMap<T>& a) { return DivElt(a); }
|
---|
189 |
|
---|
190 |
|
---|
191 | void CloneOrShare(const LocalMap<T>& a);
|
---|
192 | void Share(const LocalMap<T>& a);
|
---|
193 | LocalMap<T>& CopyElt(const LocalMap<T>& a);
|
---|
194 |
|
---|
195 |
|
---|
196 | // ---------- Méthodes internes -----------------------------
|
---|
197 |
|
---|
198 | private :
|
---|
199 |
|
---|
200 | void InitNul();
|
---|
201 | void SetCoorC(double theta0, double phi0);
|
---|
202 | TMatrix<double> CalculMatricePassage();
|
---|
203 | void Getij(int_4 k,int_4& i,int_4& j) const;
|
---|
204 | void PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const;
|
---|
205 |
|
---|
206 | void recopierVariablesSimples(const LocalMap<T>& lm);
|
---|
207 |
|
---|
208 | void initializationError() const;
|
---|
209 |
|
---|
210 | // ---------- Variables internes ----------------------------
|
---|
211 |
|
---|
212 |
|
---|
213 | // variables suffisantes pour reconstruire l'objet
|
---|
214 |
|
---|
215 | bool pixelSized_;
|
---|
216 | bool angleSized_;
|
---|
217 | bool originSet_;
|
---|
218 |
|
---|
219 | int_4 nSzX_;
|
---|
220 | int_4 nSzY_;
|
---|
221 | double angleDegresX_;
|
---|
222 | double angleDegresY_;
|
---|
223 | double thetaDegresC_;
|
---|
224 | double phiDegresC_;
|
---|
225 | int_4 x0_;
|
---|
226 | int_4 y0_;
|
---|
227 | double angleDegres_;
|
---|
228 |
|
---|
229 |
|
---|
230 | // NDataBlock<T> pixels_;
|
---|
231 | TMatrix<T> pixels_;
|
---|
232 |
|
---|
233 |
|
---|
234 | // variables derivees (redondantes, precalculees pour ameliorer
|
---|
235 | // les performances)
|
---|
236 |
|
---|
237 | int_4 nPix_;
|
---|
238 |
|
---|
239 |
|
---|
240 | double thetaC_;
|
---|
241 | double phiC_;
|
---|
242 | double csthC_;
|
---|
243 | double snthC_;
|
---|
244 | double csphC_;
|
---|
245 | double snphC_;
|
---|
246 | double XC_;
|
---|
247 | double YC_;
|
---|
248 | double ZC_;
|
---|
249 |
|
---|
250 |
|
---|
251 | double angle_;
|
---|
252 | double cosAngle_;
|
---|
253 | double sinAngle_;
|
---|
254 | double deltaPhi_;
|
---|
255 | double deltaTheta_;
|
---|
256 |
|
---|
257 | bool exc_outofmap_;
|
---|
258 |
|
---|
259 |
|
---|
260 | };
|
---|
261 |
|
---|
262 | ////////////////////////////////////////////////////////////////
|
---|
263 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
264 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,T)
|
---|
265 | \brief Operator LocalMap = LocalMap + constant */
|
---|
266 | template <class T> inline LocalMap<T> operator + (const LocalMap<T>& a, T b)
|
---|
267 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
268 | result.Add(b); return result;}
|
---|
269 | /*! \ingroup SkyMap \fn operator+(T,const LocalMap<T>&)
|
---|
270 | \brief Operator LocalMap = constant + LocalMap */
|
---|
271 | template <class T> inline LocalMap<T> operator + (T b,const LocalMap<T>& a)
|
---|
272 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
273 | result.Add(b); return result;}
|
---|
274 |
|
---|
275 |
|
---|
276 | /*! \ingroup SkyMap\fn operator-(const LocalMap<T>&,T)
|
---|
277 | \brief Operator LocalMap = LocalMap - constant */
|
---|
278 | template <class T> inline LocalMap<T> operator - (const LocalMap<T>& a, T b)
|
---|
279 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
280 | result.Sub(b); return result;}
|
---|
281 |
|
---|
282 | /*! \ingroup \fn operator-(T,const LocalMap<T>&)
|
---|
283 | \brief Operator LocalMap = constant - LocalMap */
|
---|
284 | template <class T> inline LocalMap<T> operator - (T b,const LocalMap<T>& a)
|
---|
285 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
286 | result.Sub(b,true); return result;}
|
---|
287 |
|
---|
288 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,T)
|
---|
289 | \brief Operator LocalMap = LocalMap * constant */
|
---|
290 | template <class T> inline LocalMap<T> operator * (const LocalMap<T>& a, T b)
|
---|
291 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
292 | result.Mul(b); return result;}
|
---|
293 |
|
---|
294 | /*! \ingroup SkyMap \fn operator*(T,const LocalMap<T>&)
|
---|
295 | \brief Operator LocalMap = constant * LocalMap */
|
---|
296 | template <class T> inline LocalMap<T> operator * (T b,const LocalMap<T>& a)
|
---|
297 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
298 | result.Mul(b); return result;}
|
---|
299 |
|
---|
300 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,T)
|
---|
301 | \brief Operator LocalMap = LocalMap / constant */
|
---|
302 | template <class T> inline LocalMap<T> operator / (const LocalMap<T>& a, T b)
|
---|
303 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
304 | result.Div(b); return result;}
|
---|
305 |
|
---|
306 | /*! \ingroup SkyMap \fn operator/(T,const LocalMap<T>&)
|
---|
307 | \brief Operator LocalMap = constant / LocalMap */
|
---|
308 | template <class T> inline LocalMap<T> operator / (T b, const LocalMap<T>& a)
|
---|
309 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
310 | result.Div(b, true); return result;}
|
---|
311 |
|
---|
312 | ////////////////////////////////////////////////////////////////
|
---|
313 | // Surcharge d'operateurs C = A (+,-) B
|
---|
314 |
|
---|
315 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,const LocalMap<T>&)
|
---|
316 | \brief Operator LocalMap = LocalMap + LocalMap */
|
---|
317 | template <class T>
|
---|
318 | inline LocalMap<T> operator + (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
319 | { LocalMap<T> result; result.SetTemp(true);
|
---|
320 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
321 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
322 | return result; }
|
---|
323 |
|
---|
324 | /*! \ingroup SkyMap \fn operator-(const LocalMap<T>&,const LocalMap<T>&)
|
---|
325 | \brief Operator LocalMap = LocalMap - LocalMap */
|
---|
326 | template <class T>
|
---|
327 | inline LocalMap<T> operator - (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
328 | { LocalMap<T> result; result.SetTemp(true);
|
---|
329 | if (b.IsTemp()) { result.Share(b); result.SubElt(a); }
|
---|
330 | else { result.CloneOrShare(a); result.SubElt(b); }
|
---|
331 | return result; }
|
---|
332 |
|
---|
333 | ////////////////////////////////////////////////////////////////
|
---|
334 | // Surcharge d'operateurs C = A (*,/) B
|
---|
335 |
|
---|
336 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,const LocalMap<T>&)
|
---|
337 | \brief Operator LocalMap = LocalMap * LocalMap (pixel by pixel multiply)*/
|
---|
338 | template <class T>
|
---|
339 | inline LocalMap<T> operator * (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
340 | { LocalMap<T> result; result.SetTemp(true);
|
---|
341 | if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
|
---|
342 | else { result.CloneOrShare(a); result.MulElt(b); }
|
---|
343 | return result; }
|
---|
344 |
|
---|
345 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,const LocalMap<T>&)
|
---|
346 | \brief Operator LocalMap = LocalMap / LocalMap (pixel by pixel divide)*/
|
---|
347 | template <class T>
|
---|
348 | inline LocalMap<T> operator / (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
349 | { LocalMap<T> result; result.SetTemp(true);
|
---|
350 | if (b.IsTemp()) { result.Share(b); result.DivElt(a); }
|
---|
351 | else { result.CloneOrShare(a); result.DivElt(b); }
|
---|
352 | return result; }
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 | } // Fin du namespace
|
---|
357 |
|
---|
358 | #endif
|
---|