1 | #include "localmap.h"
|
---|
2 | #include "smathconst.h"
|
---|
3 | #include <complex>
|
---|
4 | #include "piocmplx.h"
|
---|
5 | #include "fiondblock.h"
|
---|
6 |
|
---|
7 | #include <string.h>
|
---|
8 | #include <iostream.h>
|
---|
9 | #include "timing.h"
|
---|
10 |
|
---|
11 |
|
---|
12 | /*!
|
---|
13 | \class SOPHYA::LocalMap
|
---|
14 | A local map is a 2 dimensional matrix, with ny rows and nx columns.
|
---|
15 | The local map has an origin in (theta0, phi0), mapped to pixel(x0, y0)
|
---|
16 | default value of (x0, y0) is middle of the map, center of pixel(nx/2, ny/2)
|
---|
17 | Each pixel(ip, it) is defined by its "phi-like" index ip (column
|
---|
18 | index in the matrix) and its "theta-like" index it (row index in
|
---|
19 | the matrix). Index ip is associated with x-axis in a map-coordinate
|
---|
20 | system ; index it is associated with y-axis in the same map-coordinate system.
|
---|
21 |
|
---|
22 | The map is supposed to lie on a plan tangent to the celestial sphere
|
---|
23 | at a point, with spherical coordinates (theta0, phi0), whose pixel
|
---|
24 | numbers are (x0,y0) in the local map. The aperture of the map is defined
|
---|
25 | by two values of angles, angleX and angleY, covered respectively by all
|
---|
26 | the pixels in x direction and all the pixels in y direction.
|
---|
27 |
|
---|
28 | Each pixel has angleX/nx and angleY/ny, as angle extensions. So, in
|
---|
29 | map-coordinate system the pixel (i,j) has following coordinates :
|
---|
30 |
|
---|
31 | x = (i-x0)*angleX/nx
|
---|
32 |
|
---|
33 | y = (j-y0)*angleY/ny
|
---|
34 |
|
---|
35 | (angles in radians)
|
---|
36 |
|
---|
37 | The projection (method : ProjectionToSphere() )of the map onto a
|
---|
38 | sphere is made by the following procedure :
|
---|
39 |
|
---|
40 | the sphere is supposed to have radius=1. The map is
|
---|
41 | considered to be tangent to the sphere, on a point with (theta0, phi0)
|
---|
42 | spherical coodinates. A reference coordinate system (plane-coordinate
|
---|
43 | system) , is chosen in the plane of the map with reference axes :
|
---|
44 |
|
---|
45 | x-axis : vector tengent to a parallel in (theta0, phi0) on the sphere
|
---|
46 | (components in "3-dim cartesian system : -sin(phi0) ; cos(phi0) ; 0)
|
---|
47 |
|
---|
48 | z-axis : vector-radius with 3-dim cartesian cordinates :
|
---|
49 | sin(theta0)*cos(phi0) ; sin(theta0*sin(phi0) ; cos(theta0)
|
---|
50 |
|
---|
51 | y-axis = z-axis^x-axis : tangent to the meridian at (theta0, phi0)
|
---|
52 |
|
---|
53 | note that the map-coordinate system may be rotated with respect to
|
---|
54 | plane-coordinate system (parameter "angle" below).
|
---|
55 |
|
---|
56 | the projection of a map pixel is defined as the intersection of
|
---|
57 | the vector-radius, from sphere center to the pixel defined by
|
---|
58 | his coordinates in the plane-coordinate system (computed from x,y
|
---|
59 | above, with eventual rotation), with the sphere.
|
---|
60 | */
|
---|
61 | template<class T>
|
---|
62 | LocalMap<T>::LocalMap() : pixels_()
|
---|
63 | {
|
---|
64 | InitNul();
|
---|
65 | }
|
---|
66 |
|
---|
67 | //! full constructor of the local map
|
---|
68 | /*!
|
---|
69 | \param nx : number of pixels in x direction
|
---|
70 | \param ny : number of pixels in y direction
|
---|
71 | \param angleX : total angle aperture in x direction (degrees)
|
---|
72 | \param angleY : total angle aperture in y direction (degrees)
|
---|
73 | \param theta0,phi0 : spherical coordinates of reference point at which
|
---|
74 | the map is considered to be tangent to the sphere
|
---|
75 | \param x0, y0 : coodinates (in pixels) of the reference point just defined
|
---|
76 | \param angle : angle (degrees) of the rotation between x-axis of
|
---|
77 | map-coordinate system) and the tangent to parallel on
|
---|
78 | the sphere (default : 0.).
|
---|
79 | */
|
---|
80 | template<class T>
|
---|
81 | LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle)
|
---|
82 | {
|
---|
83 | InitNul();
|
---|
84 | nSzX_ = nx;
|
---|
85 | nSzY_ = ny;
|
---|
86 | nPix_= nx*ny;
|
---|
87 | pixels_.ReSize(ny,nx);
|
---|
88 | SetSize(angleX, angleY);
|
---|
89 | SetOrigin(theta0, phi0, x0, y0, angle);
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | //! standard constructor of the local map
|
---|
94 | /*!
|
---|
95 | \param nx : number of pixels in x direction
|
---|
96 | \param ny : number of pixels in y direction
|
---|
97 | \param angleX : total angle aperture in x direction (degrees)
|
---|
98 | \param angleY : total angle aperture in y direction (degrees)
|
---|
99 | \param theta0,phi0 : spherical coordinates of reference point at which
|
---|
100 | the map is considered to be tangent to the sphere
|
---|
101 | \param angle : angle (degrees) of the rotation between x-axis of
|
---|
102 | map-coordinate system) and the tangent to parallel on
|
---|
103 | the sphere (default : 0.).
|
---|
104 | */
|
---|
105 | template<class T>
|
---|
106 | LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
|
---|
107 | {
|
---|
108 | InitNul();
|
---|
109 | nSzX_ = nx;
|
---|
110 | nSzY_ = ny;
|
---|
111 | nPix_= nx*ny;
|
---|
112 | pixels_.ReSize(ny,nx);
|
---|
113 | cout << " tableau pixels initialise " << endl;
|
---|
114 | SetSize(angleX, angleY);
|
---|
115 | cout << " fin du setsize " << endl;
|
---|
116 | SetOrigin(theta0, phi0, angle);
|
---|
117 | cout << " fin du set oorigine " << endl;
|
---|
118 | }
|
---|
119 |
|
---|
120 | //! copy constructor
|
---|
121 | /*!
|
---|
122 | \param share : if true, share data. If false copy data
|
---|
123 | */
|
---|
124 | template<class T>
|
---|
125 | LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
|
---|
126 | : pixels_(lm.pixels_, share)
|
---|
127 | {
|
---|
128 |
|
---|
129 | if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
|
---|
130 | recopierVariablesSimples(lm);
|
---|
131 | }
|
---|
132 |
|
---|
133 | //! copy constructor
|
---|
134 | /*!
|
---|
135 | \warning datas are \b SHARED with \b lm.
|
---|
136 | \sa TMatrix::TMatrix(const TMatrix<T>&)
|
---|
137 | */
|
---|
138 | template<class T>
|
---|
139 | LocalMap<T>::LocalMap(const LocalMap<T>& lm)
|
---|
140 | : pixels_(lm.pixels_)
|
---|
141 |
|
---|
142 | {
|
---|
143 |
|
---|
144 | if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
|
---|
145 | recopierVariablesSimples(lm);
|
---|
146 | }
|
---|
147 |
|
---|
148 | template<class T>
|
---|
149 | LocalMap<T>::~LocalMap() {;}
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | /*! \fn void SOPHYA::LocalMap::ReSize(int_4 nx, int_4 ny)
|
---|
154 |
|
---|
155 | Resize storage area for pixels
|
---|
156 | */
|
---|
157 | template<class T>
|
---|
158 | void LocalMap<T>::ReSize(int_4 nx, int_4 ny)
|
---|
159 | {
|
---|
160 | // angles par pixel, en radians
|
---|
161 | deltaPhi_ *= nSzX_/nx;
|
---|
162 | deltaTheta_ *= nSzY_/ny;
|
---|
163 |
|
---|
164 | nSzX_ = nx;
|
---|
165 | nSzY_ = ny;
|
---|
166 | nPix_= nx*ny;
|
---|
167 | pixels_.ReSize(ny,nx);
|
---|
168 | }
|
---|
169 |
|
---|
170 | ////////////////////////// methodes de copie/share
|
---|
171 |
|
---|
172 | template<class T>
|
---|
173 | void LocalMap<T>::CloneOrShare(const LocalMap<T>& a)
|
---|
174 | {
|
---|
175 | recopierVariablesSimples(a);
|
---|
176 | pixels_.CloneOrShare(a.pixels_);
|
---|
177 | if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
|
---|
178 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
|
---|
179 | }
|
---|
180 | template<class T>
|
---|
181 | void LocalMap<T>::Share(const LocalMap<T>& a)
|
---|
182 | {
|
---|
183 | recopierVariablesSimples(a);
|
---|
184 | pixels_.Share(a.pixels_);
|
---|
185 | if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
|
---|
186 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
|
---|
187 | }
|
---|
188 |
|
---|
189 | template<class T>
|
---|
190 | LocalMap<T>& LocalMap<T>::CopyElt(const LocalMap<T>& a)
|
---|
191 | {
|
---|
192 | if (NbPixels() < 1)
|
---|
193 | throw RangeCheckError("LocalMap<T>::CopyElt(const LocalMap<T>& ) - Not Allocated Array ! ");
|
---|
194 | if (NbPixels() != a.NbPixels())
|
---|
195 | throw(SzMismatchError("LocalMap<T>::CopyElt(const LocalMap<T>&) SizeMismatch")) ;
|
---|
196 | recopierVariablesSimples(a);
|
---|
197 | int k;
|
---|
198 | pixels_ = a.pixels_;
|
---|
199 | return(*this);
|
---|
200 |
|
---|
201 | }
|
---|
202 |
|
---|
203 | template<class T>
|
---|
204 | LocalMap<T>& LocalMap<T>::Set(const LocalMap<T>& a)
|
---|
205 | {
|
---|
206 | if (this != &a)
|
---|
207 | {
|
---|
208 | if (a.NbPixels() < 1)
|
---|
209 | throw RangeCheckError("LocalMap<T>::Set(a ) - Array a not allocated ! ");
|
---|
210 | if (NbPixels() < 1) CloneOrShare(a);
|
---|
211 | else CopyElt(a);
|
---|
212 | if (mInfo_) delete mInfo_;
|
---|
213 | mInfo_ = NULL;
|
---|
214 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
|
---|
215 | }
|
---|
216 | return(*this);
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 | /*! \fn int_4 SOPHYA::LocalMap::NbPixels() const
|
---|
221 |
|
---|
222 | \return number of pixels
|
---|
223 | */
|
---|
224 | template<class T>
|
---|
225 | int_4 LocalMap<T>::NbPixels() const
|
---|
226 | {
|
---|
227 | return(nPix_);
|
---|
228 | }
|
---|
229 |
|
---|
230 | /*! \fn T& SOPHYA::LocalMap::PixVal(int_4 k)
|
---|
231 |
|
---|
232 | \return value of pixel with index k
|
---|
233 | */
|
---|
234 | template<class T>
|
---|
235 | T& LocalMap<T>::PixVal(int_4 k)
|
---|
236 | {
|
---|
237 | if((k < 0) || (k >= nPix_))
|
---|
238 | {
|
---|
239 | throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
|
---|
240 | }
|
---|
241 | //
|
---|
242 | int_4 i,j;
|
---|
243 | Getij(k,i,j);
|
---|
244 | return(pixels_(j,i));
|
---|
245 |
|
---|
246 | //
|
---|
247 | }
|
---|
248 |
|
---|
249 | /*! \fn T const& SOPHYA::LocalMap::PixVal(int_4 k) const
|
---|
250 | const version of previous method
|
---|
251 | */
|
---|
252 | template<class T>
|
---|
253 | T const& LocalMap<T>::PixVal(int_4 k) const
|
---|
254 | {
|
---|
255 | if((k < 0) || (k >= nPix_))
|
---|
256 | {
|
---|
257 | throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
|
---|
258 | }
|
---|
259 | //
|
---|
260 | int_4 i,j;
|
---|
261 | Getij(k,i,j);
|
---|
262 | return(pixels_(j,i));
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*! \fn bool SOPHYA::LocalMap::ContainsSph(double theta, double phi) const
|
---|
266 | \return true if teta,phi in map
|
---|
267 | <b> Not yet implemented </b>
|
---|
268 | */
|
---|
269 | template<class T>
|
---|
270 | bool LocalMap<T>::ContainsSph(double theta, double phi) const
|
---|
271 | {
|
---|
272 | // $CHECK$ Reza 11/11/99 - A modifier
|
---|
273 | throw NotAvailableOperation("LocalMap<T>::ContainsSph() - Not yet implemented !");
|
---|
274 | return(true);
|
---|
275 | }
|
---|
276 |
|
---|
277 | /*! \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const
|
---|
278 |
|
---|
279 | angles in radians
|
---|
280 | \return index of the pixel with spherical coordinates (theta,phi)
|
---|
281 | */
|
---|
282 | template<class T>
|
---|
283 | int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
|
---|
284 | {
|
---|
285 | int_4 i,j;
|
---|
286 |
|
---|
287 | double csTheta = cos(theta);
|
---|
288 | double snTheta = sin(theta);
|
---|
289 | double csPhi = cos(phi);
|
---|
290 | double snPhi = sin(phi);
|
---|
291 | double csPhiMPhiC = cos (phi - phiC_);
|
---|
292 | double snPhiMPhiC = sin (phi - phiC_);
|
---|
293 | // le point sur la sphere est note M.
|
---|
294 | // intersection P de OM avec le plan de la carte (tangent en C)
|
---|
295 | double denom = snTheta*snthC_*csPhiMPhiC + csTheta*csthC_;
|
---|
296 | if ( denom == 0.)
|
---|
297 | {
|
---|
298 | throw PException("LocalMap::PixIndexSph : vector radius parallel to map plane ");
|
---|
299 | }
|
---|
300 | double lambda = 1./denom;
|
---|
301 | // coordonnes du point d'intersection P dans le repere lie au plan
|
---|
302 |
|
---|
303 | double XP = lambda*snTheta*snPhiMPhiC;
|
---|
304 | double YP = lambda*snTheta*csthC_*csPhiMPhiC;
|
---|
305 |
|
---|
306 | // coordonnees dans le repere lie a la carte (eventuellement tourne par
|
---|
307 | // rapport au precedent.
|
---|
308 |
|
---|
309 | double X = XP*cosAngle_ + YP*sinAngle_;
|
---|
310 | double Y = -XP*sinAngle_ + YP*cosAngle_;
|
---|
311 |
|
---|
312 | // en unites de pixels
|
---|
313 |
|
---|
314 | X /= deltaPhi_;
|
---|
315 | Y /= deltaTheta_;
|
---|
316 |
|
---|
317 |
|
---|
318 | double xmin= -x0_-0.5;
|
---|
319 | double xmax= xmin+nSzX_;
|
---|
320 | if((X > xmax) || (X < xmin)) {
|
---|
321 | if (exc_outofmap_) throw RangeCheckError("LocalMap<T>::PixIndexSph() - Out of Map Theta/Phi (X) ");
|
---|
322 | else return(-1);
|
---|
323 | }
|
---|
324 | double xcurrent= xmin;
|
---|
325 | for(i = 0; i < nSzX_; i++ )
|
---|
326 | {
|
---|
327 | xcurrent += 1.;
|
---|
328 | if( X < xcurrent ) break;
|
---|
329 | }
|
---|
330 | double ymin= -y0_-0.5;
|
---|
331 | double ymax= ymin+nSzY_;
|
---|
332 | if((Y > ymax) || (Y < ymin)) {
|
---|
333 | if (exc_outofmap_) throw RangeCheckError("LocalMap<T>::PixIndexSph() - Out of Map Theta/Phi (Y) ");
|
---|
334 | else return(-1);
|
---|
335 | }
|
---|
336 | double ycurrent= ymin;
|
---|
337 | for(j = 0; j < nSzY_; j++ )
|
---|
338 | {
|
---|
339 | ycurrent += 1.;
|
---|
340 | if( Y < ycurrent ) break;
|
---|
341 | }
|
---|
342 | return (j*nSzX_+i);
|
---|
343 | }
|
---|
344 |
|
---|
345 | /*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 k,double& theta,double& phi) const
|
---|
346 |
|
---|
347 | \return (theta, phi) coordinates of pixel with index k
|
---|
348 | */
|
---|
349 |
|
---|
350 |
|
---|
351 | template<class T>
|
---|
352 | void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
|
---|
353 | {
|
---|
354 |
|
---|
355 | int_4 i,j;
|
---|
356 | Getij(k,i,j);
|
---|
357 |
|
---|
358 | PixThetaPhi(i,j, theta, phi);
|
---|
359 |
|
---|
360 | }
|
---|
361 |
|
---|
362 | /*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
|
---|
363 |
|
---|
364 |
|
---|
365 | \return (theta, phi) coordinates of pixel of map with indices (ip,it) corresponding to x and y directions
|
---|
366 |
|
---|
367 | \param ip : phi-like index
|
---|
368 | \param it : theta-like index
|
---|
369 | */
|
---|
370 |
|
---|
371 | template<class T>
|
---|
372 | void LocalMap<T>::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
|
---|
373 | {
|
---|
374 | double XP, YP, ZP;
|
---|
375 | PixToSphereC(ip,it,XP,YP,ZP);
|
---|
376 |
|
---|
377 | theta = acos(ZP);
|
---|
378 | phi = atan2(YP, XP);
|
---|
379 | while (phi < 0.) phi += 2.*Pi;
|
---|
380 |
|
---|
381 | }
|
---|
382 |
|
---|
383 |
|
---|
384 |
|
---|
385 |
|
---|
386 | /*! \fn T SOPHYA::LocalMap::SetPixels(T v)
|
---|
387 |
|
---|
388 | Set all pixels to value v
|
---|
389 | */
|
---|
390 | template <class T>
|
---|
391 | T LocalMap<T>::SetPixels(T v)
|
---|
392 | {
|
---|
393 | pixels_ = v;
|
---|
394 | return(v);
|
---|
395 | }
|
---|
396 |
|
---|
397 | /*! \fn double SOPHYA::LocalMap::PixSolAngle(int_4 k) const
|
---|
398 |
|
---|
399 | Pixel Solid angle (steradians)
|
---|
400 |
|
---|
401 | All the pixels are considered to have the same size in (theta, phi).
|
---|
402 |
|
---|
403 | */
|
---|
404 | template<class T>
|
---|
405 | double LocalMap<T>::PixSolAngle(int_4 k) const
|
---|
406 | {
|
---|
407 | double XP, YP, ZP;
|
---|
408 | int_4 i,j;
|
---|
409 | Getij(k,i,j);
|
---|
410 | PixToSphereC(i,j,XP,YP,ZP);
|
---|
411 |
|
---|
412 | double theta = acos(ZP);
|
---|
413 |
|
---|
414 |
|
---|
415 |
|
---|
416 | // angle solide
|
---|
417 |
|
---|
418 | double sol= 2.* deltaPhi_*sin(theta)*sin(0.5*deltaTheta_);
|
---|
419 | return sol;
|
---|
420 | }
|
---|
421 |
|
---|
422 | /*! \fn void SOPHYA::LocalMap::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP)
|
---|
423 |
|
---|
424 | projection of a pixel of map, onto the unity sphere ; result in cartesian coordinates.
|
---|
425 | */
|
---|
426 |
|
---|
427 | template<class T>
|
---|
428 | void LocalMap<T>::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const
|
---|
429 | {
|
---|
430 | double X= double(ip-x0_)* deltaPhi_;
|
---|
431 | double Y= double(it-y0_)*deltaTheta_;
|
---|
432 |
|
---|
433 | // situation dans le plan de reference tangent
|
---|
434 | double dx= X*cosAngle_-Y*sinAngle_;
|
---|
435 | double dy= X*sinAngle_+Y*cosAngle_;
|
---|
436 |
|
---|
437 | XP = XC_ - dx*snphC_ - dy*csthC_*csphC_;
|
---|
438 | YP = YC_ + dx*csphC_ - dy*csthC_*snphC_;
|
---|
439 | ZP = ZC_ + dy*snthC_;
|
---|
440 |
|
---|
441 | // on renormalise pour eviter les probleme de precision lors
|
---|
442 | // de la prise ulterieure de lignes trigonometriques
|
---|
443 | double norme = sqrt(XP*XP + YP*YP + ZP*ZP);
|
---|
444 | XP /= norme;
|
---|
445 | YP /= norme;
|
---|
446 | ZP /= norme;
|
---|
447 | }
|
---|
448 |
|
---|
449 | /*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle)
|
---|
450 |
|
---|
451 | set the referential of the map (angles in degrees)
|
---|
452 |
|
---|
453 | (default x0=siz_x/2, y0=siz_y/2)
|
---|
454 | */
|
---|
455 | template<class T>
|
---|
456 | void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
|
---|
457 | {
|
---|
458 | SetOrigin(theta0, phi0, nSzX_/2, nSzY_/2, angle);
|
---|
459 | }
|
---|
460 |
|
---|
461 | /*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
|
---|
462 |
|
---|
463 | set the referential of the map (angles in degrees)
|
---|
464 | */
|
---|
465 | template<class T>
|
---|
466 | void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
|
---|
467 | {
|
---|
468 | // if (originFlag_)
|
---|
469 | // {
|
---|
470 | // throw PException("LocalMap::SetOrigin : redefining origin is not allowed at the moment ");
|
---|
471 | // }
|
---|
472 |
|
---|
473 | if ( theta0 < 0. || theta0 > 180. || phi0 < 0. || phi0 > 360. || angle < -90. || angle > 90.)
|
---|
474 | {
|
---|
475 | throw ParmError("LocalMap::SetOrigin angle out of range");
|
---|
476 | }
|
---|
477 | SetCoorC(theta0,phi0);
|
---|
478 | angleDegres_ = angle;
|
---|
479 | // en radians
|
---|
480 | angle_ = angle*Pi/180.;
|
---|
481 | x0_= x0;
|
---|
482 | y0_= y0;
|
---|
483 | cosAngle_= cos(angle_);
|
---|
484 | sinAngle_= sin(angle_);
|
---|
485 | }
|
---|
486 |
|
---|
487 | template<class T>
|
---|
488 | void LocalMap<T>::SetCoorC(double theta0, double phi0)
|
---|
489 | {
|
---|
490 |
|
---|
491 | thetaDegresC_ = theta0;
|
---|
492 | phiDegresC_ = phi0;
|
---|
493 |
|
---|
494 | // passage en radians
|
---|
495 | thetaC_= theta0*Pi/180.;
|
---|
496 | phiC_ = phi0*Pi/180.;
|
---|
497 | csthC_ = cos(thetaC_);
|
---|
498 | snthC_ = sin(thetaC_);
|
---|
499 | csphC_ = cos(phiC_);
|
---|
500 | snphC_ = sin(phiC_);
|
---|
501 | XC_ = snthC_*csphC_;
|
---|
502 | YC_ = snthC_*snphC_;
|
---|
503 | ZC_ = csthC_;
|
---|
504 | }
|
---|
505 |
|
---|
506 |
|
---|
507 | // angles en RADIANS
|
---|
508 | template<class T>
|
---|
509 | TMatrix<double> LocalMap<T>::CalculMatricePassage()
|
---|
510 | {
|
---|
511 | cout << " calcul matrice de passage " << endl;
|
---|
512 | TMatrix<double> passage(3,3);
|
---|
513 | double cos_th_axeZ;
|
---|
514 | double sin_th_axeZ;
|
---|
515 | double cos_phi_axeZ;
|
---|
516 | double sin_phi_axeZ;
|
---|
517 |
|
---|
518 | double cth,sth, cdeltaPhi, phi, cphi, sphi;
|
---|
519 |
|
---|
520 | if ( snthC_ <= 0.) // carte centree au pole
|
---|
521 | {
|
---|
522 | cos_th_axeZ = 1.;
|
---|
523 | sin_th_axeZ = 0.;
|
---|
524 | cos_phi_axeZ = 1.;
|
---|
525 | sin_phi_axeZ = 0.;
|
---|
526 |
|
---|
527 | }
|
---|
528 | else
|
---|
529 | {
|
---|
530 | cth = cosAngle_*snthC_;
|
---|
531 | double arg = 1.-cth*cth;
|
---|
532 | if (arg <= 0. ) // carte centree sur l'equateur, sans rotation
|
---|
533 | {
|
---|
534 | cos_th_axeZ = 1.;
|
---|
535 | sin_th_axeZ = 0.;
|
---|
536 | cos_phi_axeZ = csphC_;
|
---|
537 | sin_phi_axeZ = snphC_;
|
---|
538 | }
|
---|
539 | else
|
---|
540 | {
|
---|
541 | sth = sqrt(arg);
|
---|
542 | cdeltaPhi = -csthC_*cth/(snthC_*sth);
|
---|
543 | if (cdeltaPhi < -1. ) cdeltaPhi = -1.;
|
---|
544 | if (cdeltaPhi > 1. ) cdeltaPhi = 1.;
|
---|
545 | phi = phiC_ + acos( cdeltaPhi );
|
---|
546 |
|
---|
547 | cos_th_axeZ = cth;
|
---|
548 | sin_th_axeZ = sth;
|
---|
549 | cos_phi_axeZ = cos(phi);
|
---|
550 | sin_phi_axeZ = sin(phi);
|
---|
551 | }
|
---|
552 | }
|
---|
553 | passage(0,0) = snthC_*csphC_;
|
---|
554 | passage(1,0) = snthC_*snphC_;
|
---|
555 | passage(2,0) = csthC_;
|
---|
556 |
|
---|
557 | passage(0,2) = sin_th_axeZ*cos_phi_axeZ;
|
---|
558 | passage(1,2) = sin_th_axeZ*sin_phi_axeZ;
|
---|
559 | passage(2,2) = cos_th_axeZ;
|
---|
560 |
|
---|
561 | passage(0,1) = passage(1,2)*passage(2,0) - passage(2,2)*passage(1,0);
|
---|
562 | passage(1,1) = passage(2,2)*passage(0,0) - passage(0,2)*passage(2,0);
|
---|
563 | passage(2,1) = passage(0,2)*passage(1,0) - passage(1,2)*passage(0,0);
|
---|
564 |
|
---|
565 | // passage.Print(cout);
|
---|
566 | // cout << " fin calcul passage " << endl;
|
---|
567 |
|
---|
568 | return passage;
|
---|
569 |
|
---|
570 |
|
---|
571 | }
|
---|
572 |
|
---|
573 | /*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY)
|
---|
574 |
|
---|
575 | angle range of tthe map (angles in degrees)
|
---|
576 | */
|
---|
577 | template<class T>
|
---|
578 | void LocalMap<T>::SetSize(double angleX,double angleY)
|
---|
579 | {
|
---|
580 | if ( angleX <= 0. || angleX > 180. || angleY <= 0. || angleY > 180.)
|
---|
581 | {
|
---|
582 | throw ParmError("LocalMap::SetSize extension angle out of range");
|
---|
583 | }
|
---|
584 |
|
---|
585 | angleDegresX_ = angleX;
|
---|
586 | angleDegresY_ = angleY;
|
---|
587 | // angles par pixel, en radians
|
---|
588 | cout << " taille x " << nSzX_ <<" taille y " << nSzY_ << endl;
|
---|
589 | deltaPhi_ = angleX*Pi/(180.*nSzX_);
|
---|
590 | deltaTheta_ = angleY*Pi/(180.*nSzY_);
|
---|
591 |
|
---|
592 |
|
---|
593 | }
|
---|
594 |
|
---|
595 |
|
---|
596 |
|
---|
597 | /*! \fn void SOPHYA::LocalMap::ProjectionToSphere(SphericalMap<T>& sphere) const
|
---|
598 |
|
---|
599 | Projection to a spherical map
|
---|
600 | */
|
---|
601 | template<class T>
|
---|
602 | void LocalMap<T>::ProjectionToSphere(SphericalMap<T>& sphere) const
|
---|
603 | {
|
---|
604 | double theta, phi;
|
---|
605 | int it, ip;
|
---|
606 | for (it = 0; it < nSzY_; it++)
|
---|
607 | {
|
---|
608 | for (ip = 0; ip < nSzX_; ip++)
|
---|
609 | {
|
---|
610 | PixThetaPhi(ip,it, theta, phi);
|
---|
611 | sphere(theta,phi)= pixels_(it, ip);
|
---|
612 | }
|
---|
613 | }
|
---|
614 | }
|
---|
615 |
|
---|
616 |
|
---|
617 |
|
---|
618 | // Titre Private Methods
|
---|
619 | //++
|
---|
620 | template<class T>
|
---|
621 | void LocalMap<T>::InitNul()
|
---|
622 | //
|
---|
623 | // set attributes to zero
|
---|
624 | //--
|
---|
625 | {
|
---|
626 | nSzX_ = 0;
|
---|
627 | nSzY_ = 0;
|
---|
628 | angleDegresX_ = 0.;
|
---|
629 | angleDegresY_ = 0.;
|
---|
630 | thetaDegresC_ = 0.;
|
---|
631 | phiDegresC_ = 0.;
|
---|
632 | x0_ = 0;
|
---|
633 | y0_ = 0;
|
---|
634 | angleDegres_ = 0.;
|
---|
635 |
|
---|
636 |
|
---|
637 | nPix_ = 0;
|
---|
638 |
|
---|
639 | thetaC_ = 0.;
|
---|
640 | phiC_ = 0.;
|
---|
641 | csthC_ = 1.;
|
---|
642 | snthC_ = 0.;
|
---|
643 | csphC_ = 1.;
|
---|
644 | snphC_ = 0.;
|
---|
645 | XC_ = 0.;
|
---|
646 | YC_ = 0.;
|
---|
647 | ZC_ = 1.;
|
---|
648 |
|
---|
649 | angle_ = 0.;
|
---|
650 | cosAngle_ = 1.;
|
---|
651 | sinAngle_ = 0.;
|
---|
652 | deltaPhi_ = 0.;
|
---|
653 | deltaTheta_ =0.;
|
---|
654 | SetThrowExceptionWhenOutofMapFlag(false); // Genere des exceptions si theta-phi out of range
|
---|
655 | }
|
---|
656 |
|
---|
657 |
|
---|
658 | /*! \fn void SOPHYA::LocalMap::Getij(int_4 k,int_4& i,int_4& j) const
|
---|
659 |
|
---|
660 | \return 2 indices corresponding to the pixel number k
|
---|
661 | */
|
---|
662 | template<class T>
|
---|
663 | void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
|
---|
664 | {
|
---|
665 | i= (k+1)%nSzX_-1;
|
---|
666 | if(i == -1) i= nSzX_-1;
|
---|
667 | j= (k-i+2)/nSzX_;
|
---|
668 | }
|
---|
669 |
|
---|
670 |
|
---|
671 |
|
---|
672 |
|
---|
673 |
|
---|
674 |
|
---|
675 | template<class T>
|
---|
676 | void LocalMap<T>::print(ostream& os) const
|
---|
677 | {
|
---|
678 | os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
|
---|
679 | os<<" theta0= "<<thetaC_*180./Pi <<", phi0= "<<phiC_*180./Pi <<", angle= "<<angle_*180./Pi<<endl;
|
---|
680 | os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
|
---|
681 | os<<" cos= "<< cosAngle_ <<", & sin= "<<sinAngle_<<endl;
|
---|
682 | os<<" deltaPhi_= "<< deltaPhi_ <<", deltaTheta = "<< deltaTheta_ <<endl;
|
---|
683 | os <<endl;
|
---|
684 |
|
---|
685 | os << " contenu de pixels : ";
|
---|
686 | for(int i=0; i < nPix_; i++)
|
---|
687 | {
|
---|
688 | if(i%5 == 0) os << endl;
|
---|
689 | int_4 ik,jk;
|
---|
690 | Getij(i,ik,jk);
|
---|
691 | os << pixels_(jk,ik) <<", ";
|
---|
692 | }
|
---|
693 | os << endl;
|
---|
694 | }
|
---|
695 |
|
---|
696 |
|
---|
697 | template<class T>
|
---|
698 | void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm)
|
---|
699 | {
|
---|
700 |
|
---|
701 | nSzX_ = lm.nSzX_;
|
---|
702 | nSzY_ = lm.nSzY_;
|
---|
703 | nPix_ = lm.nPix_;
|
---|
704 | x0_ = lm.x0_;
|
---|
705 | y0_ = lm.y0_;
|
---|
706 |
|
---|
707 | thetaC_ = lm.thetaC_;
|
---|
708 | phiC_ = lm.phiC_;
|
---|
709 | csthC_ = lm.csthC_;
|
---|
710 | snthC_ = lm.snthC_;
|
---|
711 | csphC_ = lm.csphC_;
|
---|
712 | snphC_ = lm.snphC_;
|
---|
713 | XC_ = lm.XC_;
|
---|
714 | YC_ = lm.YC_;
|
---|
715 | ZC_ = lm.ZC_;
|
---|
716 |
|
---|
717 | angle_= lm.angle_;
|
---|
718 | cosAngle_ = lm.cosAngle_;
|
---|
719 | sinAngle_ = lm.sinAngle_;
|
---|
720 | deltaPhi_ = lm. deltaPhi_;
|
---|
721 | deltaTheta_ = lm.deltaTheta_;
|
---|
722 | }
|
---|
723 |
|
---|
724 | // ...... Operations de calcul ......
|
---|
725 |
|
---|
726 |
|
---|
727 | //! Fill a LocalMap with a constant value \b a
|
---|
728 | template <class T>
|
---|
729 | LocalMap<T>& LocalMap<T>::SetT(T a)
|
---|
730 | {
|
---|
731 | if (NbPixels() < 1)
|
---|
732 | throw RangeCheckError("LocalMap<T>::SetT(T ) - LocalMap not dimensionned ! ");
|
---|
733 | pixels_ = a;
|
---|
734 | return (*this);
|
---|
735 | }
|
---|
736 |
|
---|
737 | /*! Add a constant value \b x to a LocalMap */
|
---|
738 | template <class T>
|
---|
739 | LocalMap<T>& LocalMap<T>::Add(T a)
|
---|
740 | {
|
---|
741 | if (NbPixels()< 1)
|
---|
742 | throw RangeCheckError("LocalMap<T>::Add(T ) - LocalMap not dimensionned ! ");
|
---|
743 | pixels_ += a;
|
---|
744 | return (*this);
|
---|
745 | }
|
---|
746 |
|
---|
747 | /*! Substract a constant value \b a to a LocalMap */
|
---|
748 | template <class T>
|
---|
749 | LocalMap<T>& LocalMap<T>::Sub(T a,bool fginv)
|
---|
750 | {
|
---|
751 | if (NbPixels()< 1)
|
---|
752 | throw RangeCheckError("LocalMap<T>::Sub(T ) - LocalMap not dimensionned ! ");
|
---|
753 | pixels_.Sub(a,fginv);
|
---|
754 | return (*this);
|
---|
755 | }
|
---|
756 |
|
---|
757 | /*! multiply a LocalMap by a constant value \b a */
|
---|
758 | template <class T>
|
---|
759 | LocalMap<T>& LocalMap<T>::Mul(T a)
|
---|
760 | {
|
---|
761 | if (NbPixels()< 1)
|
---|
762 | throw RangeCheckError("LocalMap<T>::Mul(T ) - LocalMap not dimensionned ! ");
|
---|
763 | pixels_ *= a;
|
---|
764 | return (*this);
|
---|
765 | }
|
---|
766 |
|
---|
767 | /*! divide a LocalMap by a constant value \b a */
|
---|
768 | template <class T>
|
---|
769 | LocalMap<T>& LocalMap<T>::Div(T a)
|
---|
770 | {
|
---|
771 | if (NbPixels()< 1)
|
---|
772 | throw RangeCheckError("LocalMap<T>::Div(T ) - LocalMap not dimensionned ! ");
|
---|
773 | pixels_ /= a;
|
---|
774 | return (*this);
|
---|
775 | }
|
---|
776 |
|
---|
777 | // >>>> Operations avec 2nd membre de type LocalMap
|
---|
778 | //! Add two LocalMap
|
---|
779 |
|
---|
780 | template <class T>
|
---|
781 | LocalMap<T>& LocalMap<T>::AddElt(const LocalMap<T>& a)
|
---|
782 | {
|
---|
783 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
|
---|
784 | {
|
---|
785 | throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
|
---|
786 | }
|
---|
787 | pixels_ += a.pixels_;
|
---|
788 | return (*this);
|
---|
789 | }
|
---|
790 |
|
---|
791 | //! Substract two LocalMap
|
---|
792 | template <class T>
|
---|
793 | LocalMap<T>& LocalMap<T>::SubElt(const LocalMap<T>& a)
|
---|
794 | {
|
---|
795 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
|
---|
796 | {
|
---|
797 | throw(SzMismatchError("LocalMap<T>::SubElt(const LocalMap<T>&) SizeMismatch")) ;
|
---|
798 | }
|
---|
799 | pixels_ -= a.pixels_;
|
---|
800 | return (*this);
|
---|
801 | }
|
---|
802 |
|
---|
803 | //! Multiply two LocalMap (elements by elements)
|
---|
804 | template <class T>
|
---|
805 | LocalMap<T>& LocalMap<T>::MulElt(const LocalMap<T>& a)
|
---|
806 | {
|
---|
807 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
|
---|
808 | {
|
---|
809 | throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ;
|
---|
810 | }
|
---|
811 | // pixels_ *= a.pixels_;
|
---|
812 | pixels_.DataBlock() *= a.pixels_.DataBlock();
|
---|
813 | return (*this);
|
---|
814 | }
|
---|
815 |
|
---|
816 | //! Divide two LocalMaps (elements by elements) - No protection for divide by 0
|
---|
817 | template <class T>
|
---|
818 | LocalMap<T>& LocalMap<T>::DivElt(const LocalMap<T>& a)
|
---|
819 | {
|
---|
820 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
|
---|
821 | {
|
---|
822 | throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ;
|
---|
823 | }
|
---|
824 | // pixels_ /= a.pixels_;
|
---|
825 | pixels_.DataBlock() /= a.pixels_.DataBlock();
|
---|
826 | return (*this);
|
---|
827 | }
|
---|
828 |
|
---|
829 |
|
---|
830 |
|
---|
831 |
|
---|
832 |
|
---|
833 |
|
---|
834 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
835 | #pragma define_template LocalMap<int_4>
|
---|
836 | #pragma define_template LocalMap<r_8>
|
---|
837 | #pragma define_template LocalMap<r_4>
|
---|
838 | #pragma define_template LocalMap< complex<r_8> >
|
---|
839 | #pragma define_template LocalMap< complex<r_4> >
|
---|
840 | #endif
|
---|
841 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
842 | template class LocalMap<int_4>;
|
---|
843 | template class LocalMap<r_8>;
|
---|
844 | template class LocalMap<r_4>;
|
---|
845 | template class LocalMap< complex<r_8> >;
|
---|
846 | template class LocalMap< complex<r_4> >;
|
---|
847 | #endif
|
---|